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
Support Node / Preload scripts in iframes or workers #12505
Console will emit true/false for whether the preload ran in the renderer, an iframe, and a worker. At time of writing this demo, only true for renderer.
git clone https://github.com/pfrazee/electron-bug-test-preload
cd electron-bug-test-preload
npm install
npm start
Reacted by Timothy MacIntyre, Ionut Balcau, Andrew Novikov, AbnerLee and Zack Boehm
This would be a great enhancement. I've also tried using extensions to run code within iframes, and that does not work either. Seems like the extension manifest option "all_frames" is also not supported within electron. So, as far as I can tell, there is no way to accomplish running a script within an iframe similar to how a preload script works for a webview.
@pfrazee, I'd be happy to help out in any way if you needed.
The approach I took was to set nodeIntegrationInWorker to true in my test app and then copy over a lot of behaviors from the lib/renderer JS.
Results of this exploration:
I was able to successfully include the session preloads.
Through some hacks, I was able to get the ipcRenderer API in my preload, but the methods didn't work because the internal implementation didn't find a frame for the Worker. At that point I was out of my depth so I quit. (Note, the ipcRenderer is the only reason I want preloads in iframes and workers: I use it to add Web APIs.)
I believe this approach requires node to be attached to every Web Worker, regardless of whether a preload script is being used or nodeIntegrationInWorker is enabled. I assume that's the same cost behind every other preload script.
changed the title [-]Session setPreloads() not working for iframes or workers[/-][+]Support Node / Preload scripts in iframes or workers[/+]on Jan 8, 2019
is it possible to run preloads when nodeIntegrationInSubFrames is false? nodeIntegrationInSubFrames breaks the code in my iframes as they don't expect the node stuff to be defined, and they break if it is. but i need to run the preloads there regardless. is this possible?
Sorry for resurrecting an old issue...
It looks like preload scripts don't run in web workers, it looks like it only the PR only implemented it for iframes #16425, right? I wonder if supporting preloads for web workers can be added as well?
Reacted by LyokoJeremie, Tasos Bitsios and beyondkmp
Activity
MarshallOfSound commentedon Apr 2, 2018
Please note that that PR wasn't intended to make preloads run in iframes. This should be considered an enhancement request not a bug 👍
pfrazee commentedon Apr 2, 2018
@MarshallOfSound Oh my bad, I misread that.
Well if there's nobody that can hit the enhancement easily, I can try to slot some time to implement it.
Tim91084 commentedon Apr 13, 2018
This would be a great enhancement. I've also tried using extensions to run code within iframes, and that does not work either. Seems like the extension manifest option "all_frames" is also not supported within electron. So, as far as I can tell, there is no way to accomplish running a script within an iframe similar to how a preload script works for a webview.
@pfrazee, I'd be happy to help out in any way if you needed.
pfrazee commentedon Apr 13, 2018
pfrazee commentedon Jul 4, 2018
I explored what this might require for Web Workers. See the changes made here: master...pfrazee:worker-preload-exploration
The approach I took was to set
nodeIntegrationInWorkertotruein my test app and then copy over a lot of behaviors from thelib/rendererJS.Results of this exploration:
ipcRendererAPI in my preload, but the methods didn't work because the internal implementation didn't find a frame for the Worker. At that point I was out of my depth so I quit. (Note, theipcRendereris the only reason I want preloads in iframes and workers: I use it to add Web APIs.)I believe this approach requires node to be attached to every Web Worker, regardless of whether a preload script is being used or
nodeIntegrationInWorkeris enabled. I assume that's the same cost behind every other preload script.Hope this was helpful.
InputNeuron commentedon Aug 15, 2018
Seems like this is still broken as of 3.0.0-beta4
[-]Session setPreloads() not working for iframes or workers[/-][+]Support Node / Preload scripts in iframes or workers[/+]feat: add support for node / preloads in subframes
feat: add support for node / preloads in subframes
pfrazee commentedon Jan 22, 2019
@MarshallOfSound 🎉 !
feat: preloads and nodeIntegration in iframes (#16425)
feat: preloads and nodeIntegration in iframes (#16425)
Spongman commentedon Aug 4, 2019
is it possible to run preloads when
nodeIntegrationInSubFramesis false?nodeIntegrationInSubFramesbreaks the code in my iframes as they don't expect the node stuff to be defined, and they break if it is. but i need to run the preloads there regardless. is this possible?MarshallOfSound commentedon Aug 4, 2019
@Spongman
nodeIntegrationInSubFrames: true&&nodeIntegration: falseObi-Dann commentedon Oct 9, 2020
Sorry for resurrecting an old issue...
It looks like
preloadscripts don't run in web workers, it looks like it only the PR only implemented it for iframes #16425, right? I wonder if supporting preloads for web workers can be added as well?