Skip to content

Commit

Permalink
fix: Fixed close method (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 21, 2021
1 parent ae2fbfb commit ef42485
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/api/whatsapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,21 @@ export class Whatsapp extends BusinessLayer {
* @internal
*/
public async close() {
const closing = async (waPage: {
browser: () => any;
isClosed: () => any;
close: () => any;
}) => {
if (waPage) {
const browser = await waPage.browser();
const pid = browser.process() ? browser?.process().pid : null;
if (!waPage.isClosed()) await waPage.close();
if (browser) await browser.close();
if (pid) treekill(pid, 'SIGKILL');
}
};
const browser = this.page.browser();

if (!this.page.isClosed()) {
await this.page.close().catch(() => null);
}

await browser.close().catch(() => null);

try {
await closing(this.page);
const process = browser.process();
if (process) {
treekill(process.pid, 'SIGKILL');
}
} catch (error) {}

return true;
}

Expand Down

0 comments on commit ef42485

Please sign in to comment.