Skip to content

Fix window.opener being null when nativeWindowOpen is used - #9961

Merged
zcbenz merged 3 commits into
masterfrom
fix-window-opener
Aug 4, 2017
Merged

zcbenz merged 3 commits into
masterfrom
fix-window-opener

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Fixes #9581 #8100 #9533

Not 100% sure if this is the correct fix but (a) it works and (b) it looks right to me 😆

/cc @zcbenz @kevinsawicki Can you make sure this isn't doing something silly

@MarshallOfSound

Copy link
Copy Markdown
Member Author

This appears to cause the renderer process to crash after the second navigation. This is due to the webContents launched from window.open not maintaining the nativeWindowOpen: true property resulting in the above check being false 😕 Exploring how to detect this atm

@MarshallOfSound

Copy link
Copy Markdown
Member Author

Two additional things here.

  • Child windows now inherit the nativeWindowOpen setting of the opener
  • We now check directly against the web contents as at RenderProcessWillLaunch the web contents isn't actually ready so the webPreferences we save are just the defaults every time

@MarshallOfSound

Copy link
Copy Markdown
Member Author

The newly opened window appears to crash when switching domains in some cases, can't figure out why. If anyone has any ideas would be appreciated 👍

@gerges-zz

gerges-zz commented Jul 9, 2017 •

Copy link
Copy Markdown

Haven't confirmed, but possibly related to if window.open is called directly from a <webview> or from an <iframe> inside a <webview>

@kevinsawicki

Copy link
Copy Markdown
Contributor

Child windows now inherit the nativeWindowOpen setting of the opener

Yeah, I was looking into this a bit as well via #9928, I think we need to get all the preferences supported that can overridden via new-window so that they properly take effect if set via that event, right now I believe any overrides are ignored when it is triggered via -add-new-contents.

@kevinsawicki

Copy link
Copy Markdown
Contributor

The newly opened window appears to crash when switching domains in some cases, can't figure out why.

Do you have the stack trace for this crash?

@MarshallOfSound

Copy link
Copy Markdown
Member Author

Do you have the stack trace for this crash?

@kevinsawicki As much as I try I can't get Electron to dump a crash stack on me. The renderer window just closes by itself just after a page navigation is started. Repro is as easy as window.open('https://www.google.com') then just search around and go to a different site, it should crash.

@MarshallOfSound

Copy link
Copy Markdown
Member Author

Just figured out how to stop the random crash on navigation in the opened window

Pinging @electron/maintainers this is a pretty important fix for window.open compatibility, would be good to get some 👀 on it and hopefully some ✔️

Comment thread atom/browser/atom_browser_client.cc Outdated
// reuse the same site to allow cross-window scripting. We do
// not need to check urls / domains as native window open logic
// handles cross site scripting protection.
if (WebContentsPreferences::UsesNativeWindowOpen(web_contents)) {

@poiru poiru Jul 30, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is effectively if (true) since we already checked for if (!WebContentsPreferences::UsesNativeWindowOpen(web_contents)) above. Could you remove the unnecessary check?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yeah, thought it would be good to be explicit in code though. I'll change it to still be explicit but not fetch the preferences twice 👍

Comment thread atom/browser/atom_browser_client.cc Outdated
//
// NOTE: We know that nativeWindowOpen is enabled at this point
// because we check if it is NOT enabled above this point. We
// will only reach this return if sanbox is disabled but

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iframe window.open broken

6 participants