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
21
votes
4 answers

How to deal with the captcha when doing Web Scraping in Puppeteer?

I'm using Puppeteer for Web Scraping and I have just noticed that sometimes, the website I'm trying to scrape asks for a captcha due to the amount of visits I'm doing from my computer. The captcha form looks like this one: So, I would need help…
user10021033
21
votes
1 answer

Nodejs/Puppeteer - How to use page.evaluate

I know is a noob question, but I want to know when I should use page.evaluate I also know the documentation exists, but I still do not understand Can anybody give me an explanation about how and when to use this function when creating a scraper with…
nanquim
  • 1,786
  • 7
  • 32
  • 50
21
votes
1 answer

Jest onFailure hook

I have a test suite running using Jest. I would like to trigger a hook after any failed test, ideally with the context of the test still available. Specifically, I am using Puppeteer via jest-puppeteer. The goal is to take a screenshot of the page…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
21
votes
4 answers

How to simulate a drag and drop action in puppeteer?

I have React-DnD(Drag and drop) in my application. I'd like test it E2E. What I want to simulate is drag a particular element and drop to a particular place. How do I do this? What I have is: //test.js const mouse = page.mouse; await…
Khushi
  • 1,759
  • 6
  • 26
  • 45
21
votes
3 answers

Why can't I access 'window' in an exposeFunction() function with Puppeteer?

I have a very simple Puppeteer script that uses exposeFunction() to run something inside headless Chrome. (async function(){ var log = console.log.bind(console), puppeteer = require('puppeteer'); const browser = await…
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
21
votes
1 answer

Detect and test Chrome Extension using Puppeteer

Is there a way to test a Chrome extension using Puppeteer? For example can an extension detect that Chrome was launched in "test" mode to provide different UI, check content scripts are working, etc?
ebidel
  • 23,921
  • 3
  • 63
  • 76
21
votes
3 answers

Puppeteer: How to listen to object events

Is it possible to listen to events dispatched by in-page objects? Let's say I have this code in the page I go to: var event = new CustomEvent('status', { detail: 'ok' }); window.addEventListener('status', function(e) { console.log('status: ',…
Vic
  • 211
  • 1
  • 2
  • 5
20
votes
3 answers

How to upload file with JS/Puppeteer

I'm trying to figure out how to upload a picture file into an input dialog. It isn't possible to just type in the name and hit enter as I don't see a way in order to automate that with Puppeteer. I figure I will have to set some value as the picture…
user3562806
  • 219
  • 1
  • 2
  • 6
20
votes
4 answers

Can't Use Puppeteer -- Error: Failed to launch chrome

This is the error I get. This occurs when the test code is run in the Gitlab CI. However, it works fine locally. Someone please help? 2036 $ npm test 2037 > 10_auth@1.1.3 test /builds/brhanuh/domestic-repair 2038 > jest --coverage…
Hanibal Brhanu
  • 200
  • 1
  • 1
  • 7
20
votes
1 answer

TypeScript - Puppeteer library error: "Cannot find name 'Element'"

I have included puppeteer-core as a dependency in my TypeScript project, and am using Visual Studio 2019. When I try to build the project, I get this error below (as shown by the red squiggly underline under Element): error TS2304: Build:Cannot…
aBlaze
  • 2,436
  • 2
  • 31
  • 63
20
votes
3 answers

How do i return a value from page.evaluate() in puppeteer?

I am trying to get a value from inside page.evaluate() body in my YouTube scraper that I've built using Puppeteer. I am unable to return the result from page.evaluate(). How do I achieve this? Here's the code: let boxes2 = [] const getData =…
Rohit
  • 1,385
  • 2
  • 15
  • 21
20
votes
2 answers

Puppeteer | Wait for all JavaScript is executed

I try to take screenshots from multiple pages, which should be fully loaded (including lazy loaded images) for later comparison. I found the lazyimages_without_scroll_events.js example which helps a lot. With the following code the screenshots are…
vaxul
  • 403
  • 1
  • 4
  • 14
20
votes
3 answers

puppeteer : how check if browser is still open and working

im trying to open multiple tabs in a single browser instance , after they're done i close the tabs and then re-opening those tabs every x seconds ... but i want to keep the browser itself open so i dont have to login in each tab on every loop so…
hretic
  • 999
  • 9
  • 36
  • 78
20
votes
4 answers

Checking an element is disabled using Puppeteer

I have a button that has an initial state of disabled -
20
votes
5 answers

Puppeteer not running in headless:false mode

Im trying to start puppeteer in headless:false mode. It's working on my local machine but when i push it to my server and try to start it i get this error: 4|scraperP | You have triggered an unhandledRejection, you may have forgotten to catch a…
Pjotr Raskolnikov
  • 1,558
  • 2
  • 15
  • 27