Puppeteer

Can we somehow rename the file that is being downloaded using puppeteer?

£可爱£侵袭症+ 提交于 2019-12-03 18:14:00
问题 I am downloading a file through puppeteer into my directory. I need to upload this file to an s3 bucket so I need to pick up the file name. But the problem is, this file name has a time stamp that changes every time so I can't keep a hard coded name. So is there a way around this to get a constant name every time (even if the old file is replaced), or how to rename the file being downloaded? I thought of using node's fs.rename() function but that would again require the current file name. I

Adding fonts to Puppeteer PDF renderer

瘦欲@ 提交于 2019-12-03 16:42:58
Background I am using Puppeteer in an express application that is running in a Docker image. It is necessary for us to run in Docker because of needed dependencies that Debian needs which we do not have access to install. Using Docker allows us to install what we need. We have seen a lot of people have problems getting their fonts to render in the PDFs correctly and in every case I have seen, installing the font in a way close to this is always the answer, apt-get install -yq --allow-unauthenticated ttf-mscorefonts-installer In that case they are installing specific fonts that there happens to

Rendering WebGL image in headless chrome without a GPU

天涯浪子 提交于 2019-12-03 14:46:48
问题 I'm trying to export an image rendered with WebGL on a linux server without a GPU. To do this I'm using headless Chrome however the exported image is black (example exported image, taking a screenshot of page shows its just canvas that is black). I was hoping for some help figuring out why this is happening. To export the image I render the image into a canvas, export data via canvas.toDataURL('image/jpeg') and then post the data to the server. I'm using Pixi.js for rendering, if I use canvas

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

不问归期 提交于 2019-12-03 14:28:38
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 puppeteer.launch(); const page = await browser.newPage(); var functionToInject = function(){ return window.navigator.appName; } await page.exposeFunction('functionToInject', functionToInject); var data = await page.evaluate(async function(){ console.log('woo I run inside a browser') return await functionToInject(); }); console.log(data); await browser.close(); })() This fails

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

回眸只為那壹抹淺笑 提交于 2019-12-03 13:08:14
问题 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 recommended settings/limits on parallel processes? (In my tests, (1) seems to work fine, but I'm wondering about the reliability of Puppeteer's interactions with the single (?) instance of Chrome. I haven't tried (2) but that seems less likely to work out.)

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 12:41:02
问题 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 than half the screen with scroll bars. How can I make it take up a full screen? const puppeteer = require('puppeteer'); async function test(){ const browser = await puppeteer.launch({ headless: false, }); const page = await browser.newPage(); await

puppeteer : how can i wait for ajax request and process the result

穿精又带淫゛_ 提交于 2019-12-03 07:46:35
so i open a website , waith for all redirects to be done capture captcha image and send it vie nodejs to a user an recive the typed captcha const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); await page.goto('http://localhost/p1.php' ); await page.waitForNavigation(); const captcha_image = await page.$eval('#security', e => e.getAttribute('src')); io.emit('send_captcha_to_client' , {text : captcha_image }); var captcha = await captchaPromise; after i reciv the typed value of capthca i put it in the field and click the login button await page.$eval('

Websocket communication with multiple Chrome Docker containers

南笙酒味 提交于 2019-12-03 07:25:07
问题 I have a Chrome container (deployed using this Dockerfile) that renders pages on request from an App container. The basic flow is: App sends an http request to Chrome and in response receives a websocket url to use (e.g. ws://chrome.example.com:9222/devtools/browser/13400ef6-648b-4618-8e4c-b5c73db2a122 ) App then uses that websocket url to communicate further with Chrome, and to receive the rendered page. I am using the puppeteer library to connect to and communicate with the Chrome instance,

Detect and test Chrome Extension using Puppeteer

[亡魂溺海] 提交于 2019-12-03 05:10:32
问题 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? 回答1: Passing --user-agent in puppeteer.launch() is a useful way to override the browser's UA with a custom value. Then, your extension can read back navigator.userAgent in its background page and identify that Chrome was launched with Puppeteer. At that point, you can provide different code paths

Puppeteer: How to submit a form?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 04:52:21
Using puppeteer , how could you programmatically submit a form? So far I've been able to do this using page.click('.input[type="submit"]') if the form actually includes a submit input. But for forms that don't include a submit input, focusing on the form text input element and using page.press('Enter') doesn't seem to actually cause the form to submit: const puppeteer = require('puppeteer'); (async() => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://stackoverflow.com/', {waitUntil: 'load'}); console.log(page.url()); // Type our query