Skip to content

Commit a15db71

Browse files
committed
Add dom-ready event for WebContents
1 parent 23f4d39 commit a15db71

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/ElectronNET.API/WebContents.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,35 @@ public event Action<InputEvent> InputEvent
114114

115115
private event Action<InputEvent> _inputEvent;
116116

117+
/// <summary>
118+
/// Emitted when the document in the top-level frame is loaded.
119+
/// </summary>
120+
public event Action OnDomReady
121+
{
122+
add
123+
{
124+
if (_domReady == null)
125+
{
126+
BridgeConnector.Socket.On("webContents-domReady" + Id, () =>
127+
{
128+
_domReady();
129+
});
130+
131+
BridgeConnector.Socket.Emit("register-webContents-domReady", Id);
132+
}
133+
_domReady += value;
134+
}
135+
remove
136+
{
137+
_domReady -= value;
138+
139+
if (_domReady == null)
140+
BridgeConnector.Socket.Off("webContents-domReady" + Id);
141+
}
142+
}
143+
144+
private event Action _domReady;
145+
117146
internal WebContents(int id)
118147
{
119148
Id = id;

src/ElectronNET.Host/api/webContents.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/webContents.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export = (socket: Socket) => {
3535
});
3636
});
3737

38+
socket.on('register-webContents-domReady', (id) => {
39+
const browserWindow = getWindowById(id);
40+
41+
browserWindow.webContents.removeAllListeners('dom-ready');
42+
browserWindow.webContents.on('dom-ready', () => {
43+
electronSocket.emit('webContents-domReady' + id);
44+
});
45+
});
46+
3847
socket.on('webContentsOpenDevTools', (id, options) => {
3948
if (options) {
4049
getWindowById(id).webContents.openDevTools(options);

0 commit comments

Comments
 (0)