Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught browser console error message #1939

Closed
vsemozhetbyt opened this issue Jan 31, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@vsemozhetbyt
Copy link
Contributor

commented Jan 31, 2018

  • 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?

@ebidel ebidel changed the title Uncaught browser console error massage Uncaught browser console error message Feb 2, 2018

@aslushnikov

This comment has been minimized.

Copy link
Contributor

commented Apr 11, 2018

These violations are reported via the Log domain that we don't enable yet. We need to enable domain and introduce a new page event that forwards messages
from Log domain to the clients.

I'll be happy to review a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.