Electron: WebContents `dom-ready` event

Created on 27 Apr 2015  ·  3Comments  ·  Source: electron/electron

I would like to use WebContents.insertCSS() as soon as the DOM is ready.

I tried using WebContents.on('did-finish-load'), but you can see the page being loaded before the CSS is applied.

My workaround is to have the following in a preload JS file:

document.addEventListener('DOMContentLoaded', function () {
    ipc.send('dom-ready');
});

and listen to the IPC event in the main renderer.

But it would be a lot nicer to have an event for this.

enhancement

All 3 comments

How does one use this? Id like to add CSS for the whole app.

@kylebrowning Like you should always do before asking, read the docs.

@sindresorhus Yeah I've gone over that I should have been more clear. Id like to add a whole file, not just some string. Which is unrelated to this ticket.

Was this page helpful?
0 / 5 - 0 ratings