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

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

Related

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

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.

How to disable Google Chrome extension autoupdate

How do I disable Google Chrome extension autoupdate?
Solutions I've found for this:
1. Disabling a concrete extension update
That's what I wanted!
You can do this by editing the extension's manifest.json file:
On Windows: C:\Users\<USERNAME>\AppData\Local\Google\Chrome\User Data\Default\Extensions\<EXTENSION-ID>\<VERSION>\manifest.json (find out the extension's ID by enabling Developer Mode in the extension settings page)
On MacOS: Open /Users/USERNAME/Library/Application Support/Google/Chrome/Default/Extensions/EXTENSION-ID/VERSION/manifest.json in a text editor.
On Ubuntu for Chromium: ${HOME}/.config/chromium/Default/Preferences
In this file, set the "update_url" property to something invalid like "https://localhost" for example. For the given url, it makes auto-updating that extension as simply impossible.
Source: https://productforums.google.com/d/msg/chrome/l3zOZeO-5-M/Y7VaR0KCWNIJ
2. Disabling all Google Chrome extension updates
For any OS: Just type chrome://plugins/ at address bar and turn Google Update plugin off. Source: How to disable Google Chrome auto update?
For Windows OS: Set Registry values:
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Update]
"AutoUpdateCheckPeriodMinutes"=dword:00000000
"UpdateDefault"=dword:00000000
Source: Making Google Chrome leave itself alone
If the chrome extension is on Github (which many if not most of them are), you can simply:
(1.) clone the Github repo,
(2.) reset the head to the version that you want, and
(3.) enable Developer Mode at chrome://extensions/
(4.) select the "Load unpacked" option from chrome://extensions/, and then select the folder enclosing the source code for the extension.
I recently used this technique to downgrade my version of Reddit Link Opener, which no longer supports users who have opted out of using that site's redesign. This worked for me on MacOS, but should work on all platforms.
If the extension is loaded as an unpacked extension (in the manner described above), it will NOT auto-update to a newer version.
Disabling update for a specific extension:
This can be achieved with the system policies, (more details here)
For Linux :
Get the installed extensions list (IDs), this can be found with ls -l ~/.config/google-chrome/Default/Extensions or chrome://extensions
Create the necessary directory if not present mkdir -p /etc/opt/chrome/policies/managed (with root)
Create the needed file policies file touch /etc/opt/chrome/policies/managed/google-chrome.json
Edit that file with the code bellow
open the page chrome://policy/ and reload the policies
{
"ExtensionSettings": {
"ghijklmnopabcdefghijklmnopabcdef": {
"update_url": "https://127.0.0.1/update_url",
"override_update_url": true
},
"YOUR-EXTENSION-ID-LIKE-THE-PREVIOUS-EXAMPLE": {
"update_url": "https://127.0.0.1/update_url",
"override_update_url": true
}
}
}
Note: this can not be applied widely to all extensions in a single rule and also for each newly installed extension the file need to be updated
Hi all those solitions for me have one disadvantage is that all extensions have no updates, I needed to stop only for one extension in this case and wanted al the other to keep making updates.
I think I found the solutuion for windows
Go to
C:\Users\YOUR_NAME_HERE\AppData\Local\Google\Chrome\User Data\Default\Extensions\YOUR_FOLDER APP HERE\
In that folder app click in properties and select read only an aplly that to all subfolders and files... for now for me solved the problem !!!
Regards xichas
this is a complementary answer to the accepted one https://stackoverflow.com/a/27657703/1422630 , allowing disable all at once on chromium
this is also only for linux (may be run on windows thru cygwin tho, not tested..)
this script will
backup the prefs file,
modify it,
if didnt succeed will output "FAILED"
show the differences using meld if installed
#!/bin/bash
set -ue
strPref="$HOME/.config/chromium/Default/Preferences"
cat "$strPref" |egrep "\"update_url[^,]*," -o |sort -u
read -p "existing unique urls above..." -n 1
strBkp="${strPref}.`date +"%Y%m%d%H%M%S"`.bkp"
if cp -v "$strPref" "$strBkp";then
strUpdUrl="clients2.google.com/service/update2/crx" #change this if needed #TODO should match any URL...
sed -i -r "s#(update_url\":\"https{,1}://)(${strUpdUrl})#\1127.0.0.1#g" "$strPref"
if grep "$strUpdUrl" "$strPref";then echo FAILED >&2;exit 1;fi
cmdDiff=colordiff
if which meld;then cmdDiff=meld;fi
#$cmdDiff <(cat "$strPref" |egrep "\"update_url[^,]*," -o) <(cat "$strBkp" |egrep "\"update_url[^,]*," -o)
$cmdDiff <(cat "$strPref" |sed -r 's#","#",\n"#g') <(cat "$strBkp" |sed -r 's#","#",\n"#g')
fi
tested on chromium: Version 63.0.3239.84 (Official Build) Built on Ubuntu , running on Ubuntu 16.04 (64-bit)
obs.: that script also works for google-chrome, just change the preferences file path
After updating Google Chrome to v60, no solution found on the Internet has helped me
So i just blocked IP addresses, used for updating, by doing following steps:
Opened Chrome with blank browser tab
Waited, until extension
autoupdate begins, by looking on to network tab in Resource
Monitor
Wrote out all the IP addresses with high download rate. My IP address list was:
64.233.161.94
64.233.161.102
64.233.163.95
74.125.238.132
108.177.14.138
173.194.73.132
173.194.222.102
216.58.209.110
216.58.209.97
173.194.222.99
173.194.32.227
173.194.113.172
173.194.32.224
195.216.237.77
74.125.232.170
143.215.130.61
74.125.238.147
173.194.122.137
173.194.44.66
173.194.44.67
173.194.44.95
173.194.122.136
74.125.232.183
74.125.232.171
Created outbound rule for chrome.exe in Windows Firewall and added listed IP addresses to blocklist
After I enabled this rule, chrome was unable to update my extensions.
Just (re)install the extension via Load unpacked.
Let's suppose "Roboform Password Manager" extension version 8.6.5.5 dropped some important functionality, so you want to keep version 8.6.2.2 installed.
Go to chrome://extensions/
Enable Developer mode
Get the required version of the plugin:
If Chrome still got the version you need:
Utilize Pack extension button on the plugin details page.
Just copy the extension folder, e.g. C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\Extensions\pnlccmojcmeohlpggmfnbbiapkmbliob. The extension id is visible in the url bar, on the plugin details page, e.g. chrome://extensions/?id=pnlccmojcmeohlpggmfnbbiapkmbliob.
If the version you need was overwritten already:
Get appropriate ".crx" from some extensions archive
Look for ".crx" in "C:\Program Files\..." (applications/installers sometimes bundle original ".crx" versions, unaffected by any updates)
Unzip (e.g. with 7-zip) your ".crx" (or paste the extension folder contents) to a non-temporary folder - you would have to keep those files in place until you uninstall the extension.
Click Load unpacked, select that folder.
If you just drag&drop the ".crx" file, Chrome extension details would show Source=Chrome Web Store, and it would get updated as soon as you click Update extensions now. But for an unpacked extension, you get a special "Unpacked extension" overlay icon, Source=Unpacked extension and it won't get updated.
Just tested on Chrome 79.0.3945.88 (64-bit), Windows.
Now, Chrome shows "Disable developer mode extensions" popup on each startup. Personally, I just manually dismiss them each time. I do not re-start Chrome too often.

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

