Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Electron 16.0.5 cannot enable webviewTag in nativeWindowOpen sub window #32252

Closed
3 tasks done
KochiyaOcean opened this issue Dec 19, 2021 · 3 comments
Closed
3 tasks done
Assignees
Labels
bug 🪲 bug/regression ↩️ A new version of Electron broke something component/webview

Comments

@KochiyaOcean
Copy link

KochiyaOcean commented Dec 19, 2021

Preflight Checklist

Electron Version

16.0.5

What operating system are you using?

Windows

Operating System Version

10 version 19043

What arch are you using?

x64

Last Known Working Electron version

16.0.4

Expected Behavior

When a sub window opened with webviewTag set to true, the webview in sub window should works correctly

Actual Behavior

In the subwindow, the webviewTag option is not actually enabled and webview is not working

Testcase Gist URL

https://gist.github.com/72a8040c33a7deeebdfe88d409d8ca0b

Additional Information

In the testcase, type following command in devtool console and press enter:

w = open('./index.html')
setTimeout(() => {
    w.document.querySelector('webview').addEventListener('dom-ready', (e) => console.log(e))
    w.document.querySelector('webview').reload()
}, 100)

The console will open a subwindow, but in the subwindow the webview did not load, and the console throws error w.document.querySelector(...).reload is not a function

image

@KochiyaOcean
Copy link
Author

KochiyaOcean commented Dec 19, 2021

I think it should be related to #32057

17.0.0-beta.5 has the same issue, which also includes this change (17.0.0-beta.4 do not include the change so it does not have such issue)

@codebytere
Copy link
Member

cc @miniak @zcbenz

@zcbenz zcbenz self-assigned this Jan 7, 2022
@zcbenz zcbenz added bug/regression ↩️ A new version of Electron broke something component/webview labels Jan 7, 2022
@zcbenz
Copy link
Member

zcbenz commented Jan 26, 2022

The previous behavior was actually a security bug, the new-window event does not have the ability to override the webPreferences, it only reuses the WebContents created by Chromium, so the passed webPreferences is actually ignored. The code used to work because the child window inherited the webviewTag: true from parent window directly, which was a bug instead of expected behavior.

The correct way to do it is to use webContents.setWindowOpenHandler API instead:

  mainWindow.webContents.setWindowOpenHandler(() => {
    return {
      action: 'allow',
      overrideBrowserWindowOptions: {
        webPreferences: {
          webviewTag: true
        }   
      }   
    }   
  }); 

@zcbenz zcbenz closed this as completed Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 bug/regression ↩️ A new version of Electron broke something component/webview
Projects
None yet
Development

No branches or pull requests

3 participants