Closed matheushsouto closed 3 years ago
Experiencing same issue. Is there any way arond this?
I have same issue here. There is another way to restart the client without stop and run the server?
Observation
client.destroy()
works fine if client is connected/authenticated.
UPDATE It kills the browser if you have authenticated or not, but still error comes from puppeteer code which I think can be neglected.
try replace method .initialize()
to .initialize.catch(ex => {})
on client.initialize();
or try { await client.initialize() } catch {}
to handle this promise rejection (this also will resolve the terminated of Node.js in future features because promise rejections)
Thank you a4smanjorg5
it shows me error like this
/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:189
throw new Error(${PROCESS_ERROR_EXPLANATION}\nError cause: ${error.stack}
);
^
Error: Puppeteer was unable to kill the process which ran the browser binary.
This means that, on future Puppeteer launches, Puppeteer might not be able to launch the browser.
Please check your open processes and ensure that the browser processes that Puppeteer launched have been killed.
If you think this is a bug, please report it on the Puppeteer issue tracker.
Error cause: Error: kill EPERM
at process.kill (node:internal/process/per_thread:220:13)
at BrowserRunner.kill (/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:185:29)
at BrowserRunner.close (/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:158:18)
at Browser.close (/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:394:35)
at Client.destroy (/Users/venkat/project/node_modules/whatsapp-web.js/src/Client.js:478:31)
at /Users/venkat/project/node_modules/whatsapp-web.js/src/Client.js:469:28
at runMicrotasks (
try catch not working.this is my code
`client.on('disconnected',async(reason)=>{ io.emit('message',{id:id,text:"Mobile Logged out !"}); io.emit('disconnected','disconnected'); fs.unlinkSync(SESSION_FILE_PATH,function(err){ if(err) return console.log(err); console.log('session file destroyed'); });
try {
await client.destroy();
} catch (error) {
console.log("catched");
}
client.initialize();
});
` but again it show me the error
/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:189 throw new Error(
${PROCESS_ERROR_EXPLANATION}\nError cause: ${error.stack}`);
^
Error: Puppeteer was unable to kill the process which ran the browser binary.
This means that, on future Puppeteer launches, Puppeteer might not be able to launch the browser.
Please check your open processes and ensure that the browser processes that Puppeteer launched have been killed.
If you think this is a bug, please report it on the Puppeteer issue tracker.
Error cause: Error: kill EPERM
at process.kill (node:internal/process/per_thread:220:13)
at BrowserRunner.kill (/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:185:29)
at BrowserRunner.close (/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:158:18)
at Browser.close (/Users/venkat/project/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:394:35)
at Client.destroy (/Users/venkat/project/node_modules/whatsapp-web.js/src/Client.js:478:31)
at /Users/venkat/project/node_modules/whatsapp-web.js/src/Client.js:469:28
at runMicrotasks (
same for me try { await client.destroy(); catch (error) { console.log(error); }
...
[nodemon] app crashed - waiting for file changes before starting... `
same for me as well, the above solution proposed doesn't work as well
I have same issue here. There is another way to restart the client without stop and run the server?
Hi I don't know if can help anyone currently but I leave my solution here. in effect when the server is not restarted and you make a new call to the client it is not instantiated again. the solution to implement is to be able to find this instance and destroy it before making a new instantiation to do this you must:
Create a Map that will store your instance with the id of the connected client
const sessions = new Map<string, Client>();
Then, before each instantiation of the client, you must check if there is an instance present. If there is, you destroy it.
const tempClient = sessions.get(userId); if(tempClient){ try { await tempClient.destroy(); sessions.delete(userId); }catch (e) { console.log("Error Temp") } } const client = new Client({ authStrategy: new LocalAuth({ clientId: userId, }), }) sessions.set(userId, client);
every time you make a server call, your old instance will be destroyed and you'll have no more problems. I hope this helps someone and find me on YouTube @OnProgramme ;).
(node:39965) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed. at Promise (/home/shooting4/shooting/shchat-node/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63) at new Promise ()
at CDPSession.send (/home/shooting4/shooting/shchat-node/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16)
at ExecutionContext._evaluateInternal (/home/shooting4/shooting/shchat-node/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:200:50)
at ExecutionContext.evaluateHandle (/home/shooting4/shooting/shchat-node/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:151:21)
at WaitTask.rerun (/home/shooting4/shooting/shchat-node/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:528:37)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:39965) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:39965) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Environment (please complete the following information):
WhatsApp
await client.getWWebVersion()
]:Library
node -v
):npm -v
):Additional context
Add any other context about the problem here.