Skip to content

will-navigate event not fired when in sandbox mode #8841

@sebastianseilund

Description

@sebastianseilund

Thanks for Electron! Amazing project :)

  • Electron version: 1.6.2
  • Operating system: macOS Sierra (10.12.3)

It happens when BrowserWindow is opened with sandbox: true. It might be on purpose, but I couldn't find any Electron/Chromium documentation that explains why. So I'm suspecting it's a bug. I can submit a PR with a failing test to this repo if you agree that it's a bug.

Expected behavior

webContents' will-navigate event should fire when user reloads page fx.

Actual behavior

It does not fire.

How to reproduce

package.json:

{
  "name": "electron-sandbox-will-navigate-bug",
  "version": "0.0.0",
  "main": "main.js",
  "dependencies": {
    "electron": "^1.6.2"
  }
}

main.js:

const {app, BrowserWindow} = require('electron')
const path = require('path')

app.on('ready', function() {
  const win = new BrowserWindow({
    webPreferences: {
      sandbox: true
    }
  })

  const {webContents} = win
  webContents.on('will-navigate', () => {
    console.log('will-navigate')
  })
  webContents.on('did-navigate', () => {
    console.log('did-navigate')
  })

  win.loadURL('file://' + path.join(__dirname, 'index.html'))
})

index.html:

<!doctype html>
<html>
  <body>
    <button onclick="window.location.reload()">Reload</button>
  </body>
</html>

Perform these steps:

  • Run npm install
  • Run ./node_modules/.bin/electron .
  • Click the Reload button in the browser window
  • Observe the Terminal output

Expected output:

did-navigate
will-navigate
did-navigate

Actual output:

did-navigate
did-navigate

(will-navigate is not fired).

If you outcomment the line sandbox:true in main.js, then it works as expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions