Skip to content

Commit

Permalink
feat(runner-headless): configurable launch options (#256)
Browse files Browse the repository at this point in the history
* feat(runner-headless): configurable launch options

* docs(config): document configuration additions

Document the additional launch options property option for the headless runner.
  • Loading branch information
rlodico committed Jan 25, 2021
1 parent 03b09cc commit 4a98dd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion docs/content/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,20 @@ The Best configuration file (`best.config.js`) supports the following options.

`array` The list of runners to run benchmarks.

For the headless runner, [Puppeteer launch options](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerlaunchoptions) can be provided using the `launchOptions` property in the runner config.

```js
{
runners: [
{
runner: "@best/runner-headless",
alias: "default"
alias: "default",
config: {
launchOptions: {
headless: false,
devtools: true
}
}
},
{
runner: "@best/runner-remote",
Expand Down
10 changes: 8 additions & 2 deletions packages/@best/runner-headless/src/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ const BROWSER_ARGS = [
'--enable-precise-memory-info',
];

const PUPPETEER_OPTIONS = { args: BROWSER_ARGS };
const PUPPETEER_OPTIONS: puppeteer.LaunchOptions = { args: BROWSER_ARGS };

function tempDir() {
const TEMP_DIR_PREFIX = 'runner-headless-temp';
return fs.mkdtempSync(path.join(os.tmpdir(), TEMP_DIR_PREFIX));
}

interface HeadlessRunnerConfig {
readonly launchOptions?: Readonly<puppeteer.LaunchOptions>;
}

export default class HeadlessBrowser {
pageUrl: string;
projectConfig: FrozenProjectConfig;
Expand All @@ -48,7 +52,9 @@ export default class HeadlessBrowser {
}

async initialize() {
this.browser = await puppeteer.launch(PUPPETEER_OPTIONS);
const runnerConfig: HeadlessRunnerConfig = this.projectConfig.benchmarkRunnerConfig || {};
const { launchOptions = {} } = runnerConfig;
this.browser = await puppeteer.launch({ ...PUPPETEER_OPTIONS, ...launchOptions });
this.page = await this.browser.newPage();
this.page.on('pageerror', (error: Error) => this.pageError = error);
await this.page.goto(this.pageUrl);
Expand Down

0 comments on commit 4a98dd6

Please sign in to comment.