Skip to content

Commit

Permalink
Add startScreencast()/stopScreencast()
Browse files Browse the repository at this point in the history
  • Loading branch information
dotneet committed Jun 2, 2017
1 parent 8e46818 commit a95c3be
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,25 @@ See examples: [examples/screenshot.js]
##### .pdf()
It export a current screen as a PDF data.
It export a current screen as a PDF data.
See examples: [examples/screenshot.js]
##### .startScreencast(callback, options = {})
Starts screencast to take screenshots by every frame.
See examples: [examples/screencast.js]
###### Parameter
callback: callback function for receiving parameters of screencastFrame event. See details [here](https://chromedevtools.github.io/devtools-protocol/tot/Page/#event-screencastFrame)
options: See details [here](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-startScreencast).
##### .stopScreencast()
Stops screencast.
##### .console(func)
```js
Expand Down
22 changes: 22 additions & 0 deletions examples/screencast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Chromy = require('../src')
const path = require('path')

let chromy = new Chromy()
chromy.chain()
.goto(path.join('file:https://', __dirname, '/pages/index.html'))
.startScreencast(async (payload) => {
console.log(payload.data.length)
}, {format: 'jpeg', quality: 50})
.evaluate(_ => {
setInterval(_ => {
var s = document.createElement('span')
s.innerHTML = 'foo'
document.body.appendChild(s)
}, 50)
})
.sleep(1000)
.stopScreencast()
.sleep(1000)
.end()
.then(_ => chromy.close())
.catch(_ => {console.log(_); chromy.close()})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromy",
"version": "0.1.24",
"version": "0.1.25",
"description": "a library for controlling headless chrome by nightmarejs like API.",
"main": "src/index.js",
"directories": {
Expand Down
13 changes: 12 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ class Chromy {
return Buffer.from(data, 'base64')
}

async startScreencast (callback, options = {}) {
await this.client.Page.screencastFrame(async (payload) => {
await callback.apply(this, [payload])
await this.client.Page.screencastFrameAck({sessionId: payload.sessionId})
})
await this.client.Page.startScreencast(options)
}

async stopScreencast () {
await this.client.Page.stopScreencast()
}

async emulate (deviceName) {
await this.checkStart()

Expand Down Expand Up @@ -520,7 +532,6 @@ class Chromy {
if (origin === null) {
origin = await this.evaluate(_ => { return location.origin })
}
console.log(origin)
return await this.client.Storage.clearDataForOrigin({origin: origin, storageTypes: type})
}

Expand Down

0 comments on commit a95c3be

Please sign in to comment.