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
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.
Most helpful comment
FWIW, the source of my confusion was that the original WebRequest API (https://developer.chrome.com/extensions/webRequest) uses
redirectUrlinstead ofredirectURL. This might trip up other developers trying to port Chrome extensions to Electron.