Skip to content

Instantly share code, notes, and snippets.

@patrickhulce
Created February 11, 2022 19:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickhulce/f954c4bce1dc68bfc8154ef7f491cd04 to your computer and use it in GitHub Desktop.
Save patrickhulce/f954c4bce1dc68bfc8154ef7f491cd04 to your computer and use it in GitHub Desktop.
Chromium hangs on screenshots when `--disable-frame-rate-limit` is used.
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"]
{
"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"
}
}
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