Skip to content

Uncaught browser console error message #1939

@vsemozhetbyt

Description

@vsemozhetbyt
  • Puppeteer version: 1.0.0-post, chromium_revision 526987
  • Platform / OS version: Windows 7 x64
  • Node.js version: 9.4.0

What steps will reproduce the problem?

'use strict';

const puppeteer = require('puppeteer');

(async function main() {
  try {
    const browser = await puppeteer.launch({ headless: false });
    const page = await browser.newPage();

    page.on('console', (msg) => { console.log(msg.text()); });
    page.on('pageerror', (exceptionMessage) => { console.log(exceptionMessage); });

    const result = await page.evaluate(async () => {
      try {
        const status = await new Promise((resolve, reject) => {
          const xhr = new XMLHttpRequest();
          xhr.onreadystatechange = () => {
            if (xhr.readyState === 4) {
              if (xhr.status === 200) resolve(`good status: ${xhr.status}`);
              else reject(`bad status: ${xhr.status}`);
            }
          };
          xhr.onerror = () => { reject('xhr error'); };
          xhr.open('GET', 'https://example.org/');
          xhr.send();
        });
        return status;
      } catch (err) {
        return err;
      }
    });
    console.log(result);
  } catch (err) {
    console.error(err);
  }
})();

What is the expected result?

CORS error message is transferred to puppeteer

What happens instead?

Only bad status: 0 in the Node.js console, while this error message in the browser console:

err

Is there a way to catch this error message, while page.on('console') and page.on('pageerror') seem to not work here?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions