Created
November 4, 2020 20:58
-
-
Save captainbrosset/995fe46ff62d89f4b684c5245c0633df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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