Electron: ses.webRequest.onBeforeRequest: redirectUrl is ignored

Created on 8 Jan 2016  ·  3Comments  ·  Source: electron/electron

The following code works as expected (all HTTP requests are canceled):

session.webRequest.onBeforeRequest({
  urls: ['http://*/*']
}, (details, cb) => {
  cb({cancel: true})
})

However, when redirectUrl is specified, requests are still sent instead of being canceled and redirected.

session.webRequest.onBeforeRequest({
  urls: ['http://*/*']
}, (details, cb) => {
  cb({redirectUrl: 'https://example.com'})
})

I am on electron-prebuilt 0.36.3

Most helpful comment

FWIW, the source of my confusion was that the original WebRequest API (https://developer.chrome.com/extensions/webRequest) uses redirectUrl instead of redirectURL. This might trip up other developers trying to port Chrome extensions to Electron.

All 3 comments

there is a typo, should be redirectURL . Otherwise unable to reproduce.

session.webRequest.onBeforeRequest({
  urls: ['http://*/*']
}, (details, cb) => {
  cb({redirectURL: 'https://example.com'})
})

:facepalm:

You're right, thanks for resolving.

FWIW, the source of my confusion was that the original WebRequest API (https://developer.chrome.com/extensions/webRequest) uses redirectUrl instead of redirectURL. This might trip up other developers trying to port Chrome extensions to Electron.

Was this page helpful?
0 / 5 - 0 ratings