Skip to content

Instantly share code, notes, and snippets.

View tristansokol's full-sized avatar

Tristan Sokol tristansokol

View GitHub Profile
await Promise.all([
page.waitForNavigation({}),
page.click('#tickets > div.container > div > div > div > h2:nth-child(5) > button > i', {
button: 'left',
delay: 200
})
]);
const puppeteer = require('puppeteer');
browser = await puppeteer.launch({
headless: true,
slowMo: 80,
});
page = await browser.newPage();
await page.goto('http://example.com');
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',
$ 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
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');
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);
page.click('#checkout',{
button: 'left', //left, right, middle,
clickCount: 1,
delay: 200 //how long to hold down the mouse button
})
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 => {});
const page = await browser.newPage();
page.reload();
page.setExtraHTTPHeaders({});
page.setRequestInterception(value)
page.setJavaScriptEnabled(enabled)
page.setOfflineMode(enabled)
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: