Oxygen Auth Bypass Token: Run Hydrogen E2E in CI

An Oxygen auth bypass token lets automated tests load a private Hydrogen deployment without a Shopify staff login. Run shopify hydrogen deploy --auth-bypass-token in CI, read authBypassToken and url from the h2_deploy_log.json file it writes, and send the token as an oxygen-auth-bypass-token request header. It lasts two hours by default, 12 at most.

That is the whole mechanism, and Shopify’s end-to-end testing guide covers it in one page. The details that page skips are where test suites go wrong: where the header ends up, what happens when the run outlives the token, and why a redirect to your custom domain turns every test into a login screen.

Why does Playwright get a login page from Oxygen?

Oxygen deployments are private by default. The deployment management docs say only logged-in staff can view one until you create a shareable link, and environments follow the same rule unless you switch their URL privacy to public. A headless browser in CI is not logged in to your store, so it gets bounced to a login flow and your first assertion fails on a page you never wrote.

There are three ways round it. You can make the environment public, which spends one of the plan’s limited public environment slots and exposes unreleased work to anyone with the URL. You can create a shareable link, available from the Basic plan up, which carries a token that bypasses login until someone clicks Reset link. Or you can mint a bypass token per deployment.

For CI the bypass token is the right one. It is scoped to a single deployment, it expires on its own, and nobody has to remember to revoke it. A shareable link pasted into a CI secret stays valid until someone remembers to reset it.

One side effect to know about before you write performance assertions: the environments page notes that private environment URLs load more slowly, because Oxygen verifies authentication on each request. Timings taken against a private preview will not match production.

How do you generate an Oxygen auth bypass token in CI?

The flags are on the hydrogen deploy command reference. --auth-bypass-token generates the token, --auth-bypass-token-duration sets its life in whole hours from 1 to 12, and --json-output, which defaults to true in CI, writes the deployment details to h2_deploy_log.json. The deployment token itself comes from --token or the SHOPIFY_HYDROGEN_DEPLOYMENT_TOKEN environment variable. In CI the command rejects --env; pick a target with --env-branch if the branch alone is not enough.

Copy the GitHub workflow from Shopify’s guide with care. As of November 2026 its deploy step puts the command under run: as a YAML list item, and GitHub Actions expects run to be a string. The Hydrogen demo store workflow uses a block string and is the better starting point. Here is our version of the deploy step and the test step, in one job:

name: Deploy to Oxygen and test
on: [push]

permissions:
  contents: read
  deployments: write

