fixed headless-browser.js getting stuck on background when closing
This commit is contained in:
1
main.js
1
main.js
@@ -68,6 +68,7 @@ function createWindow() {
|
|||||||
|
|
||||||
mainWindow.loadFile('views/index.html');
|
mainWindow.loadFile('views/index.html');
|
||||||
mainWindow.setMenu(null);
|
mainWindow.setMenu(null);
|
||||||
|
mainWindow.on('closed', () => { headlessBrowser.forceKill(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
|
|||||||
@@ -176,6 +176,22 @@ class HeadlessBrowser {
|
|||||||
`;
|
`;
|
||||||
await win.webContents.executeJavaScript(script);
|
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();
|
module.exports = new HeadlessBrowser();
|
||||||
Reference in New Issue
Block a user