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

`navalia.run` errors with a 404 #72

Open michaelwills opened 6 years ago

michaelwills commented 6 years ago

First, awesome project. I have seen notes about this project is or will be deprecated. I do hope rumors of its demise will be proven false. :)

The Chrome instance is easy enough to use however the navalia usage seems to have a problem. I haven't dug into code yet though.

This example fails:

process.env.DEBUG = "navalia";

import { Navalia } from "navalia";

const navalia: Navalia = new Navalia();

(async () => {
  await navalia.run(async chrome => chrome.goto("http://joelgriffith.net"));
})();

Output:

Wed, 14 Feb 2018 22:01:20 GMT navalia starting, using up to 1 instances
Wed, 14 Feb 2018 22:01:20 GMT navalia instances are available and starting
(node:22949) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: unexpected server response (404)
(node:22949) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
joelgriffith commented 6 years ago

Alrighty, this should be fixed in 1.3.0 which I just published 🎉

michaelwills commented 6 years ago

It's certainly an improvement! No more 404. The updated test code and error is below:

process.env.DEBUG = "navalia";

import { Navalia } from "navalia";

const navalia: Navalia = new Navalia();

(async () => {
  await navalia.run(
    async chrome =>
      await chrome.goto("http://example.com", {
        timeout: 10000,
        coverage: false,
        onload: true
      })
  );
})();

States there is a timeout now which

2018-02-15T17:35:16.143Z navalia starting, using up to 1 instances
2018-02-15T17:35:16.147Z navalia instances are available and starting
2018-02-15T17:35:18.127Z navalia instance 63154 is starting work
(node:50398) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Goto failed to load in the timeout specified
(node:50398) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
michaelwills commented 6 years ago

@joelgriffith running the tests does have a failure:

Test Suites: 1 failed, 2 passed, 3 total
Tests:       1 failed, 39 passed, 40 total
Snapshots:   8 passed, 8 total

Specifically:

 FAIL  integration/api.test.ts (74.361s)
  ● Chrome › #evaluate › should allow variables to be passed in

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

I'll see if I can dig in a bit later. Thanks much!

michaelwills commented 6 years ago

[edit] Quick test with navalia graphql works adding the following to Chrome.ts

  Promise.all([
    cdp.Page.enable(),
    cdp.Network.enable()
  ])
    .then(() => {
      return cdp.Page.navigate({url})
    })
    .catch(err => {
      reject(`Failed: ${err} ${url} ${typeof url}`)
    })

query:

{
  goto(url: "http://example.com") {
    url
  }
}

result:
{
  "data": {
    "goto": {
      "url": "http://example.com/"
    }
  },
  "extensions": {
    "time": 2377
  }
}

Test Suites: 3 passed, 3 total
Tests:       40 passed, 40 total
Snapshots:   8 passed, 8 total
Time:        59.034s, estimated 75s

And all tests pass. So perhaps the Chrome version requires a different approach?

js-writer commented 6 years ago

@michaelwills I have the same error. I'm using chrome 64.0.3282.186 and browser doesn't open.

When I add flag: const chrome = new Chrome({ flags: { headless: false } }); New browser instance open but in it goes to about:blank…

joelgriffith commented 6 years ago

Yeah, there's been some breaking changes in the Chromes remote protocol in recent versions. Unfortunately I'm at least a few days out from revisiting this project to bring it up to date, so I'd love some help:

Otherwise it's going take me a few to get it :/

michaelwills commented 6 years ago

@sefel When I run it visibly, it's actually Google Chrome Canary that launches as opposed to Google Chrome. I'll try to do some more tests.

js-writer commented 6 years ago

@michaelwills Yes I'm sure it was at the most recent version of Chrome (Google Chrome and also on Canary) and I tested it on all systems (Windows/OSX/Ubuntu). So I think it is problem with new Chrome.

MrJadaml commented 6 years ago

I am also running into that Timer error. Here is my output.

Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.                                        

      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:523:19)
      at ontimeout (timers.js:475:11)
      at tryOnTimeout (timers.js:310:5)
      at Timer.listOnTimeout (timers.js:270:5)

Running on linux - no Canary as it is not available for linux :(