Skip to content

Commit 4b6cd7f

Browse files
committed
Improved logging around browser initialization and retries
1 parent 81038e2 commit 4b6cd7f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/browser.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function create(puppeteerArgs) {
7878

7979
// Create a browser
8080
if (!browser) {
81+
const maxTries = 25;
8182
let tryCount = 0;
8283

8384
const open = async () => {
@@ -88,18 +89,29 @@ export async function create(puppeteerArgs) {
8889
);
8990
browser = await puppeteer.launch(launchOptions);
9091
} catch (error) {
92+
// This isn't a full error yet as puppeteer sometimes takes time to
93+
// initialize properly.
9194
logWithStack(
92-
1,
95+
2,
9396
error,
94-
'[browser] Failed to launch a browser instance.'
97+
`[browser] Failed to launch a browser instance - retrying (attempt ${tryCount}/${maxTries}).`
9598
);
9699

97100
// Retry to launch browser until reaching max attempts
98101
if (tryCount < 25) {
99-
log(3, `[browser] Retry to open a browser (${tryCount} out of 25).`);
102+
log(
103+
3,
104+
`[browser] Retry to open a browser (attempt ${tryCount}/${maxTries}).`
105+
);
100106
await new Promise((response) => setTimeout(response, 4000));
101107
await open();
102108
} else {
109+
//... now it's an error
110+
logWithStack(
111+
1,
112+
error,
113+
'[browser] Failed to load browser after maximum retries reached.'
114+
);
103115
throw error;
104116
}
105117
}

0 commit comments

Comments
 (0)