sickn33/agentic-awesome-skills · warning
Failed to parse PW_EXTRA_HEADERS as JSON:
Error message
Failed to parse PW_EXTRA_HEADERS as JSON:
What it means
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.
Source
Thrown at skills/playwright-skill/lib/helpers.js:31
*/
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
- 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"}'
Example fix
# before (not valid JSON — parse error)
export PW_EXTRA_HEADERS="{Authorization: 'Bearer x'}"
# after
export PW_EXTRA_HEADERS='{"Authorization":"Bearer x"}' Defensive patterns
Strategy: try-catch
Validate before calling
node -e "JSON.parse(process.env.PW_EXTRA_HEADERS ?? '{}')" // run before starting the suite Try / catch
try {
headers = JSON.parse(process.env.PW_EXTRA_HEADERS ?? '{}');
} catch (e) {
throw new Error(`Invalid PW_EXTRA_HEADERS JSON: ${e.message}`);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26).
Data as JSON: /api/errors/09b0478b4488c792.
Report an issue: GitHub.