Skip to content

Commit

Permalink
fix: Added timeout for browserWS connection
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 21, 2020
1 parent 35a5898 commit 1b28832
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,28 @@ export async function initBrowser(

let browser = null;
if (options.browserWS && options.browserWS != '') {
await puppeteer
.connect({
browserWSEndpoint: options.browserWS,
})
.then((e) => {
browser = e;
})
.catch(() => {
const checkConnection = new Promise(async (resolve) => {
const timeout = setTimeout(() => {
browser = 'connect';
});
resolve();
}, 10000);

puppeteer
.connect({
browserWSEndpoint: options.browserWS,
})
.then((e) => {
browser = e;
})
.catch(() => {
browser = 'connect';
})
.finally(() => {
clearTimeout(timeout);
resolve();
});
});
await checkConnection;
} else {
await puppeteer
.launch({
Expand Down

0 comments on commit 1b28832

Please sign in to comment.