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
20
votes
2 answers

What are active handles in Node.js

I see that my applications active handle count keeps on increasing. What exactly is the number of active handles ? Is this something i have to take care of preventing the app from crashing?
Balanarayanan
  • 481
  • 1
  • 5
  • 11
19
votes
1 answer

Puppeteer: Chromium instances remain active in the background after browser.disconnect

My environment Puppeteer version: 3.1.0 Platform / OS version: Windows 10 Node.js version: 12.16.1 My problem is: I have a for...of loop to visit 3000+ urls with puppeteer. I use puppeteer.connect to wsEndpoint so I can reuse one browser…
theDavidBarton
  • 7,643
  • 4
  • 24
  • 51
19
votes
1 answer

Puppeteer: how to download entire web page for offline use

How would I scrape an entire website, with all of its CSS/JavaScript/media intact (and not just its HTML), with Google's Puppeteer? After successfully trying it out on other scraping jobs, I would imagine it should be able to. However, looking…
Coolio2654
  • 1,589
  • 3
  • 21
  • 46
19
votes
2 answers

Puppeteer console.log - How to look inside JSHandle@object?

I have a React/Redux app that I am testing using Puppeteer. Based on the documentation, I am using the following code to show the console outputs: page.on('console', msg => { for(let i = 0; i < msg.args().length; ++i) { let text =…
aditi
  • 585
  • 1
  • 7
  • 14
19
votes
2 answers

How to use xpath in chrome headless+puppeteer evaluate()?

How can I use $x() to use xpath expression inside a page.evaluate() ? As far as page is not in the same context, I tried $x() directly (like I would do in chrome dev tools), but no cigar. The script goes in timeout.
MevatlaveKraspek
  • 2,246
  • 3
  • 20
  • 23
18
votes
4 answers

Node.js + Puppeteer on Docker, No usable sandbox

i'm building a node.js LTS application. I followed puppeteer documentation, so my Dockerfile has this content: FROM node:12.18.0 WORKDIR /home/node/app ADD package*.json ./ # Install latest chrome dev package and fonts to support major charsets…
18
votes
1 answer

Docker Node:Alpine-12: how to install Chromium 73 in Dockerfile?

Since I would like to run Puppeteer@1.19 but faces error in page.pdf(). Some blobs just mentioned to downgrade Chromium from version 76 to 73. How to do it in Dockerfile with using node:alpine-12? Thanks Below is my setting (chromium version is…
DaiKeung
  • 1,077
  • 1
  • 19
  • 38
18
votes
2 answers

Test callback function with jest

I'm trying to test a function with a callback inside. I set up a mock function, but I also need to test a callback. I've tried to separate it as another mock function, but it doesn't counted as covered. Function I'm trying to test: export const…
Elena
  • 569
  • 3
  • 7
  • 19
18
votes
1 answer

How to Clear History (Clear browsing data) In Node.js Puppeteer Headless=false Chromium browser

I am tring to delete history in headless=false browser with node.js puppeteer through below code but non of method work. await page.goto('chrome://settings/clearBrowserData'); await page.keyboard.down('Enter'); Second code await…
Zilvia Smith
  • 511
  • 2
  • 5
  • 10
18
votes
3 answers

How can I wait for network idle after click on an element in puppeteer?

How can I wait for network idle after click on an element in puppeteer? const browser = await puppeteer.launch({headless: false}); await page.goto(url, {waitUntil: 'networkidle'}); await page.click('.to_cart'); //Click on element trigger ajax…
Serhii Shliakhov
  • 2,631
  • 3
  • 19
  • 37
18
votes
2 answers

Puppeteer sandbox on Linux : No usable sandbox

I installed Puppeteer to use it in the generation of pdf / minuatures, but I can not activate and configure Chrome Linux Sandbox. Always the same error message : (node:46) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome! …
mahdi
  • 219
  • 1
  • 3
  • 11
18
votes
1 answer

Code Coverage on React with Puppeteer + Istanbul

I have an app created with create-react-app and some UI tests written in Jest + Istanbul. I want to get code coverage of these UI tests. I like to keep using jest as I already use it for unit-tests. I'd like not to eject create-react-app if at all…
bhathiya-perera
  • 1,303
  • 14
  • 32
18
votes
1 answer

Puppeteer Sharp: avoid downloading Chromium (bundle Chromium locally)

I'm using Puppeteer Sharp in my .NET application to do some webpage automation tasks. However, I have to deploy my app in an environment that only has intranet access, which means Puppeteer's BrowserFetcher class is unable to download Chromium from…
Master_T
  • 7,232
  • 11
  • 72
  • 144
18
votes
2 answers

Converting an ElementHandle to a DOM element using puppeteer?

This is how I currently get each DOM property from an ElementHandle : let section: ElementHandle = await page.waitForSelector(".selector-list li"); let tagName = await section.$eval('a', (e) => e.tagName); But here it's tagName. What if I'd like…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
18
votes
5 answers

integrate puppeteer in gitlab with gitlab-ci.yml

Im currently working on e2e test in Chrome Puppeteer. I am at the stage where it would be ideal to integrate my tests in the development process. What I want to accomplish is the following: my tests run automated before every deploy to production.…