Skip to content

window.opener is null :( #11471

Closed
Closed

Description

@xzycn

Hi, I'm facing a problem that window.opener is null when there is a access to window.opener in a page within webview tag.
I listen the new-window event of the webview tag,and then add a new tab.Yes, it's similar to click a a tag with _blank .
The original behavior is that opening a new window in Chrome of window.opener.But now,I changed it to act as clicking a tag with _blank .
I found a doc in https://github.com/electron/electron/blob/master/docs/api/window-open.md.
The sample code is strange,when I opened an url directly,I couldn't access window.opener in new page.
like this:
main.js

const {app, BrowserWindow, m} = require('electron');
let basicWindowParams = {
        show: true
};
console.log(process.pid)
app.on('ready', () => {
    const mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
          nativeWindowOpen: true
        }
      })
      mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
        
        if (frameName === 'reddit') {
          event.preventDefault()
          Object.assign(options, {
            modal: true,
            parent: mainWindow
          })
          let newWin = new BrowserWindow(options);
          event.newGuest = newWin;
          newWin.webContents.openDevTools();
        }
      });
      mainWindow.loadURL(`file://${__dirname}/index.html`)
});

index.html

<html>
    <body>
        <script>
            let url = 'https://reddit.com';
            let modal = window.open(url, 'reddit')
            // modal.location.href = url;
        </script>
    </body>
</html>

OS: Windows 7 SP1
Electron: 1.7.8

Activity

  1. changed the title [-]window.opener is null :)[/-] [+]window.opener is null :([/+] on Dec 19, 2017
  2. MarshallOfSound commented on Dec 19, 2017

    @MarshallOfSound
    Member

    Duplicate of #10401 #9581

    window.opener support doesn't quite work in Electron primarily due to our process model, this may change at some point in the future.

  3. xzycn commented on Dec 19, 2017

    @xzycn
    Author

    @MarshallOfSound Actually,I write a minibrowser using Electron(1.7.8), there is a calling of window.open within one webview like this:

    <button  type="button" onclick="window1=window.open('one-url,'window1','toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=500');window1.focus();return false;">Edit</button>

    There is no iframe in my case,dose this is similar to #10041 and #9581? :)

  4. MarshallOfSound commented on Dec 19, 2017

    @MarshallOfSound
    Member

    @xzycn It is the same underlying issue

  5. xzycn commented on Dec 19, 2017

    @xzycn
    Author

    @MarshallOfSound Thanks for your reply.This is a very bad message to me,the browser has cast my much time :( :(.
    Do you have a plan or a schedule to fix the issue? :)

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions