-
-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Electron process becomes unresponsive to SIGINT #467
Comments
How about your electron app listening to SIGINT and closing the browser? |
function handle(signal) {
console.log(`Received ${signal}`);
browser.close()
}
process.on('SIGINT', handle);
process.on('SIGTERM', handle); |
@berstend Funny enough, when |
If |
Did a quick test, and can only reproduce the issue if the |
Does the problem go away if the // Remove specific evasion from enabled ones dynamically
const pluginStealth = require('puppeteer-extra-plugin-stealth')()
pluginStealth.enabledEvasions.delete('user-agent-override')
puppeteer.use(pluginStealth) |
The reason I'm thinking it might be related to async onClose() {
debug('onClose')
if (this.shouldDeleteDirectory) {
this.deleteUserDataDir()
}
} Enabling DEBUG logging ( |
@berstend Yes, disabling the user data dir plugin addresses it. |
Would be great to see some logging output, the issue might be something like this. |
Running Here's the output anyway puppeteer-extra-plugin:base:stealth Initialized. +0ms
puppeteer-extra plugin registered stealth +0ms
puppeteer-extra dependencies missing Set(15) {
'stealth/evasions/chrome.app',
'stealth/evasions/chrome.csi',
'stealth/evasions/chrome.loadTimes',
'stealth/evasions/chrome.runtime',
'stealth/evasions/iframe.contentWindow',
'stealth/evasions/media.codecs',
'stealth/evasions/navigator.hardwareConcurrency',
'stealth/evasions/navigator.languages',
'stealth/evasions/navigator.permissions',
'stealth/evasions/navigator.plugins',
'stealth/evasions/navigator.webdriver',
'stealth/evasions/sourceurl',
'stealth/evasions/user-agent-override',
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions'
} +1ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.app Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.app +2ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.csi Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.csi +2ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.loadTimes Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.loadTimes +0ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.runtime Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.runtime +2ms
puppeteer-extra-plugin:base:stealth/evasions/iframe.contentWindow Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/iframe.contentWindow +1ms
puppeteer-extra-plugin:base:stealth/evasions/media.codecs Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/media.codecs +1ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.hardwareConcurrency Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.hardwareConcurrency +0ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.languages Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.languages +1ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.permissions Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.permissions +0ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.plugins Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.plugins +2ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.webdriver Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.webdriver +1ms
puppeteer-extra-plugin:base:stealth/evasions/sourceurl Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/sourceurl +0ms
puppeteer-extra-plugin:base:stealth/evasions/user-agent-override Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/user-agent-override +1ms
puppeteer-extra dependencies missing Set(3) {
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions',
'user-preferences'
} +0ms
puppeteer-extra-plugin:base:stealth/evasions/webgl.vendor Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/webgl.vendor +0ms
puppeteer-extra-plugin:base:stealth/evasions/window.outerdimensions Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/window.outerdimensions +1ms
puppeteer-extra-plugin:base:user-preferences Initialized. +0ms
puppeteer-extra plugin registered user-preferences +0ms
puppeteer-extra dependencies missing Set(1) { 'user-data-dir' } +1ms
puppeteer-extra-plugin:base:user-data-dir Initialized. +0ms
puppeteer-extra-plugin:user-data-dir initialized {
deleteTemporary: true,
deleteExisting: false,
files: [],
folderPath: '/var/folders/dj/h_jk17gd44q3hff34kl40gtw0000gn/T',
folderPrefix: 'puppeteer_dev_profile-'
} +0ms
puppeteer-extra plugin registered user-data-dir +17ms
puppeteer-extra ignoring dependency 'stealth/evasions/webgl.vendor', which has been required already. +0ms
puppeteer-extra ignoring dependency 'stealth/evasions/window.outerdimensions', which has been required already. +0ms
puppeteer-extra orderPlugins:before [
'stealth',
'stealth/evasions/chrome.app',
'stealth/evasions/chrome.csi',
'stealth/evasions/chrome.loadTimes',
'stealth/evasions/chrome.runtime',
'stealth/evasions/iframe.contentWindow',
'stealth/evasions/media.codecs',
'stealth/evasions/navigator.hardwareConcurrency',
'stealth/evasions/navigator.languages',
'stealth/evasions/navigator.permissions',
'stealth/evasions/navigator.plugins',
'stealth/evasions/navigator.webdriver',
'stealth/evasions/sourceurl',
'stealth/evasions/user-agent-override',
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions',
'user-preferences',
'user-data-dir'
] +0ms
puppeteer-extra orderPlugins:after [
'stealth',
'stealth/evasions/chrome.app',
'stealth/evasions/chrome.csi',
'stealth/evasions/chrome.loadTimes',
'stealth/evasions/chrome.runtime',
'stealth/evasions/media.codecs',
'stealth/evasions/navigator.hardwareConcurrency',
'stealth/evasions/navigator.languages',
'stealth/evasions/navigator.permissions',
'stealth/evasions/navigator.plugins',
'stealth/evasions/navigator.webdriver',
'stealth/evasions/sourceurl',
'stealth/evasions/user-agent-override',
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions',
'stealth/evasions/iframe.contentWindow',
'user-preferences',
'user-data-dir'
] +0ms
puppeteer-extra-plugin:user-preferences _userPrefsFromPlugins { intl: { accept_languages: 'en-US,en' } } +0ms
puppeteer-extra-plugin:user-data-dir created custom dir /var/folders/dj/h_jk17gd44q3hff34kl40gtw0000gn/T/puppeteer_dev_profile-wAOVxF +3ms
puppeteer-extra-plugin:user-data-dir Wrote file /var/folders/dj/h_jk17gd44q3hff34kl40gtw0000gn/T/puppeteer_dev_profile-wAOVxF/Default/Preferences +3ms
puppeteer-extra-plugin:user-data-dir onClose +1s
puppeteer-extra-plugin:user-data-dir removeUserDataDir +0ms
puppeteer-extra-plugin:user-data-dir onClose +79ms
puppeteer-extra-plugin:user-data-dir removeUserDataDir +0ms Using the above but with > start
> electron .
puppeteer-extra-plugin:base:stealth Initialized. +0ms
puppeteer-extra plugin registered stealth +0ms
puppeteer-extra dependencies missing Set(15) {
'stealth/evasions/chrome.app',
'stealth/evasions/chrome.csi',
'stealth/evasions/chrome.loadTimes',
'stealth/evasions/chrome.runtime',
'stealth/evasions/iframe.contentWindow',
'stealth/evasions/media.codecs',
'stealth/evasions/navigator.hardwareConcurrency',
'stealth/evasions/navigator.languages',
'stealth/evasions/navigator.permissions',
'stealth/evasions/navigator.plugins',
'stealth/evasions/navigator.webdriver',
'stealth/evasions/sourceurl',
'stealth/evasions/user-agent-override',
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions'
} +0ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.app Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.app +4ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.csi Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.csi +1ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.loadTimes Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.loadTimes +0ms
puppeteer-extra-plugin:base:stealth/evasions/chrome.runtime Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/chrome.runtime +1ms
puppeteer-extra-plugin:base:stealth/evasions/iframe.contentWindow Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/iframe.contentWindow +1ms
puppeteer-extra-plugin:base:stealth/evasions/media.codecs Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/media.codecs +0ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.hardwareConcurrency Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.hardwareConcurrency +1ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.languages Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.languages +1ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.permissions Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.permissions +0ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.plugins Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.plugins +2ms
puppeteer-extra-plugin:base:stealth/evasions/navigator.webdriver Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/navigator.webdriver +0ms
puppeteer-extra-plugin:base:stealth/evasions/sourceurl Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/sourceurl +1ms
puppeteer-extra-plugin:base:stealth/evasions/user-agent-override Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/user-agent-override +0ms
puppeteer-extra dependencies missing Set(3) {
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions',
'user-preferences'
} +0ms
puppeteer-extra-plugin:base:stealth/evasions/webgl.vendor Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/webgl.vendor +1ms
puppeteer-extra-plugin:base:stealth/evasions/window.outerdimensions Initialized. +0ms
puppeteer-extra plugin registered stealth/evasions/window.outerdimensions +0ms
puppeteer-extra-plugin:base:user-preferences Initialized. +0ms
puppeteer-extra plugin registered user-preferences +1ms
puppeteer-extra dependencies missing Set(1) { 'user-data-dir' } +0ms
puppeteer-extra-plugin:base:user-data-dir Initialized. +0ms
puppeteer-extra-plugin:user-data-dir initialized {
deleteTemporary: true,
deleteExisting: false,
files: [],
folderPath: '/var/folders/dj/h_jk17gd44q3hff34kl40gtw0000gn/T',
folderPrefix: 'puppeteer_dev_profile-'
} +0ms
puppeteer-extra plugin registered user-data-dir +17ms
puppeteer-extra ignoring dependency 'stealth/evasions/webgl.vendor', which has been required already. +0ms
puppeteer-extra ignoring dependency 'stealth/evasions/window.outerdimensions', which has been required already. +0ms
puppeteer-extra orderPlugins:before [
'stealth',
'stealth/evasions/chrome.app',
'stealth/evasions/chrome.csi',
'stealth/evasions/chrome.loadTimes',
'stealth/evasions/chrome.runtime',
'stealth/evasions/iframe.contentWindow',
'stealth/evasions/media.codecs',
'stealth/evasions/navigator.hardwareConcurrency',
'stealth/evasions/navigator.languages',
'stealth/evasions/navigator.permissions',
'stealth/evasions/navigator.plugins',
'stealth/evasions/navigator.webdriver',
'stealth/evasions/sourceurl',
'stealth/evasions/user-agent-override',
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions',
'user-preferences',
'user-data-dir'
] +0ms
puppeteer-extra orderPlugins:after [
'stealth',
'stealth/evasions/chrome.app',
'stealth/evasions/chrome.csi',
'stealth/evasions/chrome.loadTimes',
'stealth/evasions/chrome.runtime',
'stealth/evasions/media.codecs',
'stealth/evasions/navigator.hardwareConcurrency',
'stealth/evasions/navigator.languages',
'stealth/evasions/navigator.permissions',
'stealth/evasions/navigator.plugins',
'stealth/evasions/navigator.webdriver',
'stealth/evasions/sourceurl',
'stealth/evasions/user-agent-override',
'stealth/evasions/webgl.vendor',
'stealth/evasions/window.outerdimensions',
'stealth/evasions/iframe.contentWindow',
'user-preferences',
'user-data-dir'
] +1ms
puppeteer-extra-plugin:user-preferences _userPrefsFromPlugins { intl: { accept_languages: 'en-US,en' } } +0ms
puppeteer-extra-plugin:user-data-dir created custom dir /var/folders/dj/h_jk17gd44q3hff34kl40gtw0000gn/T/puppeteer_dev_profile-OVg3Sf +19ms
puppeteer-extra-plugin:user-data-dir Wrote file /var/folders/dj/h_jk17gd44q3hff34kl40gtw0000gn/T/puppeteer_dev_profile-OVg3Sf/Default/Preferences +40ms
puppeteer-extra-plugin:user-data-dir onClose +1s
puppeteer-extra-plugin:user-data-dir removeUserDataDir +0ms |
I think I have the same problem (and this issue seems to be related to #421). Code Snippet const puppeteer = require('puppeteer-extra')
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
puppeteer.use(StealthPlugin({
enabledEvasions: new Set(["user-agent-override"])
}));
;(async () => {
const browser = await puppeteer.launch()
await browser.close();
console.log("browser.close()");
})()
setTimeout(() => console.log("setTimeout()"), 10000);
Without Versions System:
OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 6.96 GB / 15.38 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 16.0.0 - /usr/bin/node
npm: 7.11.2 - /usr/bin/npm
npmPackages:
puppeteer: ^9.1.0 => 9.1.0
puppeteer-extra: ^3.1.18 => 3.1.18
puppeteer-extra-plugin-stealth: ^2.7.8 => 2.7.8 |
I've run into problems like this before, where a Reproduce the problem with this script. Run it and try hitting process.on(`SIGINT`, () => console.log(`caught SIGINT`))
setInterval(() => {}, 1e3) // do work to prevent immediate exit I've fixed this a couple ways in the past.
Option 2 seems like a better fit in this case, and it works better in conjunction with other, unrelated cleanup scripts with their own process.once(`SIGINT`, () => {
console.log(`caught SIGINT`)
process.kill(process.pid, `SIGINT`) // send `SIGINT` back to self
})
setInterval(() => {}, 1e3) // do work I tried replacing the For example: if (this.onClose) {
if (opts.options.handleSIGINT !== false) {
process.once('SIGINT', () => {
this.onClose()
process.kill(process.pid, `SIGINT`)
});
}
... Note: I haven't tested this against the other test cases in this thread, but it solved my problem. Maybe others can see if it works for them, too. |
@Tyler-Murphy I have created a PR based on your example. I have added you to the commit via |
Right now, it seems like this library is preventing the `SIGINT` (ctrl-C) signal from shutting down my project. I made these changes using github's edit button, so I haven't tested/linted anything, and there could be mistakes. See this comment for an explanation: berstend/puppeteer-extra#467 (comment). Here are the comment's contents at the time of writing, in case the link stops working: I've run into problems like this before, where a `process.on` listener traps `SIGINT` every time it's sent. Reproduce the problem with this script. Run it and try hitting `ctrl-C` repeatedly. It'll be trapped every time and the process won't exit. ```node process.on(`SIGINT`, () => console.log(`caught SIGINT`)) setInterval(() => {}, 1e3) // do work to prevent immediate exit ``` I've fixed this a couple ways in the past. 1. Use `process.once`, and after cleanup work is complete, print a message saying something like "send SIGINT again to exit". 2. Re-emit the kill signal after cleanup work is complete. Option 2 seems like a better fit in this case, and it works better in conjunction with other, unrelated cleanup scripts with their own `SIGINT` listeners. Here's what it looks like: ```node process.once(`SIGINT`, () => { console.log(`caught SIGINT`) process.kill(process.pid, `SIGINT`) // send `SIGINT` back to self }) setInterval(() => {}, 1e3) // do work ``` I tried replacing [the `puppeteer-extra-plugin` `process.on` listeners in the `index` file](https://github.com/berstend/puppeteer-extra/blob/0049d6010311505f27e7f3be804bb198e2c09aa2/packages/puppeteer-extra-plugin/src/index.ts#L506-L519) with `process.once` listeners as described, and it seems to fix the problem for me. For example: ```node if (this.onClose) { if (opts.options.handleSIGINT !== false) { process.once('SIGINT', () => { this.onClose() process.kill(process.pid, `SIGINT`) }); } ... ``` **Note:** I haven't tested this against the other test cases in this thread, but it solved my problem. Maybe others can see if it works for them, too.
maybe we are on same problem but maybe other still use puppeteer lower than version 1.6.0 ? #530 |
This should be fixed through #530 |
Describe the bug
Sending a SIGINT signal to the Electron process does not kill the process.
Code Snippet
package.json
main.js
Versions
The text was updated successfully, but these errors were encountered: