Skip to content

Fix race condition when initializing node integration - #1044

Merged
zcbenz merged 15 commits into
masterfrom
load-environment-later
Jan 25, 2015
Merged

zcbenz merged 15 commits into
masterfrom
load-environment-later

Conversation

@zcbenz

@zcbenz zcbenz commented Jan 22, 2015

Copy link
Copy Markdown
Contributor
  1. The custom atom-shell APIs are now injected before we initialize in JavaScript, making the JavaScript code more clear.
  2. Lots of cleanups of the node integration code.
  3. We now do not initialize node integration in iframes, because you can either use <webview> instead, or just access node integration in parent frame. This greatly simplified the node integration code in renderer process, also fixes Having multiple JavaScript contexts causes a race condition in uv event loop handling #894 and fixes add/remove iframe cause memory leak #789.
  4. Don't deal with browser messages when the document object is not ready, fixes Can't require node modules in renderer process in v0.20.6 without a refresh #1028 and fixes WebView frequently fails to load the node-related globals when there are multiple instance in a browser window  #1038.

@zcbenz

zcbenz commented Jan 22, 2015

Copy link
Copy Markdown
Contributor Author

@paulcbetts Can you test if this fixes #1028 for your?

@anaisbetts

Copy link
Copy Markdown
Contributor

@zcbenz no dice :( Patched init.js:

  global.wtf = [];
  wtf.push(window.location.href);
  wtf.push(window.location.protocol);

  if (nodeIntegration === 'true' || nodeIntegration === 'all' || nodeIntegration === 'except-iframe' || nodeIntegration === 'manual-enable-iframe') {
 /* ... */
navigator.userAgent
>> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Slack/0.5.1-d32528a Chrome/39.0.2171.65 AtomShell/0.20.7 Safari/537.36"

global.wtf
>> ["about:blank", "about:"]

@zcbenz

zcbenz commented Jan 22, 2015

Copy link
Copy Markdown
Contributor Author

@paulcbetts Can you provide a minimal app that shows this problem? I wonder if it only occurs when we used some APIs in code, because I never encountered a similar problem in Atom editor.

@anaisbetts

Copy link
Copy Markdown
Contributor

@zcbenz I can work on that, yeah - I'm out today but I'll have a look tonight

@zcbenz

zcbenz commented Jan 22, 2015

Copy link
Copy Markdown
Contributor Author

@paulcbetts Cool, thanks!

When we recevied messages from browser, we will try to transfer the
message to web page, and when we do that blink will create an empty
document when there is no document object yet, which will make our init
script run when window.location is still about:blank.
@zcbenz zcbenz changed the title Load node integration after window object is cleared Fix race condition when initializing node integration Jan 24, 2015
@zcbenz

zcbenz commented Jan 24, 2015

Copy link
Copy Markdown
Contributor Author

@paulcbetts #1028 should have been fixed by 0bcc9b7, can you have a test of this branch?

@anaisbetts

Copy link
Copy Markdown
Contributor

Works perfectly! 🎉

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

Labels

None yet

Projects

None yet

2 participants