How to modify the first pageNumber or execute JS in header or footer template with Chrome DevTools Protocol’s printToPDF

I tried straight forward approaches to solve this problem and they didn’t work. Even obscure apis like CSS expressions and counters don’t work to solve this. Fortunately there seems to be a simple enough work around. We print each page separately using the pageRange parameter and then combine all the pages to generate the required … Read more

Puppeteer – Protocol error (Page.navigate): Target closed

What “Target closed” means When you launch a browser via puppeteer.launch it will start a browser and connect to it. From there on any function you execute on your opened browser (like page.goto) will be send via the Chrome DevTools Protocol to the browser. A target means a tab in this context. The Target closed … Read more

How do I use Headless Chrome in Chrome 60 on Windows 10?

This works for me: start chrome –enable-logging –headless –disable-gpu –print-to-pdf=c:\misc\output.pdf https://www.google.com/ … but only with “start chrome” and “–enable-logging” and with a path (for the pdf) specified – and if the folder “misc” exists on the c-directory. Addition: … the path for the pdf – “c:\misc” above – can of course be replaced with any … Read more

Puppeteer: How to submit a form?

If you are attempting to fill out and submit a login form, you can use the following: await page.goto(‘https://www.example.com/login’); await page.type(‘#username’, ‘username’); await page.type(‘#password’, ‘password’); await page.click(‘#submit’); await page.waitForNavigation(); console.log(‘New Page URL:’, page.url());

Is it possible to run Google Chrome in headless mode with extensions?

You can run Chrome with extensions headless using Xvfb. Install Xvfb. On Fedora sudo dnf install xorg-x11-server-Xvfb xvfb-run google-chrome –remote-debugging-port=9222 –disable-gpu https://www.google.com Use chrome-remote-interface (or another Chrome Debug Protocol client) to trigger the screenshot. More complicated, but it does work. It’s what we use for headless chrome extension testing.

Downloading with chrome headless and selenium

Yes, it’s a “feature”, for security. As mentioned before here is the bug discussion: https://bugs.chromium.org/p/chromium/issues/detail?id=696481 Support was added in chrome version 62.0.3196.0 or above to enable downloading. Here is a python implementation. I had to add the command to the chromedriver commands. I will try to submit a PR so it is included in the … Read more

Puppeteer wait until page is completely loaded

You can use page.waitForNavigation() to wait for the new page to load completely before generating a PDF: await page.goto(fullUrl, { waitUntil: ‘networkidle0’, }); await page.type(‘#username’, ‘scott’); await page.type(‘#password’, ‘tiger’); await page.click(‘#Login_Button’); await page.waitForNavigation({ waitUntil: ‘networkidle0’, }); await page.pdf({ path: outputFileName, displayHeaderFooter: true, headerTemplate: ”, footerTemplate: ”, printBackground: true, format: ‘A4’, }); If there is a … Read more

Running Selenium with Headless Chrome Webdriver

To run chrome-headless just add –headless via chrome_options.add_argument, i.e.: from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() #chrome_options.add_argument(“–disable-extensions”) #chrome_options.add_argument(“–disable-gpu”) #chrome_options.add_argument(“–no-sandbox”) # linux only chrome_options.add_argument(“–headless”) # chrome_options.headless = True # also works driver = webdriver.Chrome(options=chrome_options) start_url = “https://duckgo.com” driver.get(start_url) print(driver.page_source.encode(“utf-8”)) # b'<!DOCTYPE html><html xmlns=”http://www…. driver.quit() So my thought is that running it with … Read more

How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?

It should look like this: from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument(‘–headless’) options.add_argument(‘–disable-gpu’) # Last I checked this was necessary. driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options) This works for me using Python 3.6, I’m sure it’ll work for 2.7 too. Update 2018-10-26: These days you can just do this: from selenium import … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)