Skip to content

Instantly share code, notes, and snippets.

@captainbrosset
Created November 4, 2020 20:58
Show Gist options
  • Save captainbrosset/995fe46ff62d89f4b684c5245c0633df to your computer and use it in GitHub Desktop.
Save captainbrosset/995fe46ff62d89f4b684c5245c0633df to your computer and use it in GitHub Desktop.
const {writeFile} = require('fs');
const CDP = require('chrome-remote-interface');
const WIDTH = 892;
const HEIGHT = 689;
const URL = 'https://google.com';
let client;
async function getClient() {
if (!client) {
client = await CDP();
}
return client;
}
async function getPageDomain() {
const client = await getClient();
const {Page} = client;
await Page.enable();
return Page;
}
async function startScreencast(url) {
const Page = await getPageDomain();
await Page.navigate({url});
await Page.loadEventFired();
await Page.setDeviceMetricsOverride({width: WIDTH, height: HEIGHT, deviceScaleFactor: 1, mobile: false});
client.on('Page.screencastFrame', frame => {
console.log(frame.metadata);
writeFile(`images\\frame.png`, frame.data, {encoding: 'base64'}, err => {});
setTimeout(() => {
Page.screencastFrameAck({sessionId: frame.sessionId});
}, 500);
});
await Page.startScreencast({quality: 100, maxWidth: WIDTH, maxHeight: HEIGHT});
}
startScreencast(URL);
{
"name": "screencast",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chrome-remote-interface": "^0.28.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment