[英]Electron preload script for webview not working?
我有這個webview,我加載如下:
<webview id="link-view"
src="http://url.espace.com/"
preload="./preload.js"
autosize="on"
partition="persist:link"></webview>
在preload.js文件中:我有這個
console.log("test");
這甚至不起作用..
誰能解釋一下?
我只是嘗試了相同的場景,它按預期工作。
你有<webview>
開發工具嗎? 由於<webview>
有自己的開發工具,這是我可以看到preload腳本沒有顯示console.log
輸出的唯一原因。 他們可以打開:
var webview = document.getElementById("link-view");
webview.openDevTools();
或者你的腳本路徑不正確,我懷疑你看起來很確定。
使用最新的Electron 2.0.0 ( beta-5
,在撰寫本文時), preload
屬性需要一個file:
或asar:
協議,后跟一個絕對路徑。 諸如./preload.js
之類的路徑似乎不再起作用並引發異常: 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`}/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.