You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Loading native modules twice during navigation results in "Native module did not self-register" #4025
In the Slack app, we have a webview with a preload script that defines a global variable.
On 0.36.1 and previous releases, when navigation is performed, the preload script is re-run and the global variable is recreated.
On 0.36.2, navigation destroys the global variables and the preload script isn't run again.
@zcbenz I thought it was due to a POST as this occurs in our login dialog. Tried to reproduce it in an Electron test but couldn't make it fail in 0.36.2. 😕 Only reliable repro I have is in the Slack app (we'll keep investigating).
Alright, I'm making some progress on this one, this seems related to native modules somehow. Our preload script is actually running but silently failing (this is a bug imho, but not the bug).
It seems as if, once navigation occurs, native modules fail with "Module failed to self-register":
I set this in the preload:
window.requireeee = require;
Then running this in console fails only after a navigation:
FWIW, in 0.36.5 I was only able to trigger the problem on pages that were loading new frames/pages in the webview via javascript, like oauth screens. I suspected this was causing the native modules to double-load, which seems likely given the above.
As a temporary workaround, I just looked a the URL and disabled the modules on those pages.
This behavior is still happening. We haven't noticed it for a while because we just stopped loading native modules on our sign-in page, but for Product Reasons™ there are now cases where the main page goes through the same set of redirects, we try to load native modules twice, and hit the Native module did not self-register error (mysteriously, only sometimes).
I tried on 1.6.2, 1.6.7, but it probably goes way further back.
changed the title [-]Navigation restarts renderer, but loses preload[/-][+]Loading native modules twice during navigation results in "Native module did not self-register"[/+]on Apr 24, 2017
Fiddled with this a bit more and came up with a workaround; if you wait for dom-ready you never hit the native module load bug. Proof of concept here: CharlieHess/webview-preload-globals#1.
This behaviour is also happening in webContents using the new feature nativeWindowOpen and this happens every time when you open a new window using window.open or _blank.
Activity
zcbenz commentedon Jan 8, 2016
@CharlieHess I'm having trouble reproduce the problem, can you work out a test case?
CharlieHess commentedon Jan 9, 2016
@zcbenz I thought it was due to a POST as this occurs in our login dialog. Tried to reproduce it in an Electron test but couldn't make it fail in 0.36.2. 😕 Only reliable repro I have is in the Slack app (we'll keep investigating).
kevinsawicki commentedon Jan 21, 2016
@CharlieHess any updates on your investigations?
CharlieHess commentedon Jan 27, 2016
@kevinsawicki: Nah, we stuck to 0.36.1 and sidelined it for now. We'll come back to this issue 🔜 since we'll inevitably need to upgrade.
anaisbetts commentedon Jan 27, 2016
@kevinsawicki This is On My List
anaisbetts commentedon Jan 27, 2016
Alright, I'm making some progress on this one, this seems related to native modules somehow. Our preload script is actually running but silently failing (this is a bug imho, but not the bug).
It seems as if, once navigation occurs, native modules fail with "Module failed to self-register":
I set this in the preload:
Then running this in console fails only after a navigation:
anaisbetts commentedon Jan 27, 2016
The most likely candidate for this bug is #3875
zcbenz commentedon Jan 27, 2016
@paulcbetts It seems like that the renderer process was not restarted, can you print out
process.pidto verify that?anaisbetts commentedon Jan 27, 2016
@zcbenz Ya, they're the same on navigate - this probably means that we're trying to double-load native modules
aggregatejeff commentedon Jan 27, 2016
FWIW, in 0.36.5 I was only able to trigger the problem on pages that were loading new frames/pages in the webview via javascript, like oauth screens. I suspected this was causing the native modules to double-load, which seems likely given the above.
As a temporary workaround, I just looked a the URL and disabled the modules on those pages.
CharlieHess commentedon Apr 24, 2017
This behavior is still happening. We haven't noticed it for a while because we just stopped loading native modules on our sign-in page, but for Product Reasons™ there are now cases where the main page goes through the same set of redirects, we try to load native modules twice, and hit the
Native module did not self-registererror (mysteriously, only sometimes).I tried on 1.6.2, 1.6.7, but it probably goes way further back.
How to reproduce
I setup a minimal repro here: https://github.com/CharlieHess/webview-preload-globals.
[-]Navigation restarts renderer, but loses preload[/-][+]Loading native modules twice during navigation results in "Native module did not self-register"[/+]CharlieHess commentedon Apr 25, 2017
Fiddled with this a bit more and came up with a workaround; if you wait for
dom-readyyou never hit the native module load bug. Proof of concept here: CharlieHess/webview-preload-globals#1.KiranNiranjan commentedon Jul 25, 2017
Uncaught Error: Module did not self-register.This behaviour is also happening in
webContentsusing the new featurenativeWindowOpenand this happens every time when you open a new window usingwindow.openor_blank.Here is a simple app where you can reproduce this issue:
https://github.com/KiranNiranjan/electron-preload-bug
codebytere commentedon Mar 25, 2020
This can be closed now that we are planning to force context-awareness for native modules and disallow renderer process reuse as discussed in #18397.