fixed headless-browser.js getting stuck on background when closing

This commit is contained in:
2025-11-25 19:52:23 +01:00
parent 1e1eaab43c
commit ccda892d18
2 changed files with 17 additions and 0 deletions

View File

@@ -68,6 +68,7 @@ function createWindow() {
mainWindow.loadFile('views/index.html');
mainWindow.setMenu(null);
mainWindow.on('closed', () => { headlessBrowser.forceKill(); });
}
app.whenReady().then(() => {

View File

@@ -176,6 +176,22 @@ class HeadlessBrowser {
`;
await win.webContents.executeJavaScript(script);
}
forceKill() {
try {
if (this.win && !this.win.isDestroyed()) {
const wc = this.win.webContents;
try { wc.stop(); } catch (_) {}
try { wc.close(); } catch (_) {}
try { wc.destroy(); } catch (_) {}
this.win.destroy();
}
} catch (_) {}
this.win = null;
}
}
module.exports = new HeadlessBrowser();