Puppeteer

puppeteer踩坑记录

ⅰ亾dé卋堺 提交于 2019-12-05 00:09:56
错误代码1: error while loading shared libraries: libXcomposite.so.1: cannot open shared 解决方案: 在项目Chrome所在的目录例如: /home/code/puppeteer/node_modules/puppeteer/.local-chromium/linux-706915/chrome-linux/ 中运行 ldd chrome | grep not 依赖库 yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y 错误代码2: Running as root without --no-sandbox is not supported. 解决方案: 在puppeteer的launch中设置 puppeteer.launch({ args: ['--no-sandbox', '-

Trouble Logging In To Google with Headless Chrome / Puppeteer

别等时光非礼了梦想. 提交于 2019-12-04 14:06:57
I'm trying to automate certain tasks for work. We have a portal that requires you to sign in through Google. I've created a Puppeteer instance that navigates to the Google auth page, types in my email and password, then stores the cookies so I can navigate through and manipulate the portal. This works perfectly on my local environment, but I've deployed it to Heroku and Google adds a sign in challenge. After entering the password, I'm given the 'Verify it's you' page that says 'This device isn't recognized' and asks me to complete 2-FA auth. I know I can't turn off 2-FA, so what would be the

Adding fonts to Puppeteer PDF renderer

半世苍凉 提交于 2019-12-04 13:17:29
问题 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

attach to previously opened puppeteer driver

牧云@^-^@ 提交于 2019-12-04 11:36:38
Is it possible to reattach to an existing puppeteer ? open puppeteer chrome browser. node script ends without closing browser. new script attaches and continue with the same browser. elena For those who stumble upon this, here's an example of how I've got it working: const puppeteer = require('puppeteer'); puppeteer.connect({"browserWSEndpoint" : "ws://some_string"}).then(async browser => { console.log("bla bla"); ... }); The browser.wsEndpoint you can find from the previous session: const endpoint = browser.wsEndpoint(); Browser websocket endpoint which can be used as an argument to puppeteer

详解Puppeteer前端自动化测试实践

雨燕双飞 提交于 2019-12-04 08:13:50
详解Puppeteer前端自动化测试实践 起因 目前我们在持续开发着一个几十个页面,十万+行代码的项目,随着产品的更迭,总会出现这样的问题。在对某些业务逻辑或者功能进行添加或者修改的时候(尤其是通用逻辑),这些通用的逻辑或者组件往往会牵扯到一些其他地方的问题。由于测试人员受限,我们很难在完成一个模块单元后,对所有功能重新测试一遍。 同时,由于环境及数据的区别,(以及在开发过程中对代码完备性的疏忽),代码会在某些特殊数据的解析和和展示上出现问题,在开发和测试中很难去发现。总的来说,我们希望有一个这样的工具,帮我们解决上述几个问题: 在进行代码和功能改动后,能够自动访问各个功能的页面,检测问题 针对大量的数据内容,进行批量访问,检测对于不同数据的展示是否存在问题 测试与代码功能尽量不耦合,避免每次上新功能都需要对测试用例进行修改,维护成本太大 定期的测试任务,及时发现数据平台针对新数据的展示完备性 其中,最重要的问题,就是将测试代码与功能解耦,避免每次迭代和修改都需要追加新的测试用例。我们如何做到这一点呢?首先我们来梳理下测试平台的功能。 功能设定 由于我们的平台主要是进行数据展示,所以我们在测试过程中,主要以日常的展示数据为重心即可,针对一些复杂的表单操作先不予处理。针对上述的几个问题,我们针对自动化测试工具的功能如下: 依次访问各个页面 访问各个页面的具体内容,如时间切换

Is there a way to add script to add new functions in evaluate() context of chrome+puppeeter?

放肆的年华 提交于 2019-12-04 05:06:55
问题 Based on this response, is there a way (like with casperjs/phantomjs) to add our custom functions in page.evaluate() context ? By example, include a file with a helper function x to call an Xpath function : x('//a/@href') 回答1: You can register helper functions in separate page.evaluate() function. page.exposeFunction() looks temptingly, but it don't have access to browser context (and you need document object). Here is an example of registering helper function with $x() : const puppeteer =

Communicating between the main and renderer function in Puppeteer

十年热恋 提交于 2019-12-04 04:35:20
问题 Is there a way to communicate between the main and renderer process in Puppeteer similar to the ipcMain and ipcRenderer functions in Electron. A simple application is demonstrated in this post. I find this functionality can be useful for debugging by triggering event from the page to the main function and vice-versa. 回答1: Debugging: - Puppeteer has various page events used for debugging purpose here. - Puppeteer recently added ASYNC stack trace so you can track errors more precisely. Event

How to delete existing text from input using Puppeteer?

左心房为你撑大大i 提交于 2019-12-04 00:54:37
I'm trying to test amending text in an editable input which contains the title of the current record - and I want to able to test editing such text, replacing it with something else. I know I can use await page.type('#inputID', 'blah'); to insert "blah" into the textbox (which in my case, having existing text, only appends "blah"), however, I cannot find any page methods 1 that allow deleting or replacing existing text. You can use page.evaluate to manipulate DOM as you see fit: await page.evaluate( () => document.getElementById("inputID").value = "") However sometimes just manipulating a

Bypassing CAPTCHAs with Headless Chrome using puppeteer

筅森魡賤 提交于 2019-12-03 22:44:17
问题 google finds my browser is being manipulated/controlled/automated by software, and because of that I get captchas . I start chromium manually and do the same steps the captchas doesn't appear. Question 1) Is it possible to solve captcha Programmatically or get rid of it when using puppeteer ? Any way to solve this? Question 2) Does this happens only when without headless option i.e const browser = await puppeteer.launch({ headless: false }) OR this is something the fact we have to accept and

Refresh when an element changes on page

大城市里の小女人 提交于 2019-12-03 21:26:16
I try to scrap an element on a website and display it on localhost with Puppeteer (1). But when this element changes, I would like to refresh data without opening a new browser/page with Puppeteer and only when element changes (2). For my example, I use www.timeanddate.com and the element is time (hours and minutes). For moment, only first part works. I don't have solution for second one. Please find below, my code. app.js var app = require('express')(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); var puppeteer = require('puppeteer'); app.get('