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
73
votes
7 answers

Pressing Enter button in puppeteer

Pressing enter in puppeteer doesn't seem to have any effect. However, when I press other keys, it does what it should. This works: await page.press('ArrowLeft'); This doesn't: await page.press('Enter'); This is how the input looks like: Any…
elena
  • 3,740
  • 5
  • 27
  • 38
69
votes
8 answers

Completely disable auto run of Jest test runner in Visual Studio Code editor

I have some sets of Jest test cases that run Puppeteer browser tests. I have tried these test runners Jest (vscode-jest) Jest Test Explorer (Jest Test Explorer for Visual Studio Code) Jest Runner (vscode-jest-runner) To me, I like Jest Test…
theeranitp
  • 925
  • 1
  • 10
  • 36
68
votes
16 answers

Puppeteer Error: Chromium revision is not downloaded

I used npm i puppeteer as stated in the Documentation and I'm getting the following error: (node:2066) UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install" at Launcher.launch when im…
Moses Schwartz
  • 2,857
  • 1
  • 20
  • 32
68
votes
14 answers

Puppeteer log inside page.evaluate

How can I console.log something inside the page.evaluate, passing it to node and using it during the evaluation of the page? I actually want to log the progress of the page.evaluate to the console and show some results to the user.
Alex Arvanitidis
  • 4,403
  • 6
  • 26
  • 36
63
votes
9 answers

How to set max viewport in Puppeteer?

When I run a new page, I must specify size of the viewport using the setViewport function: await page.setViewport({ width: 1920, height: 1080 }) I want use max viewport. How can I make the viewport resizable according to the window size?
fehif
  • 631
  • 1
  • 5
  • 4
63
votes
5 answers

Puppeteer wait for all images to load then take screenshot

I am using Puppeteer to try to take a screenshot of a website after all images have loaded but can't get it to work. Here is the code I've got so far, I am using https://www.digg.com as the example website: const puppeteer =…
Petar Vasilev
  • 4,281
  • 5
  • 40
  • 74
61
votes
9 answers

How to delete existing text from input using Puppeteer?

I'm trying to test amending text in an editable input which contains the title of the current record - and I want to able to test editing such text, replacing it with something else. I know I can use await page.type('#inputID', 'blah'); to insert…
60
votes
8 answers

Puppeteer - Protocol error (Page.navigate): Target closed

As you can see with the sample code below, I'm using Puppeteer with a cluster of workers in Node to run multiple requests of websites screenshots by a given URL: const cluster = require('cluster'); const express = require('express'); const…
60
votes
3 answers

Puppeteer: How to submit a form?

Using puppeteer, how could you programmatically submit a form? So far I've been able to do this using page.click('.input[type="submit"]') if the form actually includes a submit input. But for forms that don't include a submit input, focusing on the…
docta_faustus
  • 2,383
  • 4
  • 30
  • 47
59
votes
4 answers

Bypassing CAPTCHAs with Headless Chrome using puppeteer

google finds my browser is being manipulated/controlled/automated by software, and because of that I get reCaptcha. When I manual start chromium and do the same steps the reCaptcha doesn't appear. Question 1) Is it possible to solve captcha…
rinold simon
  • 2,782
  • 4
  • 20
  • 39
54
votes
5 answers

Puppeteer in NodeJS reports 'Error: Node is either not visible or not an HTMLElement'

I'm using 'puppeteer' for NodeJS to test a specific website. It seems to work fine in most case, but some places it reports: Error: Node is either not visible or not an HTMLElement The following code picks a link that in both cases is off the…
Vbakke
  • 1,393
  • 1
  • 12
  • 17
53
votes
6 answers

JEST - SyntaxError: Unexpected token 'export' with uuid library

I used to solve similar errors while I was using Jest with only JavaScript, but currently I'm not able to do so with Typescript. All my tests were running fine until I installed Puppeteer which requires @types/jest-environment-puppeteer,…
damdafayton
  • 1,600
  • 2
  • 10
  • 19
52
votes
8 answers

how to get text inside div in puppeteer

const puppeteer = require("puppeteer"); (async function main() { try { const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); page.setUserAgent("Mozilla/5.0 (Windows NT 6.1;…
Koh Shuan Jin
  • 551
  • 1
  • 5
  • 8
52
votes
4 answers

Collect elements by class name and then click each one - Puppeteer

Using Puppeteer, I would like to get all the elements on a page with a particular class name and then loop through and click each one. Using jQuery, I can achieve this with: var elements = $("a.showGoals").toArray(); for (i = 0; i <…
Richlewis
  • 15,070
  • 37
  • 122
  • 283
51
votes
5 answers

VSCODE: No debug adapter, can not send 'variables'"

I'm getting started with pupeteer and node and using vscode in win 10. I'm trying to log into a site and scrape a table. So far I have: (async () => { const browser = await puppeteer.launch({ headless: false, }); var page = await…
user1592380
  • 34,265
  • 92
  • 284
  • 515