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
Webview preload script not surviving webview src change #1843
I stated 0.27.2 in the issue topic but for me it broke after 0.23. I need a sanity check here. I'm doing a very basic ping/pong type IPC with my applications main window and a webview. This works perfectly fine for me on version 0.23.0 but breaks at 0.24.0 and all the way up to today with 0.27.2. I've looked at the dev tools for the webview and I can tell that my preload script is running but doing any IPC sends never makes it to the webview.
Same code works fine in 0.23.0 and breaks in 0.24 -> 0.27.2.
I'm doing exactly the same very basic IPC as listed in:
// In embedder page.webview.addEventListener('ipc-message',function(event){console.log(event.channel);// Prints "pong"});webview.send('ping');
.....// In guest page.varipc=require('ipc');ipc.on('ping',function(){ipc.sendToHost('pong');})
Is anyone else having issues with IPC in webviews?
Thanks for that! I was able to get a small sample running with a basic ping/pong. I think my problem is that when setting the src of the webview IPC doesn't respond. This is my theory at the moment, I'm going to try my little test app to see if IPC survives after changing src.
When that example is ran it opens a website in a webview, kicks off ping/pong messages and logs them to the console in the dev tools on the main window and webview. At 10 seconds the src is changed to another website. The webview node context is reset? The preload script code is gone and IPC no longer works.
I just want to stress that version 0.23 works and IPC survives a webview src change. Versions of Electron 0.24 and newer all fail.
The following issue may also be related: #1823
Another possible related issue: #1820
And another one (dang!) #1754
I am not using nodeintegration in my particular case. The interesting bit is that changing src is blowing things up. I'm looking into the code now to see if I can see anything that may have changed with webview.
@frankhale Have you tried the latest release binaries(electron v0.27.3)? I found that the preload attribute still doesn't work properly.
Here are the steps:
Create a webview html element, the src is 'about:blank'. Then change the src to a url. It works.
Create a new webview html element again, the src is 'about:blank'. Then change the src to the url of step1. It doesn't work.
Create a new webview html element again, the src is 'about:blank'. Then change the src to a new url(not same with step1). It doesn't work.
Also, I have tried those steps:
Create a webview html element, the src is a url. It works.
Create a new webview html element, the src is same with step 1. It doesn't work.
Create a new webview html element, the src is not same with step 1. It doesn't work.
@zcbenz Please help to check the steps when you are available.
@zcbenz After I tried more, I found that if you change the src to different site(in other words, different domain), it works. And then, if I change the src to the page in the site again, it doesn't work.
@steem, I haven't tried 0.27.3 yet but I did compile from master and was using the fix. I have not seen any weird issues with preload with patch #1850 because I am only creating one webview and reusing it for my entire application life cycle. It seems to work fine for me in that particular case.
@frankhale@zcbenz I have tried one webview today, still doesn't work after changing the src two times(note: the src is same). I also have tried reload method, it only works at the first time.
My test js code is very simple:
@zcbenz I debug the code and find that the it may be caused by v8 engine. The first call of reload will cause the AtomBrowserClient::AppendExtraCommandLineSwitches be called. But if you call reload again, AtomBrowserClient::AppendExtraCommandLineSwitches won't be called. WebContents::LoadURL will be called each time when calling reload.
The v8 code is libchromiumcontent, where can I get the code and build it?
@zcbenz@frankhale Finally, I found that it's caused by the following line:
app.commandLine.appendSwitch('process-per-site');
After I delete it, it works. If not, after calling reload one time, it doesn't work. Even if you create a new webview, and initialize the src to any page of a website, it doesn't work after one time.
So, libchromiumcontent may not call AtomBrowserClient::AppendExtraCommandLineSwitches if in 'process-per-site' mode in some cases. Currently, I don't have time to debug libchromiumcontent. @zcbenz , if you are available, please help to check it.
@steem Thanks for debugging this! Sorry I didn't have time to look into it.
In Electron every page is forced to use its own process, which is necessary for the node integration support, so if you pass process-per-site to Chromium some pages will then be forced to share the same process, and node integration won't work for them.
Chromium process model won't create new process if the max process number is reached. Just worry about that whether the issue may come up when the max process number is reached.
Activity
anaisbetts commentedon Jun 1, 2015
This is working for us in the Slack app, but one thing we've always had to do is patch the
processvariable back in viaprocess.nextTick:frankhale commentedon Jun 1, 2015
Thanks for that! I was able to get a small sample running with a basic ping/pong. I think my problem is that when setting the src of the webview IPC doesn't respond. This is my theory at the moment, I'm going to try my little test app to see if IPC survives after changing src.
frankhale commentedon Jun 1, 2015
Yep, after src is changed IPC stops working. Or rather the code that was set in my preload is no longer there to run.
[-]Is IPC broken for webviews in 0.27.2?[/-][+]Webview preload script not surviving webview src change[/+]frankhale commentedon Jun 1, 2015
Here is a small example to demonstrate the behavior.
https://github.com/frankhale/electron-webview-ipc-test
When that example is ran it opens a website in a webview, kicks off ping/pong messages and logs them to the console in the dev tools on the main window and webview. At 10 seconds the src is changed to another website. The webview node context is reset? The preload script code is gone and IPC no longer works.
I just want to stress that version 0.23 works and IPC survives a webview src change. Versions of Electron 0.24 and newer all fail.
The following issue may also be related: #1823
Another possible related issue: #1820
And another one (dang!) #1754
I am not using nodeintegration in my particular case. The interesting bit is that changing src is blowing things up. I'm looking into the code now to see if I can see anything that may have changed with webview.
frankhale commentedon Jun 3, 2015
Thank you!!
steem commentedon Jun 8, 2015
@frankhale Have you tried the latest release binaries(electron v0.27.3)? I found that the preload attribute still doesn't work properly.
Here are the steps:
Also, I have tried those steps:
@zcbenz Please help to check the steps when you are available.
Thanks!
steem commentedon Jun 8, 2015
@zcbenz After I tried more, I found that if you change the src to different site(in other words, different domain), it works. And then, if I change the src to the page in the site again, it doesn't work.
frankhale commentedon Jun 8, 2015
@steem, I haven't tried 0.27.3 yet but I did compile from master and was using the fix. I have not seen any weird issues with preload with patch #1850 because I am only creating one webview and reusing it for my entire application life cycle. It seems to work fine for me in that particular case.
steem commentedon Jun 9, 2015
@frankhale @zcbenz I have tried one webview today, still doesn't work after changing the src two times(note: the src is same). I also have tried reload method, it only works at the first time.
My test js code is very simple:
Using 'console-message' event to echo the message.
zcbenz commentedon Jun 9, 2015
@steem Changing src to the same value will be ignored, if you want a refresh you should call
reload.steem commentedon Jun 9, 2015
@zcbenz Yes, I use reload, but still doesn't work :(
zcbenz commentedon Jun 9, 2015
Can you provide an example? Following code works for me:
/tmp/test.js:
In devtools:
steem commentedon Jun 9, 2015
@zcbenz Here is the sample code:
HTML:
op_min.js
If you click the refresh button, the op_min.js only works at the first two click.
I found that you use absolute path for preload, I will try it again and give you the result.
Updates:
The issue still exists if you use absolute path for preload.
steem commentedon Jun 10, 2015
@zcbenz I debug the code and find that the it may be caused by v8 engine. The first call of reload will cause the AtomBrowserClient::AppendExtraCommandLineSwitches be called. But if you call reload again, AtomBrowserClient::AppendExtraCommandLineSwitches won't be called. WebContents::LoadURL will be called each time when calling reload.
The v8 code is libchromiumcontent, where can I get the code and build it?
Updates:
It seems that libchromiumcontent code is here: https://github.com/atom/libchromiumcontent. I will try to build it.
steem commentedon Jun 12, 2015
@zcbenz @frankhale Finally, I found that it's caused by the following line:
app.commandLine.appendSwitch('process-per-site');
After I delete it, it works. If not, after calling reload one time, it doesn't work. Even if you create a new webview, and initialize the src to any page of a website, it doesn't work after one time.
So, libchromiumcontent may not call AtomBrowserClient::AppendExtraCommandLineSwitches if in 'process-per-site' mode in some cases. Currently, I don't have time to debug libchromiumcontent. @zcbenz , if you are available, please help to check it.
Thanks!
zcbenz commentedon Jun 12, 2015
@steem Thanks for debugging this! Sorry I didn't have time to look into it.
In Electron every page is forced to use its own process, which is necessary for the node integration support, so if you pass
process-per-siteto Chromium some pages will then be forced to share the same process, and node integration won't work for them.frozeman commentedon Jun 12, 2015
I'm on 0.26.0 and as soon as i change the src, or navigate to another domain, i lose the preloaded script.
Is this issue not yet in 0.26.0 resolved?
steem commentedon Jun 14, 2015
@zcbenz Ok, I see.
Chromium process model won't create new process if the max process number is reached. Just worry about that whether the issue may come up when the max process number is reached.
frozeman commentedon Jun 15, 2015
The problem still persists for me at 0.26.0.
frozeman commentedon Jun 16, 2015
works on 0.28.0 👍
mschnee commentedon Sep 8, 2015
This bug appears to have returned as of 0.31.2: specifically when the WebView's location is changed via navigation or reloading in the WebView itself.
Example project here:
https://github.com/mschnee/electron-bug-example
zcbenz commentedon Sep 9, 2015
@mschnee Which operating system are you using? And can you reproduce on 0.32.0?
mschnee commentedon Sep 9, 2015
@zcbenz Verified as working in [email protected] on Windows 10, OSX 10.10, and Linux (gentoo x64, vanilla kernel 4.2)
Apologies for necro'ing a bug, looks like you beat me to it!