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

Basic screenshot example does not work #53

Closed quanghoc closed 7 years ago

quanghoc commented 7 years ago

I am using Chrome stable v60 (not Canary). The code is below

import { Chrome } from 'navalia';
const chrome = new Chrome();

async function screenshot() {
  await chrome.goto('https://www.google.com');
  await chrome.screenshot('body');
  chrome.done();
}

screenshot();

I ran fine without error but no screenshot file either.

Any help?

joelgriffith commented 7 years ago

chrome.screenshot('body') returns a buffer of data, so you'll have to save it via the fs module or something else. Here's a snippet of code:

const data = await chrome.screenshot('body');
const buffer = new Buffer(data, 'base64');
fs.writeFileSync(`some/file/path.png`, buffer, 'base64');
quanghoc commented 7 years ago

Thanks