I have this webview that I load like this:
<webview id="link-view"
src="http://url.espace.com/"
preload="./preload.js"
autosize="on"
partition="persist:link"></webview>
In the preload.js file : I have this
console.log("test");
This doesn't even work..
Can someone explain?
I just tried the same scenario, and it worked as expected.
Do you have the <webview>
dev tools open? As a <webview>
has its own dev tools, That would be the only reason i can see for the preload script not showing the console.log
output. They can be opened by:
var webview = document.getElementById("link-view");
webview.openDevTools();
Or your path to the script is incorrect, which i doubt as you seem sure about that.
Using latest Electron 2.0.0 ( beta-5
, at the time of this writing), the preload
attribute demands a file:
(or asar:
) protocol followed by an absolute path. Paths such as ./preload.js
don't seem to work anymore and raise an exception: Only "file:" protocol is supported in "preload" attribute.
这解决了我使用react.js在电子3.0.0-beta.4中的问题
<webview src={'http://example.com'} preload={`file://${__dirname}/preload.js`}/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.