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

Unable to capture screenshot #8

Closed rahul-sr closed 7 years ago

rahul-sr commented 7 years ago

Getting this error : Unhandled promise rejection (rejection id: 1): Error: unexpected server response (500) and sometimes Error: 'Target.createBrowserContext' wasn't found

Using Chrome Version 59.0.3071.115

Just tried this example:

chrome
    .start()
    .then((tab) =>
        tab.navigate('https://www.google.com/')
        .then(() => tab.screenshot('google.png'))
        .then(() => tab.done())
 );

Also tried other examples , getting the same 500 error. A quick help would be appreciable.

joelgriffith commented 7 years ago

This seems to work for me locally:

const { Chrome } = require('../build');
const chrome = new Chrome();
let tab = {};

chrome
  .start()
  .then((instance) => {
    tab = instance;
    return tab.navigate('https://www.google.com/');
  })
  .then(() => {
    return tab.screenshot('/Users/jgriffith/Downloads/google.png')
  })
  .then(() => {
    return tab.done()
  });

What version of navalia are you using (or did are you on master)?

joelgriffith commented 7 years ago

I should also note that I'll have a larger change coming out soon that will dispose of the start command and make setup much easier, especially when using just the Chrome module

rahul-sr commented 7 years ago

Thanks @joelgriffith for quick response. I used version 0.0.9 . Also I tried after cloning the master and the above example as you mentioned. Still facing the same issue.

Error: unexpected server response (500)
    at ClientRequest._req.on (/Documents/navalia/node_modules/chrome-remote-interface/node_modules/ws/lib/WebSocket.js:651:26)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:191:7)
    at HTTPParser.parserOnIncomingClient (_http_client.js:522:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
    at Socket.socketOnData (_http_client.js:411:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at readableAddChunk (_stream_readable.js:178:18)
    at Socket.Readable.push (_stream_readable.js:136:10)
    at TCP.onread (net.js:561:20)
ReferenceError: tab is not defined

This is the exact error log.

"chrome-remote-interface" is having version : "0.23.3"

joelgriffith commented 7 years ago

It could have to do with the Chrome version difference (I'm using Canary). Try these steps:

Create this file in the root of the repo (temp.js):

const { Chrome }  = require(./build');
const chrome = new Chrome();

chrome.goto('https://www.chromestatus.com/')
.then(() => chrome.screenshot('/Users/jgriffith/Downloads/chromestatus.png')) // Change this filepath for you
.then(() => chrome.done());

Run it with: DEBUG=navalia:chrome node temp.js

rahul-sr commented 7 years ago

@joelgriffith Yes the above solution works, even without the first step (Chrome Canary). Thanks.

joelgriffith commented 7 years ago

Awesome, going to close