Last active
January 30, 2020 04:20
-
-
Save Jaskaranbir/ab3b7178551b33eca7993ccfb3868673 to your computer and use it in GitHub Desktop.
Some basic experimentation with Puppeteer - Prints response-body and gets screenshot.
This file contains hidden or 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'); | |
const url = process.argv[2]; | |
if (!url) { | |
throw "Please provide URL as a first argument"; | |
} | |
async function run () { | |
const browser = await puppeteer.launch( { | |
headless: true | |
}); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
await page.on('response', async (response) => { | |
console.log('XHR response received'); | |
console.log(await response.text()); | |
}); | |
await page.content(); | |
const body = await page.evaluate(() => { | |
return document.querySelector("body").innerText; | |
}); | |
console.log(body); | |
await page.screenshot({path: 'screenshot.png'}); | |
// browser.close(); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment