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

Related issues

mccxiv picture mccxiv  路  3Comments

reggi picture reggi  路  3Comments

sindresorhus picture sindresorhus  路  3Comments

dangan-ronpa picture dangan-ronpa  路  3Comments

cniaulin picture cniaulin  路  3Comments