diff --git a/src/ElectronNET.API/WebContents.cs b/src/ElectronNET.API/WebContents.cs index cf3c0eb..f77367c 100644 --- a/src/ElectronNET.API/WebContents.cs +++ b/src/ElectronNET.API/WebContents.cs @@ -114,6 +114,35 @@ public class WebContents private event Action _inputEvent; + /// + /// Emitted when the document in the top-level frame is loaded. + /// + public event Action OnDomReady + { + add + { + if (_domReady == null) + { + BridgeConnector.Socket.On("webContents-domReady" + Id, () => + { + _domReady(); + }); + + BridgeConnector.Socket.Emit("register-webContents-domReady", Id); + } + _domReady += value; + } + remove + { + _domReady -= value; + + if (_domReady == null) + BridgeConnector.Socket.Off("webContents-domReady" + Id); + } + } + + private event Action _domReady; + internal WebContents(int id) { Id = id; diff --git a/src/ElectronNET.Host/api/webContents.js b/src/ElectronNET.Host/api/webContents.js index 8df9711..cef8980 100644 --- a/src/ElectronNET.Host/api/webContents.js +++ b/src/ElectronNET.Host/api/webContents.js @@ -28,6 +28,16 @@ module.exports = (socket) => { } }); }); + + socket.on('register-webContents-domReady', (id) => { + const browserWindow = getWindowById(id); + + browserWindow.webContents.removeAllListeners('dom-ready'); + browserWindow.webContents.on('dom-ready', () => { + electronSocket.emit('webContents-domReady' + id); + }); + }); + socket.on('webContentsOpenDevTools', (id, options) => { if (options) { getWindowById(id).webContents.openDevTools(options); diff --git a/src/ElectronNET.Host/api/webContents.ts b/src/ElectronNET.Host/api/webContents.ts index 4bf6fdd..3f4b7af 100644 --- a/src/ElectronNET.Host/api/webContents.ts +++ b/src/ElectronNET.Host/api/webContents.ts @@ -35,6 +35,15 @@ export = (socket: Socket) => { }); }); + socket.on('register-webContents-domReady', (id) => { + const browserWindow = getWindowById(id); + + browserWindow.webContents.removeAllListeners('dom-ready'); + browserWindow.webContents.on('dom-ready', () => { + electronSocket.emit('webContents-domReady' + id); + }); + }); + socket.on('webContentsOpenDevTools', (id, options) => { if (options) { getWindowById(id).webContents.openDevTools(options);