jobs:
  deploy-and-test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: lts/*
          cache: npm
      - run: npm ci

      - name: Deploy to Oxygen
        env:
          SHOPIFY_HYDROGEN_DEPLOYMENT_TOKEN: ${{ secrets.OXYGEN_DEPLOYMENT_TOKEN }}
        run: |
          npx shopify hydrogen deploy --auth-bypass-token --auth-bypass-token-duration=1
          token=$(jq -r '.authBypassToken' h2_deploy_log.json)
          echo "::add-mask::$token"
          echo "OXYGEN_BYPASS_TOKEN=$token" >> "$GITHUB_ENV"
          echo "DEPLOYMENT_URL=$(jq -r '.url' h2_deploy_log.json)" >> "$GITHUB_ENV"
          rm h2_deploy_log.json

      - run: npx playwright install --with-deps chromium
      - run: npx playwright test

Four choices in there are deliberate.

The ::add-mask:: line comes from GitHub’s workflow commands: once a value is masked, the runner redacts it from the log. The bypass token is a credential to an unreleased storefront. Masking covers the log only: a Playwright trace records request headers, so a trace uploaded as an artifact can still hold the token, which is one more reason to keep its life short.

Deleting h2_deploy_log.json stops a later “upload test results” step from sweeping the token into a build artifact.

The variable is called OXYGEN_BYPASS_TOKEN, not the AUTH_BYPASS_TOKEN the demo store uses. The command reference lists AUTH_BYPASS_TOKEN as the environment variable behind the --auth-bypass-token flag itself, and we would rather the token value and the CLI flag never share a name.

Keep deploy and tests in the same job. GitHub’s docs also say a masked value cannot be set as a step output, so handing the token to a separate sharded test job means passing an unmasked secret around. If you need sharding, as in our Playwright sharding set-up, either run more workers inside the deploy job or accept one deployment, and one token, per shard job.

If you are on the Hydrogen 2026.10 library rather than the classic 2026.4.x line, the deploy command also needs --assets-dir and --worker-dir for your build output, and the end-to-end guide currently sits under Shopify’s legacy docs. The flags themselves are on the current CLI reference. Our Hydrogen 2026.10 migration notes cover the rest of that move.

Should the header go in extraHTTPHeaders?

The demo store’s playwright.config.ts sets the token through use.extraHTTPHeaders. That works, and it sends the token to every origin the page talks to. Playwright’s test options docs define extraHTTPHeaders as headers “sent with every request”, and that includes every third-party origin your storefront page calls: image CDNs, analytics, review widgets, tag managers. A local check with two Node servers on Playwright 1.65.1 showed exactly that, with the token arriving on a cross-origin image request.

Scope it to the deployment origin with a route instead. This fixture overrides the built-in context so every test that imports it gets the header on Oxygen requests and nowhere else:

// tests/fixtures.ts
import { test as base, expect } from '@playwright/test';

const token = process.env.OXYGEN_BYPASS_TOKEN;
const deploymentUrl = process.env.DEPLOYMENT_URL;

export const test = base.extend({
  context: async ({ context }, use) => {
    if (token && deploymentUrl) {
      const origin = new URL(deploymentUrl).origin;
      await context.route(
        (url) => url.origin === origin,
        (route) =>
          route.continue({
            headers: {
              ...route.request().headers(),
              'oxygen-auth-bypass-token': token,
            },
          }),
      );
    }
    await use(context);
  },
});

export { expect };

Routing has costs, and the BrowserContext docs name them: enabling routing disables the HTTP cache, and requests a service worker intercepts skip your route, so set serviceWorkers: 'block' in the config. Neither matters for functional tests. Both matter if you were hoping to measure caching.

The Route docs add a limit on the scoping: headers set in route.continue() also apply to any redirects the request starts. If the deployment redirects off-origin, the token goes with it. The short token lifetime is the backstop there, which is one more reason not to max it out at 12 hours.

The config then points baseURL at the deployment when one exists, and only boots a local server when it does not. The demo store’s config keeps its webServer block in both cases, so it starts npm run preview even when testing a remote deployment.

// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';

const deploymentUrl = process.env.DEPLOYMENT_URL;

export default defineConfig({
  testDir: './tests',
  retries: process.env.CI ? 2 : 0,
  use: {
    baseURL: deploymentUrl ?? 'http://localhost:3000',
    serviceWorkers: 'block',
    trace: 'on-first-retry',
  },
  projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
  webServer: deploymentUrl
    ? undefined
    : { command: 'npm run preview', url: 'http://localhost:3000' },
});

Why does the bypass token stop working?

Three things, in the order we would check them.

A custom domain. Shopify’s guide is explicit that bypass tokens work only on the Oxygen deployment URL from h2_deploy_log.json, the *.myshopify.dev host. They are not supported on custom domains, and a redirect to one can stop the header reaching Oxygen at all. Use the logged url, never your staging domain.

Expiry. A long suite with retries on a slow runner can outlast the two-hour default. Set the duration just above the job’s timeout-minutes, so the token cannot outlive the job by much; with the 30-minute timeout above, 1 hour covers it.

A login redirect that nobody asserts on. When the token is wrong or expired, tests fail on missing selectors and the report reads like a storefront bug. Add one smoke test that checks the page stayed on the deployment origin, so a bad token fails with a clear message:

// tests/smoke.spec.ts
import { test, expect } from './fixtures';

test('serves the storefront, not the Oxygen login', async ({ page, baseURL }) => {
  const response = await page.goto('/');
  expect(response?.status()).toBe(200);
  expect(new URL(page.url()).origin).toBe(new URL(baseURL!).origin);
});

What we would do

On a Hydrogen project with a browser test suite, we would deploy every push to a private environment and mint a bypass token sized to the job timeout. Mask it, delete the log file, and run Playwright against the deployment URL with the header scoped by a route. Shareable links are for people reviewing a preview, not for CI.

Skip all of this when the suite never touches a deployed worker. Then npm run preview on the runner is enough, and our Oxygen environment variables guide is the more useful read for getting deploy config right.

We build Hydrogen storefronts on Oxygen and set up the pipelines that test them. If your previews deploy but no tests run against them, that is the kind of job our Shopify development work covers.

Need this built properly?

Get in touch

Hack the planet!