sickn33/agentic-awesome-skills · warning

PW_EXTRA_HEADERS must be a JSON object, ignoring...

Error message

PW_EXTRA_HEADERS must be a JSON object, ignoring...

What it means

getExtraHeadersFromEnv read PW_EXTRA_HEADERS and JSON.parse succeeded, but the parsed value was not a plain object — it was an array, a string, a number, or null. The helper warns and returns null, so Playwright requests proceed without the intended extra headers. It is a configuration warning, not a crash: the run continues, silently missing headers such as Authorization.

Source

Thrown at skills/playwright-skill/lib/helpers.js:29

 * Single header format takes precedence if both are set.
 * @returns {Object|null} Headers object or null if none configured
 */
function getExtraHeadersFromEnv() {
  const headerName = process.env.PW_HEADER_NAME;
  const headerValue = process.env.PW_HEADER_VALUE;

  if (headerName && headerValue) {
    return { [headerName]: headerValue };
  }

  const headersJson = process.env.PW_EXTRA_HEADERS;
  if (headersJson) {
    try {
      const parsed = JSON.parse(headersJson);
      if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
        return parsed;
      }
      console.warn('PW_EXTRA_HEADERS must be a JSON object, ignoring...');
    } catch (e) {
      console.warn('Failed to parse PW_EXTRA_HEADERS as JSON:', e.message);
    }
  }

  return null;
}

/**
 * Launch browser with standard configuration
 * @param {string} browserType - 'chromium', 'firefox', or 'webkit'
 * @param {Object} options - Additional launch options
 */
async function launchBrowser(browserType = 'chromium', options = {}) {
  const defaultOptions = {
    headless: process.env.HEADLESS !== 'false',
    slowMo: process.env.SLOW_MO ? parseInt(process.env.SLOW_MO) : 0,
    args: ['--no-sandbox', '--disable-setuid-sandbox']

View on GitHub (pinned to 58d857988f)

Solutions

  1. Set the variable to a flat JSON object of header names to string values
  2. Check quoting in your shell or YAML so the value arrives as one JSON object string

Example fix

# before
export PW_EXTRA_HEADERS='["Authorization: Bearer x"]'

# after
export PW_EXTRA_HEADERS='{"Authorization":"Bearer x","X-Custom":"value"}'
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = process.env.PW_EXTRA_HEADERS;
if (raw) {
  const v = JSON.parse(raw);
  if (typeof v !== 'object' || v === null || Array.isArray(v)) throw new Error('PW_EXTRA_HEADERS must be a JSON object');
}

Type guard

function isHeaderObject(v: unknown): v is Record<string, string> {
  return typeof v === 'object' && v !== null && !Array.isArray(v) &&
    Object.values(v).every(x => typeof x === 'string');
}

Prevention

When it happens

Trigger: Setting PW_EXTRA_HEADERS to a JSON array like '["Authorization: Bearer x"]', a bare quoted string, a number, or 'null' — all valid JSON, none an object.

Common situations: Copying a curl-style header list into the variable; YAML or docker-compose interpolation leaving the value a string; CI templates injecting 'null' for an unset secret; misunderstanding that the variable expects a name-to-value object.

Related errors


AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26). Data as JSON: /api/errors/43f56ba1f3c26dd3. Report an issue: GitHub.