-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screencast API #881
Screencast API #881
Conversation
There also appears to be bugs in the DTP screen api:
e.g. Using |
lib/Screencast.js
Outdated
canvas.style.display = 'none'; | ||
canvas.width = WIDTH; | ||
canvas.height = HEIGHT; | ||
canvas.style.width = `${WIDTH / 2}px`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically you scale a canvas according to the DPR of the device so the images are clear. IOW, if the screencast api captured images at 1000x800 and DPR was 2, you'd want to create a 500x400 canvas. I think we can probably remove this since 1.) we're not accounting for DPR here and 2.) The DTP screen API doesn't respect DPR.
can we get a stream api? const express = require('express');
const app = express();
async function screencastSteps(page) {
await page.goto(...);
// ... other stuff ...
}
app.get('/goofy', function(req, res) {
res.setHeader('Content-Type', 'video/ogg');
page.screencast.start(screencastSteps).pipe(res);
});
app.listen(9999); |
I especially love the "no dependencies" part, impressive. Can you write frames iteratively so that you don't accumulate them all in the memory? |
For producing image frames, users can do: const frames = [];
page.screencast.on('frame', frame => {
frames.push(frame.buffer);
}); For the video chunks, it looks like
We can send back video chunks at 1s intervals or something, but I'm not sure how useful individual small chunks would be in practice. Users would still need to put them together. That said, it's just a one liner ( https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/ondataavailable Thoughts? |
@ebidel using an async iterator would allow users to request frames whenever they need them (it's a pull based async collection) |
@graingert async iterators are still a ways off. http://node.green/#ESNEXT-candidate--stage-3--Asynchronous-Iterators-for-await-of-loops |
Is it possible to support fixed FPS in Puppeteer? Or should it be first implemented in DevTools Protocol? |
@RobertoUa DT would need to support that. Once this PR lands, you could also write a script that encodes the frames at the desired rate, using ffmpeg or something. |
@aslushnikov anything else we want to change before I add tests and document?
Were you referring to image frames or video chunks? For the former, we could write frames as they happen but I think that would mean changing the API to look like this:
or make users save frames themselves and call an extra method to produce the video:
...not as nice IMO but wouldn't store any frames in mem. |
@ebidel how about #881 (comment) |
Then you don't need a "start/stop" |
@graingert looks neat, but that's a different shape than the rest of the codebase/API. We don't use streams anywhere else AFAIK. In the future, I'm imaging we could add other APIs like |
I would also like to get video chunks iteratively (to stream them to ffmpeg for transcoding, for instance) |
Also wanted to add that this is really exciting. As someone who was generating frames one by one in Phantom.js to create videos, there are so many things that this is going to enable. Great job @ebidel 🙏 |
/** @type {boolean} */ | ||
this._recording = false; | ||
|
||
this._client.on('Page.screencastFrame', event => this._onScreencastFrame(event)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want to use this api for video streaming; it gonna be slow and low-quality. We'd need to introduce a nicer API for the protocol first to have this feature in pptr.
Closing this in favor of upstream implementation: https://bugs.chromium.org/p/chromium/issues/detail?id=781117 |
:( seems like the upstream stalled out almost right after it started. Is anyone able to shed light of if this feature is still being pursued? Thanks for all the hard work! #478 and this were a very interesting read. |
Fixes #478.
Want to get some feedback on this before finishing tests and api docs.
The shape of the API is similar to Tracing. This PR introduces
page.screencast
:Passing a
path
creates a .webm video file when you callstop()
. The solution uses no dependencies, only web platform APIs! The downside is that capturing a 'recording' is real-time, meaning longer videos will take more time to complete.