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

Puppeteer Execution context was destroyed, most likely because of a navigation

I am facing this problem in puppeteer in a for loop when i go on another page to get data, then when i go back it comes me this error line: Error "We have an error Error: the execution context was destroyed, probably because of a navigation." It's…
50
votes
6 answers

How can I capture all network requests and full response data when loading a page in Chrome?

Using Puppeteer, I'd like to load a URL in Chrome and capture the following information: request URL request headers request post data response headers text (including duplicate headers like set-cookie) transferred response size (i.e. compressed…
Matt Zeunert
  • 16,075
  • 6
  • 52
  • 78
50
votes
9 answers

Puppeteer: How to handle multiple tabs?

Scenario: Web form for developer app registration with two part workflow. Page 1: Fill out developer app details and click on button to create Application ID, which opens, in a new tab... Page 2: The App ID page. I need to copy the App ID from this…
nwxdev
  • 4,194
  • 3
  • 16
  • 22
48
votes
10 answers

Puppeteer is not able to install: "ERROR: Failed to set up Chromium r782078! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download"

I am trying to install Puppeteer in Windows 10 using the below command and am getting an error. The command used to install Puppeteer: npm install --save PUPPETEER Error: ERROR: Failed to set up Chromium r782078! Set "PUPPETEER_SKIP_DOWNLOAD" env…
user3563459
  • 567
  • 1
  • 4
  • 14
48
votes
4 answers

Set pupeteer window size when running not headless (not viewport)

Is it somehow possible to set the browsers (Chrome[ium]) window size like the viewport size? Setting only the viewport results in a unhandy appearance when the browser is not running headfully and I want to visually see what's going on within the…
Bernhard
  • 4,855
  • 5
  • 39
  • 70
47
votes
5 answers

How to pass a function in Puppeteers .evaluate() method

Whenever I try to pass a function, like this: var myFunc = function() { console.log("lol"); }; await page.evaluate(func => { func(); return true; }, myFunc); I get: (node:13108) UnhandledPromiseRejectionWarning: Unhandled promise rejection…
chitzui
  • 3,778
  • 4
  • 28
  • 38
46
votes
2 answers

How to save cookies and load it in another puppeteer session?

I had to request the same webpage twice to get the cookies in the 1st request and use it in the 2nd request in the following example. Could anybody show me the code to save the cookies in one puppeteer session and load it in another session so that…
user1424739
  • 11,937
  • 17
  • 63
  • 152
46
votes
6 answers

How to maximise Screen use in Pupeteer ( non-headless )

I'm testing out puppeteer for chrome browser automation ( previously using selenium but had a few headaches with browser not waiting until page fully loaded ) . When I launch an instance of puppeteer - then it displays the contents taking up less…
Martin Thompson
  • 3,415
  • 10
  • 38
  • 62
45
votes
7 answers

/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory Vercel

when I try to access my API uploaded on vercel server, I'm getting this error. Did anyone have the same error? When I run it locally, it works fine. 2021-02-15T19:38:59.218Z 0109b575-a2e7-478e-aefe-aa3335b5b6b8 ERROR Error: Failed to launch…
Lucas Borim
  • 575
  • 1
  • 5
  • 7
44
votes
9 answers

How to download file with puppeteer using headless: true?

I've been running the following code in order to download a csv file from the website http://niftyindices.com/resources/holiday-calendar: const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless:…
Antonio Gomez Alvarado
  • 1,842
  • 2
  • 13
  • 24
42
votes
3 answers

How to login in Puppeteer?

I'm new to JavaScript and Puppeteer. I tried the login code below, but it failed. In comparison, I added page2 and succeeded. How can I solve it? const CREDS = require('./creds'); async function main() { const puppeteer = require('puppeteer'); …
42
votes
4 answers

Puppeteer - How to fill form that is inside an iframe?

I have to fill out a form that is inside an iframe, here the sample page. I cannot access by simply using page.focus() and page.type(). I tried to get the form iframe by using const formFrame = page.mainFrame().childFrames()[0], which works but I…
Raza
  • 3,147
  • 2
  • 31
  • 35
41
votes
5 answers

While running the script throws cannot find module 'dotenv'

While loading the .env file to pass env values to the getToken.js script in the cypress root folder throws Cannot find module 'dotenv'error. I have installed npm install dotenv. Could someone please advise what I am missing here ? .env file is…
soccerway
  • 10,371
  • 19
  • 67
  • 132
41
votes
8 answers

Puppeteer: Get innerHTML

Does anybody know how to get the innerHTML or text of an element? Or even better; how to click an element with a specific innerHTML? This is how it would work with normal JavaScript: var found = false $(selector).each(function() { if (found)…
Noah
  • 661
  • 1
  • 8
  • 17
41
votes
5 answers

Puppeteer: How to listen to a specific response?

I'm tinkering with the headless chrome node api called puppeteer. I'm wondering how to listen to a specific request response and how to act in consequence. I have look at events requestfinish and response but it gives me all the request/responses…
Alex29
  • 1,211
  • 2
  • 10
  • 20