-
-
Save jackfranklin/22ba2f390f97c7312cd70025a2096fc8 to your computer and use it in GitHub Desktop.
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
import puppeteer from 'puppeteer'; | |
async function run() { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://example.com'); | |
async function someHelper(element: puppeteer.ElementHandle<HTMLLIElement>): Promise<number> { | |
return 2; | |
} | |
const stuff = await page.$('div') | |
if (!stuff) { | |
throw new Error('no stuff') | |
} | |
const foo = await stuff.evaluate((elem: Element) => { | |
const x = elem.getAttribute('data-x') || '0' | |
return window.parseInt(x); | |
}); | |
console.log(foo) | |
const listItem = await page.$('li') as puppeteer.ElementHandle<HTMLLIElement>; | |
const result = await someHelper(listItem) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment