Skip to content

webview and window.open #9523

Closed
Closed

Description

@snene

I have a renderer window with a webview tag. The webview loads the guest web pages. One of the pages calls window.open and writes HTML to the new window using the following code:

var printWin = window.open("", "_blank");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();

When the guest page calls window.open, the renderer window receives new-window event where I create a new BrowserWindow and pass it back as evt.newGuest parameter. My code looks like following:

webview.addEventListener('new-window', (evt, url, frameName, disposition, options, additionalFeatures) => {
    evt.preventDefault();
    let nW = ipcRenderer.sendSync(constants.open_new_window_event); // Send a synchronous event to create a new BrowserWindow
    event.newGuest = nW;
  });

But looks like window.open called from the webview guest page does not receive this newly created window. In the webpage, printWin.document.open(); call fails with "TypeError: Cannot read property 'document' of null"

Is there any suggestion on how to handle window.open calls in the pages loaded in the webview?

Activity

  1. kevinsawicki commented on May 31, 2017

    @kevinsawicki
    Contributor

    Is there any suggestion on how to handle window.open calls in the pages loaded in the webview?

    Accessing document on the opened window requires the nativeWindowOpen option to be set which is now supported on <webview> tags starting in `1.7.2.

    You do not need to override the new-window event to support this, you should be able to access printWin.document without it.

    Closing this out.

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