Skip to content

Instantly share code, notes, and snippets.

@capaj
Created February 21, 2024 07:22
Show Gist options
  • Save capaj/8647a83b5f03786778e5e610ac173b07 to your computer and use it in GitHub Desktop.
Save capaj/8647a83b5f03786778e5e610ac173b07 to your computer and use it in GitHub Desktop.
interview excercise for node.js dev role
import puppeteer from 'puppeteer'
const requestTimings = [] as {
url: string
startTime: number
}[]
async function run() {
const browser = await puppeteer.launch({
headless: false
//executablePath: '/usr/bin/chromium-browser'
})
const page = await browser.newPage()
await page.setRequestInterception(true)
// capture background requests:
page.on('request', (request) => {
const url = request.url()
if (url.startsWith('data:')) {
request.continue()
return
}
requestTimings.push({
url,
startTime: new Date().getTime()
})
request.continue()
})
// capture background responses:
page.on('response', (response) => {
const url = response.url()
const endTime = new Date().getTime()
const startTime = requestTimings.find((r) => r.url === url)?.startTime
if (startTime) {
console.log(url, endTime - startTime)
}
})
// page.goto('https://www.conductor.com/careers/')
// page.goto('https://www.google.com/')
page.goto('https://www.conductor.com/careers/?location=brno')
await page.waitForNetworkIdle({ idleTime: 5000 })
const vacancyCard = 'VacancyCard_title__bpd9S'
// get all vacancy card titles
const vacancyTitles = await page.evaluate((vacancyCard) => {
const titles = Array.from(document.getElementsByClassName(vacancyCard))
return titles.map((title) => title.textContent)
}, vacancyCard)
console.log({
vacancyTitles
})
await browser.close()
console.log('done')
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment