Questions tagged [puppeteer]

Puppeteer is a Node.js library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium.

Puppeteer is a Node.js library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium. You can also use Puppeteer with Firefox Nightly (experimental support).


Puppeteer is mostly used for:

  1. Generate screenshots and PDFs of pages.
  2. Crawl an SPA and generate pre-rendered content (i.e. "SSR").
  3. Scrape content from websites.
  4. Automate form submission, UI testing, keyboard input, etc.
  5. Create an up-to-date, automated testing environment. Run your tests directly in the latest version of Chrome using the latest JavaScript and browser features.
  6. Capture a timeline trace of your site to help diagnose performance issues.

Resources:

Books:

7753 questions
14
votes
2 answers

How to invoke Chrome Node Screenshot from the console?

I know you can capture a single html node vial the command prompt, but is it possible to do this programmatically from the console similar to Puppeteer? I'd like to loop all elements on a page and capture them for occasional one-off projects where I…
motleydev
  • 3,327
  • 6
  • 36
  • 52
14
votes
2 answers

How to execute a js function on the page while automating in puppeteer?

Say the script has navigated to a certain page. How to execute a js function inside that script? describe("TestSuite", () => { test("Login", async() => { await page.goto(APP); await page.waitForSelector("[name=loginForm]"); await…
dina
  • 937
  • 1
  • 12
  • 29
14
votes
2 answers

How to blur input element in puppeteer?

I'm testing form with puppeteer. The form has validation that fires when blur event happens on input element. But there are no API to blur element in puppeteer. I'm trying focusing/clicking body or div element, but that can't fire my onBlur…
Ryoji Ishii
  • 303
  • 1
  • 4
  • 14
14
votes
4 answers

Puppeteer: How to select a dropdown option based on its text?

In Puppeteer, we can select an option of a dropdown by providing the value as a parameter: page.select('select#idOfSelect', 'optionValue'); Is there a function to select an option based on its text and not from its value?
14
votes
1 answer

Getting the sibling of an elementHandle in Puppeteer

I'm doing const last = await page.$('.item:last-child') Now I'd love to get the preceding element based on last. ie const prev = last.$.prev() Any thoughts on how to do this? Thanks!
bernatfortet
  • 2,084
  • 4
  • 22
  • 28
14
votes
3 answers

Puppeteer in docker container: Chromium revision is not downloaded

I'm trying to launch puppeteer in an express app that's run in a docker container, using docker-compose. The line that should launch puppeteer const browser = await puppeteer.launch({args: ['--no-sandbox']}); throws the following error: (node:28)…
ebbishop
  • 1,833
  • 2
  • 20
  • 45
14
votes
2 answers

How to click on a link that has a certain content in puppeteer?

If I have some content in my page such as: Hi! How can I use Google's Puppeteer to automate the clicking of that element? I need to be able to select it based on its contents alone, not id, class or attribute. Is there something like…
Totty.js
  • 15,563
  • 31
  • 103
  • 175
14
votes
4 answers

How to intercept request in Puppeteer before current page is left?

Usecase: We need to capture all outbound routes from a page. Some of them may not be implemented using link elements but via some javascript code or as GET/POST forms. PhantomJS: In Phantom we did this using onNavigationRequested…
Marek Trunkát
  • 729
  • 1
  • 6
  • 9
14
votes
3 answers

How to stop puppeteer follow redirects

Currently it seems the default behaviour of puppeteer is to follow redirects and return the DOM at the end of the chain. How can I make the .goto() method to stop after the first redirect happened and simply return the html from that first 3xx page…
makeitmorehuman
  • 11,287
  • 3
  • 52
  • 76
13
votes
4 answers

Cloud Functions Puppeteer cannot open browser

My setup in GCF: install npm install --save puppeteer from project cloud shell edit package.json like so: { "dependencies": { "puppeteer": "^19.2.2" } } paste code from medium.com into…
smith007
  • 221
  • 2
  • 9
13
votes
1 answer

puppeteer - Error: Protocol error (Network.getResponseBody): No resource with given identifier found

I'm trying with this code to get the response body from a website using puppeteer #!/usr/bin/env node require('dotenv').config(); const puppeteer = require('puppeteer'); const readline = require('readline').createInterface({ input:…
newbiedev
  • 2,607
  • 3
  • 17
  • 65
13
votes
3 answers

Convert HTML to PDF or PNG without headeless browser instance in NodeJS

TL;DR: Any suggestions in NodeJS to convert an HTML to PDF or PNG without any headless browser instances. Also anyone uses puppeteer in any production environment. I would like to know how the resource utilisations and performance of running…
Anand Prem
  • 397
  • 5
  • 15
13
votes
4 answers

Error: Could not find browser revision 756035. Run "npm install"

My code is as follows: const browser = await puppeteer.launch({headless: params["headless"]}); const page = await browser.newPage(); await page.setJavaScriptEnabled(true); await page.setRequestInterception(true); ... The issue is…
Amna Arshad
  • 767
  • 3
  • 10
  • 21
13
votes
1 answer

Force headless chromium/chrome to use actual gpu instead of Google SwiftShader

I'm trying to print html to pdf using headless chromium (using puppeteer) and everything works fine except if html contains large png images (over 10.000x10.000px) the whole process of rendering page takes extremely long (up to half an hour, but if…
Danhoss
  • 131
  • 1
  • 1
  • 4
13
votes
3 answers

Puppeteer: How can I wait until a list is closed? How can I wait until an element is disappeared from the DOM?

Сase: There is a list in which you need to select an item, then it closes. When you click on another item the list does not have time to close. Finally there is one more click on another list element. await page.waitForSelector('.list'); await…
Oleksiy
  • 131
  • 1
  • 3