Relative Content

Tag Archive for puppeteer

launch puppeteer without blocking the cli

using puppeteer, i wrote a code that will be executed from the command line and i want to open the browser, navigate to a web page, keep the browser open and retain control to the command line.

Does puppeteer render properly?

I’m using puppeteer to take screenshots for reporting but can’t seem to get a good image from it. Is it possible to render ‘properly’ or is the below image the best I’m going to get?

How to continue from where the last browser session is left with?

#!/usr/bin/env node // vim: set noexpandtab tabstop=2: const puppeteer = require(‘puppeteer’) const browserURL = ‘http://127.0.0.1:9222’ let browser; (async () => { // const browser = await puppeteer.launch({headless: false}); browser = await puppeteer.connect({browserURL}) const page = await browser.newPage() await page.goto(‘https://httpbin.org’) })() .catch(err => console.error(err)) .finally(() => browser?.disconnect()) Suppose that I connect an existing browser process in […]

How to wait until an element disappears?

==> autoremove.html <== <!DOCTYPE html> <html> <head> <title>Delayed Deletion</title> </head> <body> <button id=”myButton”>Click me!</button> <script> var button = document.getElementById(“myButton”); setTimeout(function() { button.remove(); }, 3000); </script> </body> </html> ==> main.js <== #!/usr/bin/env node // vim: set noexpandtab tabstop=2: const puppeteer = require(‘puppeteer’); const browserURL = ‘http://127.0.0.1:9222’; const url = process.argv[2] let browser; (async () => { […]

How to get the last matched element in puppeteer?

const puppeteer = require(‘puppeteer’); const url = process.argv[2] const selector = process.argv[3] const browserURL = ‘http://127.0.0.1:9222’ ;(async () => { const browser = await puppeteer.connect({browserURL}) const page = await browser.newPage() await page.goto(url) const element = await page.$(selector) console.log(await page.evaluate(el => el.outerHTML, element)) await browser.disconnect() })(); Input html file. <html lang=”en”> <body> <div> <message-content> ABC </message-content> […]