Puppeteer

Puppeteer intercept request and respond in json

亡梦爱人 提交于 2020-12-13 17:44:09
问题 So puppeteer provide pretty basic example of intercepting a request for a url to a pic, and responding with a different url to a different pic. Example from their doc here: https://github.com/webdriverio/webdriverio/tree/master/packages/devtools My question is I'm trying to intercept an XHR request and respond with my own json. I can't seem to find the documentation on this. It would be nice if someone can share where more documentation on this can be. Or provide examples of this. I want to

How to detect a colour with Puppeteer?

守給你的承諾、 提交于 2020-12-13 04:49:28
问题 I have been trying to detect the presence of the colour yellow on a web page using Puppeteer. Any insight on how this may be possible would be greatly appreciated! 回答1: With getComputedStyle You can get the colours of a page by applying getComputedStyle on all elements of a page: let colr = new Set(); document.body.querySelectorAll('*').forEach(n => { colr.add(window.getComputedStyle(n).color); colr.add(window.getComputedStyle(n).backgroundColor); }); colr = [...colr]; Or with Puppeteer for

How to Use a reCaptcha token to open a captcha prompt in a different window

我们两清 提交于 2020-12-13 04:23:46
问题 I am Using puppeteer to automate filling out a form. although when testing it in headless: true I can easily solve the captcha there so it is no problem. The problem is the program MUST be headless so in order to solve the captcha I must bring the captcha to a separate window and solve it there. I see you can grab a Recaptcha token but I don't know how I open a Recaptcha window using that token? Almost like a captcha solving window, I don't know if you have to use a certain library? If 回答1: I

Docker NodeJS Puppeteer@2.0.0 - How do fix Failed to launch chrome! issue

你。 提交于 2020-12-13 03:03:24
问题 Without setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true and CHROMIUM_PATH /usr/bin/chromium-browser Without chromium package Error for printPdf() Error: Failed to launch chrome! spawn /usr/src/app/node_modules/puppeteer/.local-chromium/linux-706915/chrome-linux/chrome ENOENT With setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true and CHROMIUM_PATH /usr/bin/chromium-browser With chromium package Error is missing photos sometimes Below is my Dockerfile: FROM alpine:latest WORKDIR /usr/src/app RUN

Puppeteer flow logic, check if navigation has occurred (vs wait for)

十年热恋 提交于 2020-12-12 21:51:31
问题 Looking for some feedback. In Puppeteer, I want to check if navigation has occurred, do something if it has, else do something else if it hasn't (e.g. try again). The two ways of doing it I've come up with are: if (await page.url() != finalURL) { let t = 0; busy: while(t > 400) { try { await Promise.all([ await page.click('#tryAgainLink'), await page.waitForNavigation(), ]); break busy; } catch(err) { // navigation didn't happen t++; await page.waitForTimeout(1500); } } } However my

How to bundle headless chromium module with AWS Lambda?

回眸只為那壹抹淺笑 提交于 2020-12-12 10:25:28
问题 I'm attempting to use Puppeteer with Lambda, however, on serverless deploy, the lambda errors out due to exceeding the 250mb unbundled package size limit. So, to get under the limit, I've switched to Puppeteer core which doesn't come packaged with chromium. This requires referencing a path to an executable to launch chrome. (e.g. puppeteer.launch({executablePath: headlessChromiumPath}) ); However, I'm not sure how to load a headless Chromium into my container so that I can later reference it.

Puppeteer performance timeline?

僤鯓⒐⒋嵵緔 提交于 2020-12-11 04:56:59
问题 Is there a way to record a performance timeline for tests run with Puppeteer? 回答1: Yes, just use page.tracing methods like in this example: const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.tracing.start({ path: 'trace.json' }); await page.goto('https://en.wikipedia.org'); await page.tracing.stop(); await browser.close(); })(); And then load trace.json file in Chrome Performance tab. If you want

Puppeteer performance timeline?

邮差的信 提交于 2020-12-11 04:56:46
问题 Is there a way to record a performance timeline for tests run with Puppeteer? 回答1: Yes, just use page.tracing methods like in this example: const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.tracing.start({ path: 'trace.json' }); await page.goto('https://en.wikipedia.org'); await page.tracing.stop(); await browser.close(); })(); And then load trace.json file in Chrome Performance tab. If you want

Puppeteer performance timeline?

别来无恙 提交于 2020-12-11 04:56:13
问题 Is there a way to record a performance timeline for tests run with Puppeteer? 回答1: Yes, just use page.tracing methods like in this example: const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.tracing.start({ path: 'trace.json' }); await page.goto('https://en.wikipedia.org'); await page.tracing.stop(); await browser.close(); })(); And then load trace.json file in Chrome Performance tab. If you want

How to listen to history.pushstate with Puppeteer?

。_饼干妹妹 提交于 2020-12-09 16:25:47
问题 Using Puppeteer, is it possible to listen to the browser history API such as history.pushState , history.replaceState or history.popState , often used under the hood by single page application frameworks routers, like react-router , to navigate back and fourth through views? I'm not looking for page.waitForNavigation(options) , as it's not really navigating in the literal sense of the word, and is not a listener. Moreover, I would like to be able to capture the arguments passed to history