Puppeteer

How to pass a function in Puppeteers .evaluate() method?

六眼飞鱼酱① 提交于 2020-04-28 00:09:51
问题 Whenever I try to pass a function, like this: var myFunc = function() { console.log("lol"); }; await page.evaluate(func => { func(); return true; }, myFunc); I get: (node:13108) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: TypeError: func is not a function at func (<anonymous>:9:9) (node:13108) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the

How can I dynamically inject functions to evaluate using Puppeteer?

[亡魂溺海] 提交于 2020-04-27 18:44:35
问题 I am using Puppeteer for headless Chrome. I wish to evaluate a function inside the page that uses parts of other functions, defined dynamically elsewhere. The code below is a minimal example / proof. In reality functionToInject() and otherFunctionToInject() are more complex and require the pages DOM. const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(someURL); var functionToInject = function(){ return 1+1; } var otherFunctionToInject = function

How can I dynamically inject functions to evaluate using Puppeteer?

二次信任 提交于 2020-04-27 18:29:33
问题 I am using Puppeteer for headless Chrome. I wish to evaluate a function inside the page that uses parts of other functions, defined dynamically elsewhere. The code below is a minimal example / proof. In reality functionToInject() and otherFunctionToInject() are more complex and require the pages DOM. const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(someURL); var functionToInject = function(){ return 1+1; } var otherFunctionToInject = function

How Set cookie from array of objects using loop

a 夏天 提交于 2020-04-17 20:38:34
问题 I want to set cookies from data in my cookie.json file. Right now I have 2 objects in my cookies collection. I want to get each object by incrementing the value of [i], so I can set each cookie at a time. var cookie = JSON.parse(fs.readFileSync('cookies.json', 'utf8')); for(var i = 0; i < cookie.length; i++) { await page.setCookie(...cookie[i]) //this line is not working, cookies is not writting 来源: https://stackoverflow.com/questions/60845736/how-set-cookie-from-array-of-objects-using-loop

Can't log in through Facebook using Puppeteer - Error: Cookies required

。_饼干妹妹 提交于 2020-04-17 20:23:48
问题 This is my code to login using facebook to a website I'm automating: const loginButton = await page.waitForXPath( "//button[contains(@name, 'login')]" ); const email = await page.waitForSelector("#email"); const pass = await page.waitForSelector("#pass"); await page.evaluate((text) => { email.value = text; }, "my email"); await page.evaluate((text) => { pass.value = text; }, "my password"); await loginButton.click(); Usually it works well, but once every 4 or 5 times, I get the following

Can't log in through Facebook using Puppeteer - Error: Cookies required

蹲街弑〆低调 提交于 2020-04-17 20:21:47
问题 This is my code to login using facebook to a website I'm automating: const loginButton = await page.waitForXPath( "//button[contains(@name, 'login')]" ); const email = await page.waitForSelector("#email"); const pass = await page.waitForSelector("#pass"); await page.evaluate((text) => { email.value = text; }, "my email"); await page.evaluate((text) => { pass.value = text; }, "my password"); await loginButton.click(); Usually it works well, but once every 4 or 5 times, I get the following

Can't log in through Facebook using Puppeteer - Error: Cookies required

蹲街弑〆低调 提交于 2020-04-17 20:18:34
问题 This is my code to login using facebook to a website I'm automating: const loginButton = await page.waitForXPath( "//button[contains(@name, 'login')]" ); const email = await page.waitForSelector("#email"); const pass = await page.waitForSelector("#pass"); await page.evaluate((text) => { email.value = text; }, "my email"); await page.evaluate((text) => { pass.value = text; }, "my password"); await loginButton.click(); Usually it works well, but once every 4 or 5 times, I get the following

Can't log in through Facebook using Puppeteer - Error: Cookies required

百般思念 提交于 2020-04-17 20:15:36
问题 This is my code to login using facebook to a website I'm automating: const loginButton = await page.waitForXPath( "//button[contains(@name, 'login')]" ); const email = await page.waitForSelector("#email"); const pass = await page.waitForSelector("#pass"); await page.evaluate((text) => { email.value = text; }, "my email"); await page.evaluate((text) => { pass.value = text; }, "my password"); await loginButton.click(); Usually it works well, but once every 4 or 5 times, I get the following

TypeScript - Puppeteer library error: “Cannot find name 'Element'”

给你一囗甜甜゛ 提交于 2020-04-17 04:31:05
问题 I have included puppeteer-core as a dependency in my TypeScript project, and am using Visual Studio 2019. When I try to build the project, I get this error below (as shown by the red squiggly underline under Element ): error TS2304: Build:Cannot find name 'Element' How can I resolve this please? 回答1: Adding dom to my tsconfig.json got rid of the issue: { "compilerOptions": { "lib": [ "es2018", "dom" ] } } 来源: https://stackoverflow.com/questions/57999416/typescript-puppeteer-library-error

Puppeteer cors mistake

强颜欢笑 提交于 2020-04-16 03:05:10
问题 hello i have problem in my code using puppeteer, cors error happens randomly but in 80% of my tests. Here is my code thanks for help.Btw the server respond is Access to fetch at 'https://secure-store.nike.com/eu/services/jcartService/?action=addItem&rt=json&country=GB&region=eu&lang_locale=en_GB&catalogId=1&productId=12238990&qty=1&skuId=21502246' from origin 'https://www.nike.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.