Skip to content

Instantly share code, notes, and snippets.

@justinfagnani
Last active February 8, 2020 05:38
Show Gist options
  • Save justinfagnani/d3298c9c752774f3aaf08e61f109855d to your computer and use it in GitHub Desktop.
Save justinfagnani/d3298c9c752774f3aaf08e61f109855d to your computer and use it in GitHub Desktop.

This is a reproduction for https://bugs.chromium.org/p/chromium/issues/detail?id=1050221

To reproduce:

  1. Download gist
  2. run npm i
  3. run npm start

Chrome will start, cycle through some async tasks, and print the duration to the document and the terminal running node. On my laptop it takes ~500ms.

Next, run npm start again, bug switch back to the terminal as soon as Chrome launches. There should be enough time to put Chrome in the background before the task completes. The tasks should either never start or never complete. If you put Chrome in the foreground, the tasks will finish quickly.

const wd = require('wd');
const Koa = require('koa');
const selenium = require('selenium-standalone');
const {promisify} = require('util');
const seleniumConfig = {
'baseURL': 'https://selenium-release.storage.googleapis.com',
'version': '3.141.59',
'drivers': {
'chrome': {
'version': '2.43',
'arch': process.arch,
'baseURL': 'https://chromedriver.storage.googleapis.com'
},
}
};
(async () => {
const port = 3000;
const app = new Koa();
app.use(async ctx => {
ctx.body = `
<!doctype html>
<script>
const start = performance.now();
(async () => {
await new Promise((resolve) => setTimeout(() => resolve()));
console.log('Start: ' + start);
for (let i = 0; i < 100; i++) {
await new Promise((resolve) => setTimeout(() => resolve()));
}
const end = performance.now();
console.log('End: ' + end);
const time = end - start;
console.log('Finished in ' + time);
document.body.innerHTML = '<p id="result">' + time + '</p>';
})();
</script>
`;
});
app.listen(port);
const browser = wd.promiseChainRemote();
try {
await promisify(selenium.install)(seleniumConfig);
await promisify(selenium.start)(seleniumConfig);
await browser.init({browserName:'chrome'});
console.log('Selenium started');
await browser.get(`http://localhost:${port}`);
const resultEl = await browser.waitForElementById('result', 100000);
const result = await resultEl.text();
console.log('Finished', result);
await browser.close();
} catch (e) {
console.error(e.message);
}
})();
{
"name": "chrome-slow",
"version": "0.0.0",
"private": true,
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"koa": "^2.11.0",
"selenium-standalone": "^6.7.0",
"wd": "^1.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment