(Created on )

Puppeteer: Script to evaluate on new document with id {value} not found

A preload-script removal ID is not registered on this page.


A preload-script removal ID is not registered on this page.

Error message

Script to evaluate on new document with id {value} not found

{value} is replaced by the value shown in your error message.

How this error happens

A preload script identifier belongs to the page that registered it. Removing the same identifier twice no longer finds a registered script.

The snippets use an open Chrome/CDP page named page.

const script = await page.evaluateOnNewDocument(() => {
    window.exampleReady = true;
});

await page.removeScriptToEvaluateOnNewDocument(
    script.identifier
);

await page.removeScriptToEvaluateOnNewDocument(
    script.identifier
);

How to fix

Keep the identifier returned by registration and remove it exactly once from the same page.

const script = await page.evaluateOnNewDocument(() => {
    window.exampleReady = true;
});

await page.removeScriptToEvaluateOnNewDocument(
    script.identifier
);

Things to keep in mind

Removing a preload prevents it from running in future documents. It does not undo changes it already made in the current document.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →