This file contains 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'); | |
browser = await puppeteer.launch({ | |
headless: true, | |
slowMo: 80, | |
}); | |
page = await browser.newPage(); | |
await page.goto('http://example.com'); |
This file contains 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
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', |
This file contains 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
$ 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 |
This file contains 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
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'); |
This file contains 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
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); |
This file contains 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
page.click('#checkout',{ | |
button: 'left', //left, right, middle, | |
clickCount: 1, | |
delay: 200 //how long to hold down the mouse button | |
}) |
This file contains 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
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 => {}); |
This file contains 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 page = await browser.newPage(); | |
page.reload(); | |
page.setExtraHTTPHeaders({}); | |
page.setRequestInterception(value) | |
page.setJavaScriptEnabled(enabled) | |
page.setOfflineMode(enabled) |
This file contains 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
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: |
NewerOlder