Puppeteer: Stylesheet URL is undefined (styleSheetId={value})
CSS coverage has a stylesheet ID without its recorded URL.
CSS coverage has a stylesheet ID without its recorded URL.
Error message
Stylesheet URL is undefined (styleSheetId={value})
{value} is replaced by the value shown in your error message.
How this error happens
CSS coverage recorded a stylesheet ID without the corresponding URL. A stylesheet’s lifecycle and the coverage collector’s records are out of sync.
The snippets use an open Chrome/CDP page named page.
await page.coverage.startCSSCoverage();
await page.setContent(
"<style>p { color: red; }</style><p>Hello</p>"
);
const coverage = await page.coverage.stopCSSCoverage();
How to fix
Start CSS coverage before the page work you want to measure, stop it once after that work, and keep the page alive until collection finishes.
await page.coverage.startCSSCoverage();
try {
await page.setContent(
"<style>p { color: red; }</style><p>Hello</p>"
);
} finally {
const coverage = await page.coverage.stopCSSCoverage();
console.log(coverage);
}
Things to keep in mind
This valid workflow only produces the error if stylesheet events or collector bookkeeping become inconsistent. A controlled inline stylesheet helps isolate dynamic replacement or navigation from a browser/Puppeteer issue. Do not patch private stylesheet records.