What is the correct type for the pageerror event in Puppeteer?

Puppeteer

Summary

The pageerror event may emit not only Error objects but also values of unknown type. Treat the payload as unknown and log or stringify it instead of assuming it is an Error.

How to handle

Use a guard to log the value you receive, and extract a message if possible.

page.on('pageerror', (err) => {
  // err can be an Error or any other value
  if (err instanceof Error) {
    console.error('Page error:', err.message);
  } else {
    console.error('Page error:', String(err));
  }
});

Rationale

Puppeteer recently updated its pageerror event types to include unknown values in addition to Error objects. Handling both ensures you capture the error details without crashing.