joelgriffith / navalia

A bullet-proof, fast, and reliable headless browser API
https://joelgriffith.github.io/navalia/
GNU General Public License v3.0
957 stars 33 forks source link

Undescriptive error message on error in `.evaluate` #34

Closed queckezz closed 7 years ago

queckezz commented 7 years ago

Running the following code results into an error because it's accessing a property from an undefined variable:

async function run () {
  const browser = new Chrome()
  await browser.goto('https://google.com')
  const res = await browser.evaluate(() => window.__UNKNOWN_VARIABLE__.x)
  console.log(res)
  await browser.done()
}

Error:

Error
    at Chrome.<anonymous> (D:\...\node_modules\navalia\build\Chrome.js:141:23)
    at Generator.next (<anonymous>)
    at fulfilled (D:\dev\...\node_modules\navalia\build\Chrome.js:4:58)
    at <anonymous>

Is there anyway we could forward chrome's error messages when .evaluate()ing?

joelgriffith commented 7 years ago

Thanks for the repro steps. Generally they do come through, so I'll see what the issue is with this. Thanks!

joelgriffith commented 7 years ago

I've got it now printing a better error for your case:

(node:5602) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: TypeError: Cannot read property 'x' of undefined
    at result (<anonymous>:3:59)
    at <anonymous>:3:62
    at <anonymous>:9:9

There's enough info here to even get fancy about pointing to the error in code, but that will likely be a feature sometime later.

Will have this patched soon!

joelgriffith commented 7 years ago

0.1.2 has this improvement. It's still likely that I've missed a case since the location of Error text from Chrome's inject can be in a few different places. Feel free to re-open if it's still vague in your use-case.

queckezz commented 7 years ago

Great! Thanks for the quick fix! ✨ Errors are coming through now with 0.1.2