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]: Problems with webview new-window event #35417

Closed
3 tasks done
toschlog opened this issue Aug 23, 2022 · 9 comments
Closed
3 tasks done

[Bug]: Problems with webview new-window event #35417

toschlog opened this issue Aug 23, 2022 · 9 comments
Labels

Comments

@toschlog
Copy link

Preflight Checklist

Electron Version

20.0.0

What operating system are you using?

Windows

Operating System Version

Windows 10 Home 19042.1826

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

When the page displayed in a webview attempts to open a new tab, I would expect to get the new-window event and be able to open a new webview myself.

Actual Behavior

I do not get the new-window event when the web page attempts to open the new tab. However, if I specify allowpopups='true' on my webview, I do get the event. But in this case Electron opens a new BrowserWindow and there's apparently nothing I can do to stop it.

Testcase Gist URL

No response

Additional Information

No response

@Kilian
Copy link
Member

Kilian commented Aug 24, 2022

The new-window event is deprecated. You can use contents.setWindowOpenHandler(handler) instead which gives you more control over the handling.

@yurnery
Copy link

yurnery commented Aug 24, 2022

@Kilian this api is not for webview tag

@codebytere
Copy link
Member

That doesn't matter - the event is still deprecated and going away. You should, as kilian said, use contents.setWindowOpenHandler(handler). It's perfectly possible to get the id of the webcontents associated with the webview, which you can then use to get the webcontents itself, and then call setWindowOpenHandler

@codebytere codebytere closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2022
@toschlog
Copy link
Author

If I use setWindowOpenHandler() I do get notified, but the callback doesn't work as documented. I've set up my handler like this:

    webContents.setWindowOpenHandler(evt => {
        return {action: 'allow'}
    })

As I understand it, this should allow the window to open. But it doesn't. I don't get the pop-up window, and the link opens in the existing <webview>.

@yurnery
Copy link

yurnery commented Aug 25, 2022

@toschlog How to access webContents? Is it a webview property?

@toschlog
Copy link
Author

@toschlog How to access webContents? Is it a webview property?

Like this:

    let remote = window.require('@electron/remote')
    let webContents = remote.webContents.fromId(webview.getWebContentsId())

@yurnery
Copy link

yurnery commented Aug 25, 2022

Thanks

@toschlog
Copy link
Author

@Kilian @codebytere Anything on setWindowOpenHandler() not working correctly? Should I create a new ticket? Or can we reopen this one?

@miniak
Copy link
Contributor

miniak commented Sep 8, 2022

FYI the new-window event was removed in #34526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants