electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

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

Open leofidus opened 6 years ago

leofidus commented 6 years ago

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 commented 6 years ago

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?