How to access PDF from headless chrome browser - google-chrome

I am trying to access a pdf from a headless chrome browser.
Below is the command I am trying to hit from the command prompt(Administrator). I can see the pdf file gets generated. However, I can not see any data coming up in the pdf.
The URL in the below command needs a password to access when I open it on the browser. It will really be a great help if you can let me know if I do need to use username, password (If yes then how and whats the command).Many thanks!!
"%chrome%" --headless --disable-gpu --print-to-pdf="C:\Users\i077219\Desktop\temp3.pdf "https://**ipaddress**/s/opu/odata/sp/CA_OC_OUTPUT_REQUEST_SRV/Items(ApplObjectType='BILLING_DOCUMENT',ApplObjectId='0090004410',ItemId='1')/GetDocument/$value/

Related

chrome headless mode run in batch mode

I am trying to convert a series of html files to pdfs and then send the generated pdf file. However, if i start headless chrome like
...chrome.exe --headless --disable-gpu --print-to-pdf=file01.pdf source01.html
The chrome process exits immediately even though it could take some time before the pdf is generated. Is there a way or flag to instruct chrome.exe to wait for the pdf to be saved before exiting?
p.s.
Is there also a way to see html/js erros on the page?
p.p.s
I have given the simplest example.
What I actually run has
--run-all-compositor-stages-before-draw
--virtual-time-budget=10000 # Need to render some stuff first
--enable-logging

Take a screenshot of page using Chrome --headless + cookies/oauth token

I've found, that it's possible to take a page screenshot easily - https://superuser.com/questions/1410641/how-to-take-screenshots-of-a-list-of-urls - by calling:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --enable-logging --screenshot="C:\path\to\screenshot.png" http://example.com/
However it's starting new Chrome process, which results that I'm able to take a screenshots of simple pages, but what with pages, with authentication (like Oauth2)?
Can I somehow fore chrome, to use already existing "session" of browser, where I'm logged in to interested page, that I'm about to take a screenshot OR to pass oauth2 token or even cookie, somehow?

How to open chrome://inspect devices using command prompt

I want to open chrome://inspect from windows command prompt.
Here my use case is I want to open the chrome browser from command prompt(using ProcessBuilder in java) and chrome://inspect link so i can see the devices attached to my system
so i tried opening chrome://inspect using this command
start chrome chrome://inspect which is not working
if I replace chrome://inspect with any url it's working.
Can any one let me know how to do this from command prompt or any other possible ways to do this
Chrome URLs can't be opened from the command line. They must be typed by a user into the omnibar.

Open URL in Chrome & save its source code using Command prompt

I am having a hard time to find how to save the page as html or .txt using command line in Chrome Browser,
This is what I've done so far,
C:\Users\Cipher\AppData\Local\Google\Chrome\Application>chrome.exe --new-window
http://google.com
This command will open a new window of Chrome browser and visit google.com but i couldn't be able to figure our how can i save google.com as html or as txt file ,
is there anyway to do so using command prompt ?
You cannot perform the task you describe manually, but you can perform it using WebDriver automation.
Chrome can be remote controlled using an API called WebDriver (part of Selenium 2 automating suite). WebDrive has bindings for various programming languages, including e.g. JavaScript and Python.
Here is example code for Python (not tested):
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
html = driver.page_source
f = open("myhtml", "wt")
f.write(html)
f.close()
Orignal example
Do you really need to open Google Chrome? You can get the page source using Wget (available for UNIX systems or for Windows in this post on SuperUser). Once installed, just use the following command:
wget http://google.com -O yourfilename.html
And this should be all :) I don't think there's a way to tell Chrome to download the HTML from the command line though :(
UPDATE: There's a repo on GitHub called chrome-cli that allows the user to control Chrome from the command line. Downside is that it only works on Mac OS X.
I created a small script to do perform exactly this task: https://github.com/abiyani/automate-save-page-as . See the demo gif in the README.
It automates the keyboard actions you would otherwise perform to save the page manually (literally sends those key signals to OS). As a side effect of it being used in another project of mine, it's been tested on various linux flavors: Ubuntu, Mint, Fedora, etc - and works fine on all of them. It probably won't work (at least without modifications) on Mac, and certainly not on Windows.
This should work :
cd c:\Program Files (x86)\Google\Chrome\Application
c:\Program Files (x86)\Google\Chrome\Application>chrome.exe --headless --dump-dom --enable-logging --disable-gpu https://www.google.com >c:\yourpath\yourfile.html

Launch Portable Google Chrome with supplied parameters from flash drive on Mac OSX

As the title suggests, I want to write a shell command to open google chrome portable (with supplied parameter) which is installed on the flash drive also. I am trying to do it as follows:
open "/Volumes/NDCS/chrome/chromium.app/Contents/MacOS/Portable Chromium" --allow-file-access-from-files
Portable Chrome opens up, but the setting hasn't worked. I also wanted it to launch a default homepage (parameter is --homepage="[url or file path]", but for now have done that by setting the default homepage in the browser.
If anyone has any knowledge/advice on this, would be much appreciated. I have done the same scenario on PC recently, just struggling with the Mac deployment.
From man open you need to supply thr parameters to the executable using the --args argument, otherwise they are taken as arguments to open not the app.
Also Open works on the App bundle
So
open "/Volumes/NDCS/chrome/chromium.app" --args --allow-file-access-from-files
oruse the plain unix executable as you are doinf without the open
"/Volumes/NDCS/chrome/chromium.app/Contents/MacOS/Portable Chromium" --allow-file-access-from-files