Why doesn't Chromium headless dump the DOM when I tell it to? - google-chrome

Here's exactly what I did:
I went to https://download-chromium.appspot.com/ and clicked the button.
I ran the file (oddly called chrome-win.exe instead of Chromium.exe).
I went to its install directory and opened a cmd.exe in there.
I ran the command:
chrome.exe --headless --dump-dom "https://www.example.com/"
According to the manual, this is supposed to open that URL headlessly and dump the DOM as text after JavaScript has been executed, to the stdout, meaning the cmd.exe in this case.
Problem: Nothing happens. Literally no output at all. The only thing that I can tell that happens (and that was just out of pure coincidence) is that a file called chrome_debug.txt is created in the same directory, with this contents:
[0712/065333.417:ERROR:browser_process_sub_thread.cc(203)] Waited 5 ms for network service
If I instead run the command:
chrome.exe "https://www.example.com/"
It opens the browser and goes to that URL (as expected). So it's not something fundamentally wrong with my Internet connection or computer.
What am I doing wrong?

You might want to try to enable logging by adding the --enable-logging flag to the command line.
Also, although according to this bug report this is no longer necessary, it may be wise to add the --disable-gpu flag to prevent GPU errors from showing in the stdout.
The final command line should look like this:
chrome.exe --headless --enable-logging --disable-gpu --dump-dom "https://www.example.com/""
which returns the DOM of www.example.com/ on chromium 76.0.3809.87 succesfully.

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

Chrome 49 plus --disable-web-security

Today (Mar, 15, 2016) chrome stopped working with the --disable-web-security flag. I have tried the following options described in various posts:
1) Kill all instances of Chrome.exe in the windows task manager.
2) add the --use-data-dir flag, there is a current post regarding this, but the answers there do not work anymore
Here is my script I am using:
start chrome.exe --disable-web-security --allow-running-insecure-content --use-data-dir=c:/temp/chrome_dev
Chrome opens under this script with the disable security warning but localhost cross domain calls still fail:
I have solutions that are using --disable-web-security.
Finally I found solution. Now chrome just will accept it if you set --user-data-dir together.
You will have different instances when you use it.
Try it:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="D:\chrome"
For linux
google-chrome --user-data-dir=”/var/tmp/Chrome” --disable-web-security
I suggest a temp directory
Just for OS X user, this worked for me (on El Capitan): /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --user-data-dir="<some-dir>"
Also works on Yosemite 10.10.5. Please note that --user-data-dir may no longer be left empty. You have to specify some dir.
This doesn't work anymore, since Chrome 80. You have to specify a non-default --user-data-dir to make it work now.
Original answer:
You can use your existing data dir, if you don't want to create a new one.
So on Linux the command to start unsafe Chrome will be something like this:
google-chrome --user-data-dir=/home/<your username>/.config/google-chrome --disable-web-security
But don't use this Chrome instance for anything except development or debugging, since it's open for a vast amount of web attacks.
This works with chrome 61 too for me -
chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
Update: I have found a permanent solution for this disable web security issue.
step 1: create 1 chrome app shortcut on desktop and rename it anything like "disabled-security.exe"
step 2: right click on icon and go to properties => change target input box to something like following eg. and save it.
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-site-isolation-trials --user-data-dir=c:\chromeSession
step 3: launch this app, it will work fine as expected
Note: everytime you need to clear folder "c:\chromeSession" before opening this app
Do not disable web security. You're opening your accounts to attacks and your local files to being stolen.
Instead use a simple web server. It will take you all of 2 minutes to install and use. Here's one with a gui, and here's several more that run from the command-line

How to load-and-launch a Google Chrome App from the command line?

At this link, it says:
These command line options to Chrome may help you iterate:
--load-and-launch-app=/path/to/app/ installs the unpacked application from the given path, and launches it.
What is the entire command line statement?
For example, is it:
$ chrome --load-and-launch-app=/path/to/app/
or maybe:
$ cca --load-and-launch-app=/path/to/app/
What, specifically, is the entire command?
The basic command you have correct
/Path/to/Chrome --load-and-launch-app=/Path/to/App
Assuming you are using Mac, OSX(from your comments) and you installed Google Chrome the normal way, (into your Applications directory), your /Path/to/Chrome will be
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
But to make sure you can your Google Chrome Application directly into your terminal (assuming standard MacOSX terminal or iTerm)
For the /Path/To/App part of the command, use the directory which contains the manifest.json file.
For instance, if your path to the manifest.json file is
/Users/[Your Username]/Downloads/basic/manifest.json
which you can get from going to this link
Your command to load and launch the "Basic" google chrome app is
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --load-and-launch-app=/Users/[Your Username]/Downloads/basic
One additional detail that may be helpful: the path to your app must be an absolute path, beginning at the root directory (/).
You have to do --load-and-launch-app=/Users/YourUsername/Documents/my_chrome_app
Alternately, if you don't want to type the whole path, you could use $PWD, which evaluates to your current directory (must execute the command from the same directory as your manifest.json):
--load-and-launch-app=$PWD
You cannot do --load-and-launch-app=.
You cannot do --load-and-launch-app=~/Documents/my_chrome_app

Open google chrome (all users installation) in kiosk mode from terminal

I execute this in order to open Google chrome in kiosk mode:
"C:\Users\Javier\AppData\Local\Google\Chrome\Application\chrome.exe" --user-data-dir=$(mktemp -d) --kiosk "url"
but, what I need to modify if google chrome is installed in Program Files(x86)? If I execute:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --user-data-dir=$(mktemp -d) --kiosk "url"
I get an error in --user-data-dir=$(mktemp -d) sentence.
Thanks in advance.
Javier
I think there may be no elegant solution at this point. "mktemp -d" is a linux/unix command and I can't find it, or an equivalent, on windows. It may have worked at one time (I stumbled on mktemp on a microsoft development page), but on 8.1 it didn't. The error I was getting said it had to do with permissions, but that wasn't the case.
If someone could get commands in Cygwin working at the windows command prompt then maybe the above would work. Another option may be to create something for PowerShell that does the same and plug that in there.
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:\somedir --kiosk "some.url.here" does work though. It works from a shortcut, so it should also work from the command line, but you do lose the random temp directory.
For my case, I just wanted some websites/web-apps to default full screen (F11) from a shortcut and I'd just Alt-F4 to close, and Alt-Tab between them and the desktop. As it is, I'm thinking I'll have to make a separate data-dir for each one I want to do.
I was using the command chrome.exe --user-data-dir=$(mktemp -d) --kiosk http://someUrl/ and it was working well for over a week until I started testing my program with a limited privilege user today. I noticed that chrome process itself did not start after calling process.start() method. There were no entries in event logs to see what went wrong. After looking at your solution, I changed my program to generate a temp folder using C# command pass it as an argument and it started working. Thanks for the help. This is the simplified version of the code I use.
DirectoryInfo tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "Chrome" + DateTime.Now.ToString("ddMMHHmmss")));
Process process = new Process();
process.StartInfo.FileName = GetBrowserPathFromRegistry();
process.StartInfo.Arguments = String.Format("--user-data-dir={0} --kiosk {1}", tempDirectory.FullName, this.uri);
process.Start();

Does --disable-web-security work in Chrome?

I'm trying to do a simple test without changing any server-side code involving a cross-domain AJAX call, and I was wondering if it's possible to use --disable-web-security anymore. It seems to not work on Chrome 28.
I haven't used it since Chrome version 21; has this feature been dropped?
Check your windows task manager and make sure you kill all chrome processes before running the command.
The new tag for recent Chrome and Chromium browsers is :
--disable-web-security --user-data-dir=c:\my\data
Try this :
Windows:
Run below commands in CMD to start a new instance of chrome browser with disabled security
Go to Chrome folder:
cd C:\Program Files (x86)\Google\Chrome\Application
Run below command:
chrome.exe --disable-web-security --user-data-dir=c:\my-chrome-data\data
MAC OS:
Run this command in terminal:
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_sess_1" --disable-web-security
Hope this will help both Windows & Mac users!
This flag worked for me at v30.0.1599.101 m
The warning "You are using an unsupported command-line flag" can be ignored. The flag still works (as of Chrome v86).
This should work. You may save the following in a batch file:
TASKKILL /F /IM chrome.exe
start chrome.exe --args --disable-web-security
pause
Open target location of chrome and navigate through cmd
type
chrome.exe --disable-web-security --user-data-dir=c:\my\dat
Just create this batch file and run it on windows. It basically would kill all chrome instances and then would start chrome with disabling security. Save the following script in batch file say ***.bat and double click on it.
TASKKILL /F /IM chrome.exe
start chrome.exe --args --disable-web-security –-allow-file-access-from-files
Check if you have Chrome App Launcher. You can usually see it in your toolbar. It runs as a second instance of chrome, but unlike the browser, it auto-runs so is going to be running whenever you start your PC. Even though it isn't a browser view, it is a chrome instance which is enough to prevent your arguments from taking effect. Go to your task manager and you will probably have to kill 2 chrome processes.
As you can't run --disable-web-security and a normal chrome in parallel it's probably a good solution to use Opera for --disable-web-security
Here is how to create a launcher for opera on windows. By the way, Opera has the same debugging tools as chrome!
http://www.opera.com/
:: opera-browse-dangerously.bat
cd c:\Program Files\Opera\
launcher.exe --disable-web-security --user-data-dir="c:\opera-dev"
PS: Opera doesn't display any notification when started without web-security
If you want to automate this:
Kill chrome from task Manager First. In Windows - Right Click (or Shift+right click, in-case of taskbar) on Chrome Icon. Select Properties. In "Target" text-box, add --disable-web-security flag.
So text in text-box should look like
C:\Users\njadhav\AppData\Local\Google\Chrome SxS\Application\chrome.exe" --disable-web-security
Click Ok and launch chrome.
just run this command from command prompt and it will launch chrome instance with CORS disabled:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp
Automated solution for Windows 10
Right-click on Chrome icon > right-click Google Chrome > Properties
Shortcut > Target > "C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir="C:\ChromeDevSession"
Notes:
Your file path for chrome.exe may vary.
Also, the --user-data-dir flag is required, and its file path may vary. Besides C:\ChromeDevSession, another possible location is ~/chromeTemp
Now Chrome always has its web security disabled :-)