Add webview.loadURL
Could you please expose the extraHeaders option from WebContents.loadURL as a WebView attribute? It would also be great to have access to loadURL on WebView as a method (like BrowserWindow). Thanks
Adding loadURL to webview looks good to me. However adding extraHeaders attribute seems unnecessary, you can use the webRequest API.
loadURL on webview would be great.
@zcbenz is it as simple as this? https://github.com/atom/electron/pull/4186
yep.
having some trouble with this API. If I dont have the src attribute in the webview to start with, then the loadURL gives an error -
function updateWebviewURL(u) { var webv = document.getElementById('mainwebview'); if (webv) { webv.loadURL(u); webv.style.display = 'block'; } };
Uncaught TypeError: Cannot read property 'loadURL' of undefined node_modules/electron-prebuilt/dist/Electron.app/Contents/Resources/atom.asar/renderer/lib/web-view/web-view.js:410
using electron-prebuilt version 0.36.7
Anyone else seen this scenario?
Yeah, I am having the same issue! The documentation states that you should use the dom-ready event first:
webview.addEventListener("dom-ready", function() {
webview.openDevTools();
});
But trying to use .loadURL inside this event's callback will trigger the dom-ready event again once it's loaded, which calls the .loadURL!!
Yes this is indeed how it works. I dealt with this by just checking whether this is the initial load or not.
Rishi Bhargava 408-905-8344 Demisto.comhttp://www.demisto.com/
From: Ahmed Zain <[email protected]mailto:[email protected]> Reply-To: atom/electron <[email protected]mailto:[email protected]> Date: Monday, March 14, 2016 at 5:09 AM To: atom/electron <[email protected]mailto:[email protected]> Cc: Rishi Bhargava <[email protected]mailto:[email protected]> Subject: Re: [electron] Add webview.loadURL (#4101)
Yeah, I am having the same issue! The documentation states that you should use the dom-ready event first:
webview.addEventListener("dom-ready", function() { webview.openDevTools(); });
But trying to use .loadURL inside this event's callback will trigger the dom-ready event again once it's loaded, which calls the .loadURL!!
— Reply to this email directly or view it on GitHubhttps://github.com/atom/electron/issues/4101#issuecomment-196281255.
Sure, me too. But I think that there should be a closer look into this, or not. It's just a bit weird.
I'm having the exact same issue with 'webview.loadURL()', if I use it inside the 'dom-ready' handler it will fire the event again, and therefore create a URL loading bucle. Is this the intended behaviour?
I was having the same issue with the page below:
<webview id="app" preload="./preload.js" style="width:100%; height:100%">
</webview>
<script>
ipcRenderer.on('load-url', (events,url)=>{
webview.loadURL(url)
})
</script>
This will give the following error:
Uncaught Error: The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.
at HTMLElement.WebViewElement.getWebContentsId (web-view-impl.ts:223)
at HTMLElement.loadURL (web-view-impl.ts:266)
at EventEmitter.<anonymous> (index.html:8)
at EventEmitter.emit (events.js:210)
at Object.onMessage (init.ts:50)
Solution (More of a workaround)
Turns out this is caused by no source tag in webview. A quick workaround is just adding a dummy source to the initial webview
<webview id="app" preload="./preload.js" src=false style="width:100%; height:100%"></webview>
@FlameOfIgnis unfortunately that didn't work for me, same error message.
This is like pulling teeth. I thought I could fix this issue in 10-15 minutes, but it's now the second hour with no end in sight. We really have to load a site just to call loadURL?
I use innerHtml,
const url = 'Your website'
document.body.innerHTML= `<webview style="height:100%" src="${url}" disablewebsecurity id="wv"></webview>`
It's highly inadvisable to use disablewebsecurity.