question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New burstMode for screenshots

See original GitHub issue

Page. _screenshotTask can make up to 4 WebSocket calls before performing the screenshot:

  • Target.activateTarget
  • Page.getLayoutMetrics
  • Emulation.setDeviceMetricsOverride
  • Emulation.setDefaultBackgroundColorOverride

Then it calls Page.captureScreenshot and then it might need to call Emulation.setDefaultBackgroundColorOverride and setViewport .

This hurt the performance when trying to perform screenshots in “burst mode”. With “burst mode” I mean taking a series of screenshots to the same page during a certain period.

With this new BurstMode we would perform those first four calls only on the first screenshot. Then we would call only Page.captureScreenshot.

After screenshots are taken, the user will need to call setBurstModeOff explicitelly. So we run Emulation.setDefaultBackgroundColorOverride and setViewport.

This is how the code would look like:

await page.setViewport({width: 500, height: 500});
await page.goto(server.PREFIX + '/grid.html');
for (let i = 0; i < 30; ++i) {
  promises.push(page.screenshot({
    clip: {
      x: 50 * i,
      y: 0,
      width: 50,
      height: 50
    },
    burstMode = true
  }));
}
await page.setBurstModeOff();

I implemented this on Puppeteer-Sharp, and it performed 2.5x times faster. This was used by a user who wanted to create GIFs from her page. Let me know what you think about it. I’m willing to implement this here.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
aslushnikovcommented, Nov 6, 2018

Hey @kblok, thanks for filing this.

Our screenshots are not very performant indeed. I have a few thoughts regarding this:

  1. The burstMode the way it is implemented here could be done from the user-land. The main performance hit comes from the emulation we do for every screenshot. If instead the viewport is set initially, and the subsequent screenshots are generated without the fullPage argument, then they should be much faster.
// Crude estimation for page width / height
const {width, height} = await page.evaluate(() => ({width: document.body.offsetWidth, height: document.body.offsetHeight});
await page.setViewport({width, height});
await Promise.all(new Array(30).map((_, i) => page.screenshot({
  clip: {
    x: 50 * i,
    y: 0,
    width: 50,
    height: 50
  }
})));
  1. IIRC the protocol implementation of Page.captureScreenshot has a lot of low-hanging fruits to pick that will bump performance; I’d be glad to see this happenning.
  2. Ultimately, the #478 would be a much nicer solution for the GIF-generation usecase and many others.

To summarize, my concerns regarding burst mode are:

  • We have a lot of room for improvement to make screenshots faster on the chromium side, drastically reducing value of “burst mode” API.
  • There are plans for screen capture API that will supersede the “burst mode” API.

Let me know what you think

P.S. awesome work on pptr#! 👍

1reaction
kblokcommented, Nov 6, 2018

The screen capture feature would kill this feature for sure. I don’t know how many users are trying to do “burst mode” to make an important internal change.

The burstMode the way it is implemented here could be done from the user-land.

The main cost here are the WebSocket calls. If the user does that manually, we will go from 7 calls to 4 (because only three calls are under the fullScreen option) and I think those are too many calls if you want to take 3+ screenshots per second.

I just wanted to share my two cents here. Feel free to close this issue if you think it doesn’t worth the effort to implement it.

P.S. awesome work on pptr#! 👍

💪

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capture action shots with Burst mode on your iPhone camera
Use Burst mode on your iPhone camera to take multiple high-speed photos so that you have a range of photos to choose from...
Read more >
Here's how I setup & use "Burst Mode" or "Continuous ... - Reddit
Here's how I setup & use "Burst Mode" or "Continuous Shooting" for split-second in-game screenshots.
Read more >
How to Take, View, & Save Burst Photos on iPhone (2022)
How to Take Burst Photos · Open the Camera app. · Frame your shot, then tap and hold on the Shutter button at...
Read more >
How to use iPhone burst mode to better capture the moment
Open the Settings app on your iPhone. Scroll down and tap Camera. Toggle on Use Volume Up for Burst. a screenshot showing how...
Read more >
How to use burst mode with iPhone 11 and 12 cameras
How to use burst mode with iPhone 11 and 12 cameras · Press and immediately drag the shutter button to the left for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found