Created
October 5, 2018 20:10
-
-
Save alexpreynolds/efb585132262dd3968168ef35f964231 to your computer and use it in GitHub Desktop.
Puppeteer PNG + PDF export test
This file contains hidden or 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 stall(stallTime = 3000) { | |
await new Promise(resolve => setTimeout(resolve, stallTime)); | |
} | |
(async() => { | |
const width = 1024; | |
const height = 1280; | |
const browser = await puppeteer.launch({ | |
args: [ | |
'--no-sandbox', | |
`--window-size=${ width },${ height }` | |
], | |
timeout: 10000 | |
}); | |
var page = await browser.newPage(); | |
await page.setViewport({ | |
width: 1024, | |
height: 1280, | |
deviceScaleFactor: 1 | |
}); | |
await page.emulateMedia('screen'); | |
const url = "http://explorer.altius.org/app/?config=SUFTOi4wT5S79NgyLKPTcg&chr=chr3&start=181500000&stop=181800000"; | |
await page.goto(url, { | |
waitUntil: ['networkidle0', 'domcontentloaded', 'load', 'networkidle2'] | |
}); | |
//await stall(); | |
// page.pdf() is currently supported only in headless mode. | |
// @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118 | |
await page.pdf({ | |
path: 'localPuppeteerTest.pdf', | |
width: '1024px', | |
height: '1280px', | |
pageRanges: '1-1' | |
}); | |
await page.screenshot({path: 'localPuppeteerTest.png', fullPage: true}); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment