Skip to content

No opener using native window.open from an iframe in non-sandbox mode #9533

Closed

Description

@AshDevFr
  • Electron version: 1.7.1
  • Operating system: MacOS

Expected behavior

The popup should have window.opener set

Actual behavior

I was using native window.open in sandbox mode until this PR was merged : #8963

I switched to non-sandbox mode using the version 1.7.1 and what happen is that, if your main app is embedded in an iframe and if it open a new window using window.open, the new window won't have window.opener set

If I load the same app directly in the main window and not using the iframe, it is working as expected

I am using the code from https://github.com/electron/electron/blob/master/docs/api/window-open.md

How to reproduce

In the main window load in an iframe your app.

In the app open a popup with window.open

The new popup does not have window.opener set

Activity

  1. changed the title [-]No opener using window.open from an iframe in non-sandbox mode[/-] [+]No opener using native window.open from an iframe in non-sandbox mode[/+] on May 19, 2017
  2. kevinsawicki commented on May 23, 2017

    @kevinsawicki
    Contributor

    @AshDevFr are you setting the nativeWindowOpen option to true on the BrowserWindow?

  3. kevinsawicki commented on May 24, 2017

    @kevinsawicki
    Contributor

    @AshDevFr I'm having trouble reproducing this with the following example, can you confirm if it works for you or not?

    index.js

    const {app, BrowserWindow} = require('electron')
    
    let mainWindow
    
    app.once('ready', () => {
      mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
          nativeWindowOpen: true
        }
      })
      mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
        if (frameName === 'modal') {
          // open window as modal
          event.preventDefault()
          Object.assign(options, {
            modal: true,
            parent: mainWindow,
            width: 500,
            height: 500
          })
          event.newGuest = new BrowserWindow(options)
        }
      })
      mainWindow.loadURL(`file://${__dirname}/frame.html`)
    })

    frame.html

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
      </head>
      <body>
        <iframe src="./index.html"></iframe>
      </body>
    </html>

    index.html

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
      </head>
      <body>
        <script>
          let modal = window.open('./popup.html', 'modal')
        </script>
      </body>
    </html>

    popup.html

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
      </head>
      <body>
        <script>
          alert(window.opener.location)
        </script>
      </body>
    </html>
  4. added
    blocked/need-info ❌
    on May 24, 2017
  5. AshDevFr commented on May 24, 2017

    @AshDevFr
    Author

    @kevinsawicki I was using this:

    nativeWindowOpen: true,
    sandbox: false
    

    I was not setting the parent with parent: mainWindow because if I do it it link the popup window to the parent position.

    I will try your example and let you know if it is working for me.

    Thank you

  6. kevinsawicki commented on Jun 12, 2017

    @kevinsawicki
    Contributor

    will try your example and let you know if it is working for me.

    @AshDevFr were you able to confirm if it is working for you?

  7. codebytere commented on Sep 27, 2017

    @codebytere
    Member

    Closing due to abandonment.

  8. Gvozd commented on Jul 4, 2018

    @Gvozd

    To correct window.opener, and work facebook(and others) logins

    You need use webPreferences.nativeWindowOpen=true, and set same webPreferences.affinity for mainWindow, and opened windows(hook on mainWindow.webContents.on('new-window'))
    https://gist.github.com/Gvozd/2cec0c8c510a707854e439fb15c561b0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked/need-info ❌

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions