diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 190667bbffd6b..5742b2d73f204 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -184,3 +184,38 @@ jobs: max_attempts: 3 timeout_minutes: 10 command: npm run funit + chrome-headless: + runs-on: ${{ matrix.os }} + strategy: + matrix: + # https://github.com/actions/virtual-environments#available-environments + os: [ubuntu-latest, macos-latest, windows-latest] + node: [16] + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Set up Node.js + uses: actions/setup-node@v3.1.1 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: | + npm install + ls .local-chromium + + - name: Build + run: | + npm run build + + - name: Run unit tests + uses: nick-invision/retry@v2 + env: + CHROMIUM: true + with: + max_attempts: 1 + command: npm run chrome-headless-unit + timeout_minutes: 60 diff --git a/package.json b/package.json index 23f42fe0fc5d6..fe96de5458d97 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "test-browser": "wtr", "test-browser-watch": "wtr --watch", "unit": "npm run tsc-cjs && mocha --config mocha-config/puppeteer-unit-tests.js", + "chrome-headless-unit": "cross-env HEADLESS=chrome npm run unit", "unit-debug": "npm run tsc-cjs && mocha --inspect-brk --config mocha-config/puppeteer-unit-tests.js", "unit-with-coverage": "cross-env COVERAGE=1 npm run unit", "assert-unit-coverage": "cross-env COVERAGE=1 mocha --config mocha-config/coverage-tests.js", diff --git a/src/node/LaunchOptions.ts b/src/node/LaunchOptions.ts index 81173b1970625..da9fd650b9246 100644 --- a/src/node/LaunchOptions.ts +++ b/src/node/LaunchOptions.ts @@ -27,7 +27,7 @@ export interface BrowserLaunchArgumentOptions { * Whether to run the browser in headless mode. * @defaultValue true */ - headless?: boolean; + headless?: boolean | 'chrome'; /** * Path to a user data directory. * {@link https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/user_data_dir.md | see the Chromium docs} diff --git a/src/node/Launcher.ts b/src/node/Launcher.ts index 4abae70c734b6..17301d0e07b7e 100644 --- a/src/node/Launcher.ts +++ b/src/node/Launcher.ts @@ -241,7 +241,11 @@ class ChromeLauncher implements ProductLauncher { chromeArguments.push(`--user-data-dir=${path.resolve(userDataDir)}`); if (devtools) chromeArguments.push('--auto-open-devtools-for-tabs'); if (headless) { - chromeArguments.push('--headless', '--hide-scrollbars', '--mute-audio'); + chromeArguments.push( + headless === 'chrome' ? '--headless=chrome' : '--headless', + '--hide-scrollbars', + '--mute-audio' + ); } if (args.every((arg) => arg.startsWith('-'))) chromeArguments.push('about:blank'); diff --git a/test/mocha-utils.ts b/test/mocha-utils.ts index 97909df98f092..abf80397dc279 100644 --- a/test/mocha-utils.ts +++ b/test/mocha-utils.ts @@ -64,8 +64,8 @@ const product = const alternativeInstall = process.env.PUPPETEER_ALT_INSTALL || false; -const isHeadless = - (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true'; +const headless = (process.env.HEADLESS || 'true').trim().toLowerCase(); +const isHeadless = headless === 'true' || headless === 'chrome'; const isFirefox = product === 'firefox'; const isChrome = product === 'Chromium'; @@ -82,7 +82,7 @@ const defaultBrowserOptions = Object.assign( { handleSIGINT: true, executablePath: process.env.BINARY, - headless: isHeadless, + headless: headless === 'chrome' ? ('chrome' as const) : isHeadless, dumpio: !!process.env.DUMPIO, }, extraLaunchOptions