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
30
votes
1 answer

Get the Value of HTML Attributes Using Puppeteer

Using Puppeteer, I've selected some HTML elements using: await page.$$( 'span.styleNumber' ); I can get the element's text using: console.log( await ( await styleNumber.getProperty( 'innerText' ) ).jsonValue() ); How can I the value of the…
GTS Joe
  • 3,612
  • 12
  • 52
  • 94
30
votes
4 answers

How to avoid being detected as bot on Puppeteer and Phantomjs?

Puppeteer and PhantomJS are similar. The issue I'm having is happening for both, and the code is also similar. I'd like to catch some informations from a website, which needs authentication for viewing those informations. I can't even access home…
30
votes
2 answers

How to use Puppeteer in an Angular application

My question is simple but I don't understand if it's possible and, in this case, how it's possible. I would like to use the puppeteer library in an Angular application using the npm package, but I don't understand how I can use it. For example I…
Ronaldonizuka
  • 411
  • 1
  • 4
  • 4
30
votes
3 answers

Is it safe to run multiple instances of Puppeteer at the same time?

Is it safe/supported to run multiple instances of Puppeteer at the same time, either at the process level (multiple node screenshot.js at the same time) or at the script level (multiple puppeteer.launch() at the same time)? What are the…
mjs
  • 63,493
  • 27
  • 91
  • 122
30
votes
7 answers

Puppeteer opens an empty tab in non-headless mode

When running puppeteer(last version from npm - 0.13.0) and passing args to puppeteer.launch({ headless: false }) the chrome is opened with an empty page as a first tab and opens the actual page from the script in the second tab. const page = await…
dre.dev
  • 442
  • 1
  • 4
  • 11
30
votes
3 answers

run puppeteer on already installed chrome on macos

1.How can I run the Puppeteer script on the already installed chrome in mac machine. I tried with the following script, not able to run. 2.Is there any way to open the chrome window with particular window size here I am not talking about viewport, I…
Mohamed Hussain
  • 7,433
  • 14
  • 55
  • 85
30
votes
4 answers

How do you send a POST request in Puppeteer?

I use this code for sending a GET request: (async() => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://www.example.com/search'); const data = await page.content(); …
J. Doe
  • 447
  • 1
  • 4
  • 7
29
votes
3 answers

How to click element in Puppeteer using xPath

I want to click on an element without using css selectors. await page.click() uses selectors to identify the element. So how can I do something like this? await page.click('/*[@id="toc"]/ul/li[1]/a')
Jozott
  • 2,367
  • 2
  • 14
  • 28
29
votes
4 answers

How to reload page in Puppeteer?

I would like to reload the page whenever the page doesn't load properly or encounters a problem. I tried page.reload() but it doesn't work. for(const sect of sections ){ // Now collect all the URLs const appUrls = await…
glhe13
  • 469
  • 1
  • 4
  • 10
28
votes
3 answers

Property 'innerText' does not exist on type 'Element'

I'm using Typescript for Puppeteer. I'm trying to get innerText from an element. const data = await page.$eval(selector, node => node.innerText); I'm getting the error: Property 'innerText' does not exist on type 'Element' I tried casting to…
Scruffy
  • 444
  • 1
  • 6
  • 13
28
votes
5 answers

Get href attribute in pupeteer Node.js

I know the common methods such as evaluate for capturing the elements in puppeteer, but I am curious why I cannot get the href attribute in a JavaScript-like approach as const page = await browser.newPage(); await…
Googlebot
  • 15,159
  • 44
  • 133
  • 229
28
votes
5 answers

Crawling multiple URLs in a loop using Puppeteer

I have an array of URLs to scrape data from: urls = ['url','url','url'...] This is what I'm doing: urls.map(async (url)=>{ await page.goto(url); await page.waitForNavigation({ waitUntil: 'networkidle' }); }) This seems to not wait for page…
ahhmarr
  • 2,296
  • 4
  • 27
  • 30
27
votes
2 answers

Puppeteer: how to store a session (including cookies, page state, local storage, etc) and continue later?

Is it possible to have a Puppeteer script that opens and interacts with a page, and then saves that browser sessions as-is, and have another script load that and continue from there? By "browser session" I mean the currently loaded page including…
RocketNuts
  • 9,958
  • 11
  • 47
  • 88
27
votes
1 answer

Puppeteer fingerprint simulation

By doing tests I am faced with JavaScript fingerprinting such like: audio context fingerprinting opengl fingerprinting canvas fingerprinting installed fonts fingerprinting installed plugins fingerprinting webrtc I want to replace the results of…
27
votes
1 answer

How to make Puppeteer work with a ReactJS application on the client-side

I am fairly new to React and I am developing an app which will take actual screenshots of a web page and the app can draw and add doodles on top of the screenshot taken. I initially used html2canvas and domToImage to take client-side screenshots but…
NoobNewb
  • 583
  • 2
  • 10
  • 21