diff --git a/src/ElectronNET.API/API/BrowserWindow.cs b/src/ElectronNET.API/API/BrowserWindow.cs
index d74b82c..012cbfb 100644
--- a/src/ElectronNET.API/API/BrowserWindow.cs
+++ b/src/ElectronNET.API/API/BrowserWindow.cs
@@ -1140,7 +1140,17 @@ public class BrowserWindow : ApiBase
/// passing null will turn current window into a top-level window.
///
///
- public void SetParentWindow(BrowserWindow parent) => this.CallMethod1(JObject.FromObject(parent, _jsonSerializer));
+ public void SetParentWindow(BrowserWindow parent)
+ {
+ if (parent == null)
+ {
+ BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, null);
+ }
+ else
+ {
+ BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
+ }
+ }
///
/// The parent window.
diff --git a/src/ElectronNET.Host/api/browserWindows.ts b/src/ElectronNET.Host/api/browserWindows.ts
index a6a56a5..b231742 100644
--- a/src/ElectronNET.Host/api/browserWindows.ts
+++ b/src/ElectronNET.Host/api/browserWindows.ts
@@ -721,9 +721,14 @@ export = (socket: Socket, app: Electron.App) => {
});
socket.on('browserWindowSetParentWindow', (id, parent) => {
+ const child = getWindowById(id);
+ if (!parent) {
+ // Clear parent: make this window top-level
+ child.setParentWindow(null);
+ return;
+ }
const browserWindow = BrowserWindow.fromId(parent.id);
-
- getWindowById(id).setParentWindow(browserWindow);
+ child.setParentWindow(browserWindow);
});
socket.on('browserWindowGetParentWindow', (id) => {