Open an .html file with default browser using Bash on Mac

So, this is what I need :
Let's say I have an index.html file.
How do I tell the terminal to open it using the default browser?
(Using AppleScript, BASH,...?)
from the directory containing index.html, try...
open ./index.html
the open command opens a file (or directory, or URL). open is included with MacOSx. specifics and options can be found using
man open
note: default application is determined via LaunchServices.
You can use the open command with the -a flag to open a file or location in Chrome (or any target application):
open -a "Google Chrome" index.html
This also works with URLs, i.e. open -a "Google Chrome" http://www.apple.com.
---> I found this answer # stack exchange, thanks to user "robmathers"
Actually, this is not quite as straightforward as it looks. As suggested by the other answers, OS X provides the open utility to launch applications matching a file type from the shell. However, in the case of a HTML file, that is the application registered with Launch Services for the file type public.html, which can, but need not be, your default browser (I think it is on a pristine install) – or whatever editor registers as able to edit HTML (not an uncommon occurrence on a dev system). And while the default browser is registered for the URL protocol http no matter what, there is no way to access that protocol handler to open a file with open.
To compound the issue, although the handlers are stored in the com.apple.LaunchServices.plist preferences accessible via the defaults command, the structure of the information (a dictionary with two same level entries, one denoting the protocol, one the handler) makes it non-trivial to parse with defaults.
The good news is somebody already solved that problem: HAMsoft Engineering offers the DefaultApplication shell utility. Download it and save it somewhere where it is accessible to the shell (typically /usr/local/bin, although that is not in the default path for shells on some OS X versions – check the contents of /etc/paths to be sure). That available, the following command will open a HTML file in the default browser, whatever editor / viewer might be registered otherwise:
open -a "$(/usr/local/bin/DefaultApplication -url 'http:')" "/path/to/your/document.html"
To open the filename.html in the default browser use :
open filename.html
open is a very good command as well as a feature of Mac OS that makes me fall in love with it more deeper.
It automatically chooses the appropriate default app to open the file.
And in case you want to open a file in your desired app rather then default :
open -a /Applications/Google\ Chrome.app filename.html
The backslash \ after Google is used to escape the space character.
Alternatively you can write :
open -a "/Applications/Google Chrome.app" filename.html
Hope this helps you ( I know I am very late ) and others !!!.
You can also get the default browser with Perl: open http://example.com -a "$(VERSIONER_PERL_PREFER_32_BIT=true perl -MMac::InternetConfig -le 'print +(GetICHelper "http")[1]')".
i managed to open the html file with chrome by placing the file after the browser command. so,
google-chrome-stable ./index.html
although im not sure what the call would be to the default browser, if you knew it you could put it as an alias in your .bashrc and from then on, use whatever you called your alias, plus the file.
goo ./index.html
just my experience, first response
In terminal you can run open index.html
this works on linux, should also work on mac
#!/bin/sh
# open a html file in default browser, not text editor,
# when text editor is set as default app for html files
url=file:///path/to/file.html
protocol=http
app=$(xdg-mime query default x-scheme-handler/$protocol)
# example: chromium-browser.desktop
[ -z "$app" ] && {
echo "error: xdg-mime could not find default app for protocol $protocol"
exit 1
}
app=$(basename $app .desktop)
gtk-launch $app "$url"
ideally i could just say
xdg-open http+file:///path/to/file.html
but this is not working