Skip to content

Instantly share code, notes, and snippets.

Tristan Sokol tristansokol

Block or report user

Report or block tristansokol

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View puppeteer-navigation.js
await Promise.all([
page.waitForNavigation({}),
page.click('#tickets > div.container > div > div > div > h2:nth-child(5) > button > i', {
button: 'left',
delay: 200
})
]);
View puppeteer-registration.js
const puppeteer = require('puppeteer');
browser = await puppeteer.launch({
headless: true,
slowMo: 80,
});
page = await browser.newPage();
await page.goto('http://example.com');
View image-diff.js
await page.goto('https://www.wikihow.com/Tie-Your-Shoes');
await page.waitForSelector('#article_shell');
await page.screenshot({
path: './production.png',
fullPage: false,
})
await page.goto('https://www.wikihow.com/Tie-Your-Shoes');
await page.waitForSelector('#article_shell');
await page.screenshot({
path: './local.png',
View headless-chrome-image-diff.sh
$ chrome --headless --screenshot=local.png \
--window-size=1280,1000 localhost:8080
$ chrome --headless --screenshot=production.png \
--window-size=1280,1000 https://example.com/
$ pixelmatch local.png production.png output.png 0.1
View puppeteer-keyboard.js
page.type('#name','Sammy',{
delay: 50//how long to wait between keystrokes
})
page.keyboard.type('Hello World!');
page.keyboard.press('ArrowLeft');
await page.keyboard.down('Shift');
await page.keyboard.up('Shift');
View puppeteer-mouse.js
let mouse = page.mouse();
// same as page.click(), but uses a page x,y coordinate
mouse.click(300, 287,{
button: 'middle',//left, right, middle
clickCount: 2,
delay: 20 //how long to hold down the mouse button
})
mouse.down();
mouse.up();
mouse.move(x,y);
View puppeteer-click.js
page.click('#checkout',{
button: 'left', //left, right, middle,
clickCount: 1,
delay: 200 //how long to hold down the mouse button
})
View puppeteer-page-events.js
page.on('console', msg => {});
page.on('dialog', msg => {});
page.on('error', msg => {});
page.on('frameattached', msg => {});
page.on('framenavigated', msg => {});
page.on('load', msg => {}); //javascript load events
page.on('request', msg => {});
page.on('response', msg => {});
page.on('workercreated', msg => {});
View puppeteer-page.js
const page = await browser.newPage();
page.reload();
page.setExtraHTTPHeaders({});
page.setRequestInterception(value)
page.setJavaScriptEnabled(enabled)
page.setOfflineMode(enabled)
View puppeteer-browser.js
browser = await puppeteer.launch({
headless: //Whether to run browser in headless mode
executablePath: //path to a specified version of chrome to run
slowMo: //slows down all actions
defaultViewport: {
width:
height:
deviceScaleFactor:
isMobile:
hasTouch:
You can’t perform that action at this time.