How to use Puppeteer in an Angular application

How to use Angular e2e testing with Puppeteer 1) Install Puppeteer npm install –save-dev puppeteer @types/puppeteer 2) Configure Protractor to use Puppeteer Edit your protractor.conf.js and add the following inside capabilities: // … const puppeteer = require(‘puppeteer’); exports.config = { // … capabilities: { browserName: ‘chrome’, chromeOptions: { args: [‘–headless’], binary: puppeteer.executablePath(), }, }, // … Read more

Chrome Headless puppeteer too much CPU

my default args, please test it and tell me if this run smoothly. Please note that –no-sandbox isn’t secure when navigate to vulnerable sites, but it’s OK if you’re testing your own sites or apps. So make sure, you’re know what you’re doing. const options = { args: [ ‘–no-sandbox’, ‘–disable-setuid-sandbox’, ‘–disable-dev-shm-usage’, ‘–disable-accelerated-2d-canvas’, ‘–no-first-run’, ‘–no-zygote’, … Read more

Property ‘innerText’ does not exist on type ‘Element’

You can fix it like this: const data = await page.$eval(selector, node => (node as HTMLElement).innerText); or: const data = await page.$eval(selector, node => (<HTMLElement>node).innerText); UPDATE: So, after some exchange on Github, it’s clear why the syntax from this question does not work. It actually defines anonymous generic function. <HTMLElement>(node: HTMLElement) => node.innerText Clearer example … Read more

Injecting CSS into site with Puppeteer

addStyleTag: You can use page.addStyleTag to add some style which will either add a link or style tag based on your options which can be a url, path or some css content. // url await page.addStyleTag({url: ‘http://example.com/style.css’}) // path, can be relative or absolute path await page.addStyleTag({path: ‘style.css’}) // content await page.addStyleTag({content: ‘.body{background: red}’}) evaluateOnNewDocument: … Read more

Running headless Chrome / Puppeteer with –no-sandbox

I was hitting a similar problem trying to run Chromium headless in an Alpine Docker container, and apparently so are many other (e.g., here, here). The –no-sandbox option is a straightforward workaround but obviously a poor security practice. What worked for me was setting a custom seccomp. Download this file (if interested, see the author’s … Read more

Puppeteer not rendering color, background color when I try to save PDF on disk

Puppeteer is just a library to drive Chrome/Chromium, so if anything goes wrong while using it, our best bet is to open Chromium with puppeteer.launch({headless:false}) and debug there. Set your page css in <style></style> tag. You can solve the issue with the following CSS code: html { -webkit-print-color-adjust: exact; } p { color: #FF0000; }

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

It’s fine to run multiple browser, contexts or even pages in parallel. The limits depend on your network/disk/memory and task setup. I crawled a few million pages and from time to time (in my setup, every ~10,000 pages) puppeteer will crash. Therefore, you should have a way to auto-restart the browser and retry the job. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)