Puppeteer: Unknown error code:
request.abort receives an error code absent from the supported mapping.
request.abort receives an error code absent from the supported mapping.
Error message
Unknown error code:
How this error happens
request.abort accepts Puppeteer’s abort reasons, not a numeric HTTP status or an arbitrary browser error label.
The snippets use an open Chrome/CDP page named page.
await page.setRequestInterception(
true
);
const waiting = page.waitForRequest(
() => true
);
const navigation = page.goto(
"https://example.com/"
);
navigation.catch(() => { });
const request = await waiting;
await request.abort(
"404"
);
How to fix
Use a supported abort reason such as failed. If you want an HTTP 404 response rather than a network failure, use respond.
await request.respond({
status: 404,
contentType: "text/plain",
body: "Not found",
});
await navigation;
Things to keep in mind
The correction continues from the paused request above. An HTTP error response and an aborted network request have different semantics.