Skip to content

Electron 5 webview with no contextIsolation and nativeWindowOpen fails to load a preload in a popup window in the correct context #17989

Closed

Description

@Tim91084

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 5.0.0
  • Operating System:
    • Windows (didn't test anywhere else)
  • Last Known Working Electron version::
    • ? not sure.

Expected Behavior

When opening a popup window from a webview with contextIsolation=no,nativeWindowOpen=yes, the preload script for that webview should load in the popup window in the correct context

Actual Behavior

The preload script appears to fail to load in the correct context, causing things like fetch to fail with the following error: TypeError: Failed to execute 'fetch' on 'Window': The global scope is shutting down.

To Reproduce

index.html

<webview src="webview-test.html"
      style="height:100%; width: 100%"
      allowpopups
      preload="preload.js"
      webPreferences="contextIsolation=no,nativeWindowOpen=yes"></webview>

webview-test.html

<html>
<body>
  <script>
    window.openGoogle = function () {
      window.open('https://www.google.com')
    }
  </script>
  <button onclick="openGoogle()" type="button">window.open('https://www.google.com')</button>
</body>
</html>

preload.js

// window.location.href always reports about:blank in this situation for some reason
console.log('window.location.href', window.location.href)
fetch('https://www.google.com')
    .then(x => console.log('success', x.text()))
    .catch(x => console.log('error', x))

forked quick start repo with reproduction

https://github.com/Tim91084/electron-window-open-bug

Screenshots

image

image

Activity

  1. hugomano commented on Apr 30, 2019

    @hugomano

    We observed that preloads scripts are not executed after a window.open only when the opener and the opened window shares the same origin domain. But, after navigating the opened window to a different domain, preloads are executed. More details here

    It really looks like #15821 has something to do with that:
    When a new WebContents is created in an existing browsing instance, will renderer initialization scripts (responsible for preload scripts execution) be executed?

    @ppontes @deepak1556 @zcbenz any idea?

  2. alexstrat commented on Apr 30, 2019

    @alexstrat
    Contributor

    Wouldn't this condition on Opener() be preventing the execution of renderer initialization scripts?

    // Do not load node if we're aren't a main frame or a devtools extension
    // unless node support has been explicitly enabled for sub frames
    bool is_main_frame =
    render_frame->IsMainFrame() && !render_frame->GetWebFrame()->Opener();

  3. electron-triage commented on Feb 19, 2020

    @electron-triage

    Thank you for taking the time to report this issue and helping to make Electron better.

    The version of Electron you reported this on has been superseded by newer releases.

    If you're still experiencing this issue in Electron 6.x.y or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.

    I'm setting the blocked/need-info label for the above reasons. This issue will be closed 7 days from now if there is no response.

    Thanks in advance! Your help is appreciated.

  4. added
    blocked/need-info ❌
    on Feb 19, 2020
  5. electron-triage commented on Feb 26, 2020

    @electron-triage

    Thank you for your issue!

    We haven't gotten a response to our questions in our comment above. With only the information that is currently in the issue, we don't have enough information to take action. I'm going to close this but don't hesitate to reach out if you have or find the answers we need, we'll be happy to reopen 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

    5-0-xblocked/need-info ❌bug 🪲platform/windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions