google-chrome-headless

Passing a thunk to puppeteer's $.eval

时光怂恿深爱的人放手 提交于 2021-02-19 02:39:29
问题 The function setValue receives a value and returns a function. Inside the second function I'm trying to console log the value of value but I get Error: Evaluation failed: ReferenceError: value is not defined My code bellow. It can be tested on try-puppeteer, just copy and paste my code and remove the require statement. const puppeteer = require('puppeteer'); (async () => { const USERNAME = 'helloworld'; const setValue = (value) => (input) => { console.log(value) }; const browser = await

Getting DOM node text with Puppeteer and headless Chrome

主宰稳场 提交于 2021-02-18 10:15:51
问题 I'm trying to use headless Chrome and Puppeteer to run our Javascript tests, but I can't extract the results from the page. Based on this answer, it looks like I should use page.evaluate(). That section even has an example that looks like what I need. const bodyHandle = await page.$('body'); const html = await page.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose(); As a full example, I tried to convert that to a script that will extract my name from my user profile on

Getting DOM node text with Puppeteer and headless Chrome

£可爱£侵袭症+ 提交于 2021-02-18 10:15:30
问题 I'm trying to use headless Chrome and Puppeteer to run our Javascript tests, but I can't extract the results from the page. Based on this answer, it looks like I should use page.evaluate(). That section even has an example that looks like what I need. const bodyHandle = await page.$('body'); const html = await page.evaluate(body => body.innerHTML, bodyHandle); await bodyHandle.dispose(); As a full example, I tried to convert that to a script that will extract my name from my user profile on

Why local chrome-urls like: chrome://downloads or chrome://apps doesn't work in headless mode?

淺唱寂寞╮ 提交于 2021-02-17 03:30:32
问题 I am trying to visit chrome local urls. But it's not working. Does headless chrome support local urls? 回答1: I was looking for exactly this just today. Found this: Most chrome internal pages are not implemented in headless mode. This is a limitation of headless Chrome itself, and is not related to ChromeDriver. If you need a particular internal page available in headless Chrome, please file a feature request at https://crbug.com/. :( citation 来源: https://stackoverflow.com/questions/57004031

Why local chrome-urls like: chrome://downloads or chrome://apps doesn't work in headless mode?

落爺英雄遲暮 提交于 2021-02-17 03:28:25
问题 I am trying to visit chrome local urls. But it's not working. Does headless chrome support local urls? 回答1: I was looking for exactly this just today. Found this: Most chrome internal pages are not implemented in headless mode. This is a limitation of headless Chrome itself, and is not related to ChromeDriver. If you need a particular internal page available in headless Chrome, please file a feature request at https://crbug.com/. :( citation 来源: https://stackoverflow.com/questions/57004031

How to print a webpage with all click-to-expand contents?

六月ゝ 毕业季﹏ 提交于 2021-02-11 17:51:06
问题 I'm using print-to-pdf option in headless chrome (or chromehtml2pdf ) to print this page to PDF. It's unfortunate that this page has some click-to-expand contents. For example, Here is when we click the triangle to open To expand all of these hidden contents, we can click to the plus symbol at the top right side I would like to ask if there is any way to print the webpage as well as click-to-expand contents. Thank you so much for your help! 来源: https://stackoverflow.com/questions/61900799/how

Double Click does not work with headless Selenium in Python

ⅰ亾dé卋堺 提交于 2021-02-10 08:02:56
问题 Im trying to double click on a selected element on a website using selenium in headless mode, however the double click action does not work. My chrome version is 72. Any help would be greatly appreciated. Below is the relevant portion of my code. element = driver.find_element_by_id('player-forpost-html5').click() time.sleep(5) action = ActionChains(driver) element_1 = driver.find_element_by_id('player-forpost-html5') action.move_to_element(element_1) action.double_click(element_1) action

Double Click does not work with headless Selenium in Python

时光毁灭记忆、已成空白 提交于 2021-02-10 08:02:22
问题 Im trying to double click on a selected element on a website using selenium in headless mode, however the double click action does not work. My chrome version is 72. Any help would be greatly appreciated. Below is the relevant portion of my code. element = driver.find_element_by_id('player-forpost-html5').click() time.sleep(5) action = ActionChains(driver) element_1 = driver.find_element_by_id('player-forpost-html5') action.move_to_element(element_1) action.double_click(element_1) action

Headless Google Chrome: How to prevent sites to know whether their window is focused or not

橙三吉。 提交于 2021-02-07 20:31:39
问题 Is there a way to prevent sites to know if they are visible or not? Perhaps a command line flag? I checked here but I could not find anything suitable https://peter.sh/experiments/chromium-command-line-switches/. I think they use the page visibility API: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API 回答1: If your goal is to fool the visibility API, then inject this piece of script in the related page or frame: await page.evaluate(` Object.defineProperty(window.document,

Crawling multiple URL in a loop using puppeteer

对着背影说爱祢 提交于 2021-02-05 21:34:44
问题 I have urls = ['url','url','url'...] this is what I'm doing urls.map(async (url)=>{ await page.goto(url); await page.waitForNavigation({ waitUntil: 'networkidle' }); }) This seems to not wait for page load and visit all the urls quite rapidly(i even tried using page.waitFor ) just wanted to know am I doing something fundamentally wrong or this type of functionality is not advised/supported 回答1: map , forEach , reduce , etc, does not wait for the asynchronous operation within them, before they