electron: `will-navigate` not triggered for some website.

  • Output of node_modules/.bin/electron --version: 3.0.0-beta8
  • Operating System (Platform and Version): win/mac
  • Output of node_modules/.bin/electron --version on last known working Electron version (if applicable): 3.0.0

Expected Behavior will-navigate event can be triggered successfully.

Actual behavior will-navigate is not triggered.

To Reproduce We have QQ oath login function in our electron app. The oauth url looks like https://graph.qq.com/oauth2.0/authorize?client_id=xxx&redirect_uri=xxx&response_type=code&scope=get_user_info&state=xxx.

We can success catch the will-navigate event in electron@2.0.8 as well as 2.0.10, but failed when update electron to 3.x(tried 3.0.0-beta8 and 3.0.0).

Another wechat oauth function works well for both electron 2.x and 3.x and it’s url looks like https://open.weixin.qq.com/connect/qrconnect?appid=xxx&redirect_uri=xxx&response_type=code&scope=snsapi_login&state=xxx#wechat_redirect

Additional Information Some major code:

win.webContents.on('will-navigate', (e, redirectUrl) => {
  if (redirectUrl.startsWith(this.callbackUrl)) {
    e.preventDefault()
    // do something
  }
})

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I also face this issue! Still reproducible on 3.0.3 and 3.0.4!

Please fix this asap!

Faced the same issue. Reproducible on 3.0.0 and 3.0.2. I found that ‘will-navigate’ is triggered whenever any link is clicked but is not triggered when location is changed by form submission.

use did-navigate it works to me! 😃

In my experience it seems to fail on the vast majority of navigations. You can bind up to the session.webRequest and listen for onBeforeRequest to work around this.

If you’re following the security advice on navigation and haven’t noticed this, there’s potential for security holes downstream 😕

2.0.10 works well

will-navigate does not get emitted for redirects inside the navigation chain.

You need to subscribe to will-redirect to get that information

🔗 https://electronjs.org/docs/api/web-contents#event-will-redirect

same on Electron 3.0.5