{"record":{"id":"09b0478b4488c792","repo":"sickn33/agentic-awesome-skills","slug":"failed-to-parse-pw-extra-headers-as-json","errorCode":null,"errorMessage":"Failed to parse PW_EXTRA_HEADERS as JSON:","messagePattern":"Failed to parse PW_EXTRA_HEADERS as JSON:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"skills/playwright-skill/lib/helpers.js","lineNumber":31,"sourceCode":" */\nfunction getExtraHeadersFromEnv() {\n  const headerName = process.env.PW_HEADER_NAME;\n  const headerValue = process.env.PW_HEADER_VALUE;\n\n  if (headerName && headerValue) {\n    return { [headerName]: headerValue };\n  }\n\n  const headersJson = process.env.PW_EXTRA_HEADERS;\n  if (headersJson) {\n    try {\n      const parsed = JSON.parse(headersJson);\n      if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {\n        return parsed;\n      }\n      console.warn('PW_EXTRA_HEADERS must be a JSON object, ignoring...');\n    } catch (e) {\n      console.warn('Failed to parse PW_EXTRA_HEADERS as JSON:', e.message);\n    }\n  }\n\n  return null;\n}\n\n/**\n * Launch browser with standard configuration\n * @param {string} browserType - 'chromium', 'firefox', or 'webkit'\n * @param {Object} options - Additional launch options\n */\nasync function launchBrowser(browserType = 'chromium', options = {}) {\n  const defaultOptions = {\n    headless: process.env.HEADLESS !== 'false',\n    slowMo: process.env.SLOW_MO ? parseInt(process.env.SLOW_MO) : 0,\n    args: ['--no-sandbox', '--disable-setuid-sandbox']\n  };\n  ","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/playwright-skill/lib/helpers.js#L13-L49","documentation":"JSON.parse threw while reading PW_EXTRA_HEADERS, so the variable's value is not valid JSON at all — unquoted keys, single quotes, smart quotes, an unterminated string, or unresolved template placeholders. The helper logs the parser's message and returns null; the effect is that requests run without the extra headers, which usually surfaces later as unexpected 401/403 responses from the target site.","triggerScenarios":"PW_EXTRA_HEADERS set to {Authorization: \"Bearer x\"} (unquoted key), {\"a\": 'b'} (single quotes), a multi-line YAML block folded wrongly, or a value still containing ${SECRET} placeholders.","commonSituations":"Hand-writing JSON in a shell export without escaping quotes; docker-compose/Kubernetes env values that drop inner quotes; CI secret substitution leaving placeholder text; smart quotes pasted from a chat window or rich text editor.","solutions":["Validate before the run: node -e \"JSON.parse(process.env.PW_EXTRA_HEADERS)\" and fix whatever it reports","In YAML use single quotes or a block scalar around the whole JSON so inner double quotes survive: PW_EXTRA_HEADERS: '{\"Authorization\":\"Bearer x\"}'"],"exampleFix":"# before (not valid JSON — parse error)\nexport PW_EXTRA_HEADERS=\"{Authorization: 'Bearer x'}\"\n\n# after\nexport PW_EXTRA_HEADERS='{\"Authorization\":\"Bearer x\"}'","handlingStrategy":"try-catch","validationCode":"node -e \"JSON.parse(process.env.PW_EXTRA_HEADERS ?? '{}')\" // run before starting the suite","typeGuard":null,"tryCatchPattern":"try {\n  headers = JSON.parse(process.env.PW_EXTRA_HEADERS ?? '{}');\n} catch (e) {\n  throw new Error(`Invalid PW_EXTRA_HEADERS JSON: ${e.message}`);\n}","preventionTips":["Wrap the whole JSON value in single quotes in shell/YAML to protect inner double quotes","Validate all JSON env vars in a startup step so bad config fails the deploy, not the request"],"tags":["playwright","environment-variable","json-parse","configuration","headers"],"backgroundTag":"invalid-env-var-json-config","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}