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.

Execution ~300x Slower when page backgrounding take a place (headful mode)

See original GitHub issue
  • Puppeteer version: 1.19.0
  • Platform / OS version: Windows 10
  • Node.js version: doesn’t matter

Here is a simple test which shows the problem. In the test we measure the time of the mouse movement, when the page is visible execution of the test is almost instant, but as soon as we minimize chrome, everything gets incredibly slow. But actually the problem is not in minimization, it is just the fastest way to reproduce the issue, in production I noticed the same behavior even when the page is maximized but not visible because another maximized windows is on top, also the same behavior detected when we open new tab in chrome and make it active. Even more when the page goes to this ‘slow’ mode, some js function just stops to work, for example IntersectionObserver callback never called in this mode (https://github.com/GoogleChrome/puppeteer/issues/3156#issuecomment-522600282). This object is used by a puppeteer in click function, and as result Click doesn’t work.

In the test, I used mouse movement from (1,1) to (100,100) and back x25 times. I tried to change the distance from (1,1) to (10,10) but the execution time is not changed it doesn’t depend on distance. But as far I removed one of two calls of mouse movent inside cycle and changed it to move to i, execution time reduced twice:

for(var i=0;i<25;i++){
   await page.mouse.move(1, 1);
   await page.mouse.move(100, 100);
}

changed to =>>>>

for(var i=0;i<25;i++){
    await page.mouse.move(1, i);
}

Also I recorder timeline of page buy using provided api ‘page.tracing.start’ and here is files: trace_ok.json.log trace_slow.json.log Files can be viewed via https://chromedevtools.github.io/timeline-viewer/

As we can see events executes only every 5 seconds. We should have a way to disable this behavior in chrome and do not throttle execution. I tried to use these command-line switches but no result: “–disable-background-timer-throttling”, “–disable-backgrounding-occluded-windows”

Code to reproduce issue:

const puppeteer = require('puppeteer');

(async () => {
    var baseTime=Date.now();

  const browser = await puppeteer.launch({
    headless: false,
//    executablePath :"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
  });
  const page = await browser.newPage();
  await page.goto('https://github.com/',{waitUntil:'load'});

 
  console.log('Start test#1');
  await page.tracing.start({path: 'trace_ok.json'});
  var hrstart = process.hrtime()
  for(var i=0;i<25;i++){
      await page.mouse.move(1, 1);
      await page.mouse.move(100, 100);
  }
  await page.tracing.stop();
  hrend = process.hrtime(hrstart)
  console.info('Execution time normal mode: %ds %dms', hrend[0], hrend[1] / 1000000)
  
  console.log('Please minimize chrome now');
  process.stdout.write('\x07');
  console.log('Wait for user  to minimize chrome');
  await sleep(5000);

  console.log('Start test#2');
  hrstart = process.hrtime()
  await page.tracing.start({path: 'trace_slow.json'});
  for(var i=0;i<25;i++){
      await page.mouse.move(1, 1);
      await page.mouse.move(100, 100);
  }
  await page.tracing.stop();
  hrend = process.hrtime(hrstart)
  console.info('Execution time throttled mode: %ds %dms', hrend[0], hrend[1] / 1000000)
  
  function sleep(ms){
    return new Promise(resolve=>{
        setTimeout(resolve,ms)
    })
}
})();

output:

Start test#1 Execution time normal mode: 0s 823.829ms Please minimize chrome now Wait for user to minimize chrome Start test#2 Execution time throttled mode: 250s 121.6708ms

What is the expected result? Execution time should be similar whenever the application is minimized or in a normal state when devtools is active.

What happens instead? When page window is minimized, execution performance 1000x slower, and some js features doesn’t work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

6reactions
Gdocalcommented, Aug 21, 2019

Update: Quick and dirty fix for this bug is to use Devtools protocol and to send 2 next commands: DOM.enable Overlay.enable

0reactions
0x7357commented, Oct 11, 2022

@Gdocal Thanks for your dirty fix! Have you (in the meantime) found another way/fix? It’s working, but it really feels dirty.

Edit: I struggle with the exact same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slow down browser rendering - javascript - Stack Overflow
It's just for our developers to see which parts of the page are rendered slowly or are "glitchy".
Read more >
Browser - MarketSquare
When a New Page is called without an open browser, New Browser and New Context are executed with default values first.
Read more >
lAX - River Thames Conditions - Environment Agency - GOV.UK
Audi v8t motor, Weer driebergen zeist, Le proporzioni, Epp mhinga website, ... How to get zone 1 parking in dc, Privatne akademije beograd,...
Read more >
Untitled
Telugu ringtones for iphone, Surigao mining v harris, Add background to gif. #tulcea Laatste nieuws swifterbant, Svenska magasinet solkusten, ...
Read more >
dfc90-autopilot-pilot-s-operating-handbook.pdf - fly MAA
All images contained in this manual are for reference use only, and are subject to change. Avidyne strongly recommends that pilots use the...
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