Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

preload script for webview not working when contextIsolation is activated #292

Open
leofidus opened this issue Mar 2, 2018 · 1 comment

Comments

@leofidus
Copy link

leofidus commented Mar 2, 2018

My electron app includes a webview tag with preload script. I would like to use typescript for the preload script, but electron-prebuilt-compile doesn't compile it. I tried following https://github.com/electron-userland/electron-forge/wiki/Using-'preload'-scripts (as suggested in #259), but that doesn't work. Instead I get the following on the dev console:

Unable to load preload script: [[PROJECTDIR]]\src\preload-launcher.js

Error: Failed to execute 'registerElement' on 'Document': Registration failed for type 'x-require'. Elements cannot be registered from extensions.
    at exports.default ([[PROJECTDIR]]\node_modules\electron-compile\lib\x-require.js:51:19)
    at Object.<anonymous> ([[PROJECTDIR]]\node_modules\electron-compile\lib\x-require.js:52:3)
    at Object.<anonymous> ([[PROJECTDIR]]\node_modules\electron-compile\lib\x-require.js:54:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
@leofidus
Copy link
Author

leofidus commented Mar 3, 2018

Turns out that the problem disappears and the linked wiki entry works if I don't enable contextIsolation for the webview. With contextIsolation, I get the previously mentioned error.

This is an acceptable workaround for development, but I would very much like to have Context Isolation active if possible. Is it possible to make electron-compile cooperate with context isolation?

@leofidus leofidus changed the title preload script for webview not working preload script for webview not working when contextIsolation is activated Mar 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant