Skip to content

Commit

Permalink
fix(browser-pool): change logs to better inform about missing browser…
Browse files Browse the repository at this point in the history
… dependencies
  • Loading branch information
foxt451 committed Aug 29, 2023
1 parent 0964001 commit faecfb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
17 changes: 9 additions & 8 deletions packages/browser-pool/src/playwright/playwright-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class PlaywrightPlugin extends BrowserPlugin<BrowserType, SafeParameters<
try {
if (useIncognitoPages) {
browser = await this.library.launch(launchOptions).catch((error) => {
this._notifyOfFailedLaunch();
this._notifyOfFailedLaunch(launchContext);
throw error;
});

Expand Down Expand Up @@ -112,7 +112,7 @@ export class PlaywrightPlugin extends BrowserPlugin<BrowserType, SafeParameters<
}

const browserContext = await this.library.launchPersistentContext(userDataDir, launchOptions).catch((error) => {
this._notifyOfFailedLaunch();
this._notifyOfFailedLaunch(launchContext);
throw error;
});

Expand Down Expand Up @@ -180,15 +180,16 @@ export class PlaywrightPlugin extends BrowserPlugin<BrowserType, SafeParameters<
return browser;
}

private _notifyOfFailedLaunch() {
let debugMessage = `Failed to launch browser. ${this.launchOptions?.executablePath ? 'Check whether the provided executable path is correct.' : ''} `;
private _notifyOfFailedLaunch(launchContext: LaunchContext<BrowserType>) {
let debugMessage = `Failed to launch browser.`
+ `${launchContext.launchOptions?.executablePath
? ` Check whether the provided executable path is correct: ${launchContext.launchOptions?.executablePath}.` : ''}`;
if (process.env.APIFY_IS_AT_HOME) {
debugMessage += 'Make sure you used the correct Actor template for Playwright: '
+ 'your Dockerfile has to extend `apify/actor-node-playwright-*` (with a correct browser name). Or install ';
debugMessage += ' Make sure your Dockerfile extends apify/actor-node-playwright-*` (with a correct browser name). Or install';
} else {
debugMessage += 'Try installing ';
debugMessage += ' Try installing';
}
debugMessage += 'the required dependencies by running `npx playwright install --with-deps` (https://playwright.dev/docs/browsers).'
debugMessage += ' the required dependencies by running `npx playwright install --with-deps` (https://playwright.dev/docs/browsers).'
+ ' The original error will be displayed below.';
log.error(debugMessage);
}
Expand Down
14 changes: 10 additions & 4 deletions packages/browser-pool/src/puppeteer/puppeteer-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ export class PuppeteerPlugin extends BrowserPlugin<
}
} catch (error) {
await close();
let debugMessage = `Failed to launch browser.`
+ `${launchContext.launchOptions?.executablePath
? ` Check whether the provided executable path is correct: ${launchContext.launchOptions?.executablePath}.` : ''}`;
if (process.env.APIFY_IS_AT_HOME) {
log.error('Failed to launch browser. Make sure you used the correct Actor template for Puppeteer:'
+ ' your Dockerfile has to extend `apify/actor-node-puppeteer-chrome`.'
+ ' Or install the missing dependencies manually, referring to the Puppeteer\'s troubleshooting guide.'
+ ' The original error will be displayed below.');
debugMessage += ' Make sure your Dockerfile extends `apify/actor-node-puppeteer-chrome. Or install';
} else {
debugMessage += ' Try installing';
}
debugMessage += ' browser, if it\'s missing, by running `npx @puppeteer/browsers install chromium --path [path]`'
+ ' and pointing `executablePath` to the downloaded executable (https://playwright.dev/docs/browsers).'
+ ' The original error will be displayed below.';
log.error(debugMessage);
throw error;
}
}
Expand Down

0 comments on commit faecfb5

Please sign in to comment.