Reputation: 206
Per the documentation on Electron's website, you have to wait until the webview element is available to actually use the methods that belong to it. Most methods work just fine, but I'm having some issues understanding the workflow of how the WebView's loadURL()
method can be applied programmatically.
The example on Electron's website
const webview = document.getElementById('foo')
webview.addEventListener('dom-ready', () => {
webview.openDevTools()
})
I want to use the <WebView>.loadURL(...)
method instead, because the WebView will load a URL programmatically, I tried this:
const webview = document.getElementById('foo')
webview.addEventListener('dom-ready', () => {
webview.loadURL('http://google.com')
})
The thing with this is that it actually triggers a repainting of the WebView (the dom-ready
event) itself producing a bucle of reloads, causing the URL to load uncountable times.
I see no further clarification of this issue on the official website, and certainly there is nothing on Google. Any help would be greatly appreciated.
Upvotes: 2
Views: 5794
Reputation: 10369
you need to use webview.removeEventListener, you can do it like this
const webview = document.getElementById('foo')
const loadPage = () => {
webview.loadURL('http://google.com');
webview.removeEventListener('dom-ready', loadPage);
};
webview.addEventListener('dom-ready', loadPage)
Upvotes: 3