Created
February 11, 2022 19:47
-
-
Save patrickhulce/f954c4bce1dc68bfc8154ef7f491cd04 to your computer and use it in GitHub Desktop.
Chromium hangs on screenshots when `--disable-frame-rate-limit` is used.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:16-buster | |
WORKDIR /app | |
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - | |
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list | |
RUN apt-get update | |
RUN apt-get install -y google-chrome-stable | |
COPY package.json ./ | |
RUN npm install | |
COPY run.js ./ | |
CMD ["node", "run.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "puppeteer-screenshot-hang", | |
"version": "1.0.0", | |
"description": "", | |
"main": "run.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"puppeteer": "^13.3.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer') | |
async function main() { | |
const browser = await puppeteer.launch({ | |
headless: true, | |
args: [ | |
'--no-sandbox', | |
'--disable-frame-rate-limit', | |
], | |
}) | |
try { | |
for (let i = 0; i < 100; i++) { | |
console.log(`Test #${i}`) | |
const page = await browser.newPage() | |
await page.evaluate(() => (document.body.textContent = 'Hello, World!')) | |
console.log('Take screenshot.') | |
const result = await Promise.race([ | |
page.screenshot({type: 'png'}), | |
new Promise(r => setTimeout(r, 10_000)), | |
]) | |
if (!result) throw new Error(`Chromium is hung`) | |
console.log('Screenshot successful.') | |
} | |
} catch (err) { | |
console.error(err) | |
} finally { | |
await browser.close() | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment