Skip to content

Commit

Permalink
🐛 Ensure discoverer cleanup happens even when the page crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Aug 4, 2020
1 parent 472460e commit e9c57d1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/core/src/discoverer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,17 @@ export default class PercyDiscoverer {
meta
}));

// navigate to the root URL and wait for the network to idle
await page.goto(rootUrl);
await idle(() => processing, this.networkIdleTimeout);

// cleanup
page.removeAllListeners('request');
page.removeAllListeners('requestfailed');
page.removeAllListeners('requestfinished');
await page.close();
try {
// navigate to the root URL and wait for the network to idle
await page.goto(rootUrl);
await idle(() => processing, this.networkIdleTimeout);
} finally {
// cleanup
page.removeAllListeners('request');
page.removeAllListeners('requestfailed');
page.removeAllListeners('requestfinished');
await page.close();
}
});
}

Expand Down

0 comments on commit e9c57d1

Please sign in to comment.