Skip to content

Loading native modules twice during navigation results in "Native module did not self-register" #4025

Closed

Description

@CharlieHess

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.

Activity

  1. zcbenz commented on Jan 8, 2016

    @zcbenz
    Contributor

    @CharlieHess I'm having trouble reproduce the problem, can you work out a test case?

  2. CharlieHess commented on Jan 9, 2016

    @CharlieHess
    ContributorAuthor

    @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).

  3. kevinsawicki commented on Jan 21, 2016

    @kevinsawicki
    Contributor

    Only reliable repro I have is in the Slack app (we'll keep investigating).

    @CharlieHess any updates on your investigations?

  4. CharlieHess commented on Jan 27, 2016

    @CharlieHess
    ContributorAuthor

    @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.

  5. anaisbetts commented on Jan 27, 2016

    @anaisbetts
    Contributor

    @kevinsawicki This is On My List

  6. anaisbetts commented on Jan 27, 2016

    @anaisbetts
    Contributor

    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:

  7. anaisbetts commented on Jan 27, 2016

    @anaisbetts
    Contributor

    The most likely candidate for this bug is #3875

  8. zcbenz commented on Jan 27, 2016

    @zcbenz
    Contributor

    @paulcbetts It seems like that the renderer process was not restarted, can you print out process.pid to verify that?

  9. anaisbetts commented on Jan 27, 2016

    @anaisbetts
    Contributor

    @zcbenz Ya, they're the same on navigate - this probably means that we're trying to double-load native modules

  10. aggregatejeff commented on Jan 27, 2016

    @aggregatejeff

    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.

  11. CharlieHess commented on Apr 24, 2017

    @CharlieHess
    ContributorAuthor

    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.

    How to reproduce

    I setup a minimal repro here: https://github.com/CharlieHess/webview-preload-globals.

  12. 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
  13. CharlieHess commented on Apr 25, 2017

    @CharlieHess
    ContributorAuthor

    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.

  14. KiranNiranjan commented on Jul 25, 2017

    @KiranNiranjan

    Uncaught Error: Module did not self-register.

    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.

    • Electron ver: 1.7.5
    • Operating sys: macOS Sierra

    Here is a simple app where you can reproduce this issue:
    https://github.com/KiranNiranjan/electron-preload-bug

  15. codebytere commented on Mar 25, 2020

    @codebytere
    Member

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions