GoogleChrome/lighthouse · error

missing WPT_KEY

Error message

missing WPT_KEY

What it means

Thrown by startWptTest() when the WPT_KEY environment variable is falsy. WebPageTest requires an API key to start tests, so the script refuses to proceed without one.

Source

Thrown at core/scripts/lantern/collect/collect.js:57

  fs.writeFileSync(`${common.collectFolder}/${filename}`, data);
  return filename;
}

/**
 * @param {string} url
 * @return {Promise<string>}
 */
async function fetchString(url) {
  const response = await fetch(url);
  if (response.ok) return response.text();
  throw new Error(`error fetching ${url}: ${response.status} ${response.statusText}`);
}

/**
 * @param {string} url
 */
async function startWptTest(url) {
  if (!WPT_KEY) throw new Error('missing WPT_KEY');

  const apiUrl = new URL('/runtest.php', WPT_URL);
  apiUrl.search = new URLSearchParams({
    k: WPT_KEY,
    f: 'json',
    url,
    location: 'gce-us-east4-linux:Chrome.3GFast',
    runs: '1',
    lighthouse: '1',
    mobile: '1',
    // Make the trace file available over /getgzip.php.
    lighthouseTrace: '1',
    lighthouseScreenshots: '1',
    // Disable some things that WPT does, such as a "repeat view" analysis.
    type: 'lighthouse',
  }).toString();
  const wptResponseJson = await fetchString(apiUrl.href);
  const wptResponse = JSON.parse(wptResponseJson);

View on GitHub (pinned to 9515cd4e58)

Solutions

  1. Obtain a WPT API key from webpagetest.org and set `export WPT_KEY=your_key` before running.
  2. If using a .env file, ensure it's loaded (e.g. via dotenv) before the script runs.
  3. In CI, add WPT_KEY as a secret environment variable.

Example fix

// before
node core/scripts/lantern/collect/collect.js
// after
export WPT_KEY=YOUR_KEY && node core/scripts/lantern/collect/collect.js
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.WPT_KEY) {
  console.error('Missing WPT_KEY. Set it via: export WPT_KEY=your_key');
  process.exit(1);
}

Prevention

When it happens

Trigger: Running the Lantern collect script without setting WPT_KEY; the variable is set in a different shell or .env file not loaded.

Common situations: Fresh environment without WPT credentials; .env file not sourced; CI secret not injected.

Related errors


AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13). Data as JSON: /api/errors/7b6990a2f2466c01. Report an issue: GitHub.