Skip to content

Instantly share code, notes, and snippets.

Created June 20, 2019 16:27
What would you like to do?
Example puppeteer setup for Joe McCann
const puppeteer = require('puppeteer');
const config = {
entryUrl: '',
auth: {
email: '',
emailSelector: '',
password: '',
passwordSelector: '',
submitButtonSelector: ''
dataSelector: '',
inputSelector: '',
input: '',
inputSubmitSelector: '',
modalTriggerSelector: '',
targetSelector: '',
screenShotPath: ''
(async () => {
const browser = await puppeteer.launch({
headless: false, // remove this once this works
defaultViewport: null, // account for wonky viewport bug on mac
const [ page ] = await browser.pages();
// Start page
await page.goto(config.entryUrl);
// Auth
await page.type(config.emailSelector,;
await page.type(config.passwordSelector, config.password);
// This may be better as a waitForResponse();
await page.waitForNavigation();
// Click on the Data element. You may be able to just navigate directly to the URL
// if the app allows it
// same as above wrt:waitForResponse();
await page.waitForNavigation();
// Enter the "DAYS" input and click on the button
await page.type(config.inputSelector, config.input);
// same wrt:waitForResponse();
await page.waitForNavigation();
// Click on selector for "Bitmex funding rate"
// This is probably better waiting for something specific about the modal/graphic
// maybe an animation end or an event.
await page.waitFor(1000);
// Grab the element that we want to screenshot
const target = page.$(config.targetSelector);
// You can omit the path and have this return a buffer
await target.screenshot({path: config.screenShotPath});
await browser.close();
Copy link

The awaits can be combined in whatever promise-managing way you want. I left them all flat because it'll be easier to test and cut/copy/paste during troubleshooting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment