Karma: use Windows' Chrome from WSL - google-chrome

I am trying to launch karma from WSL using the Windows version of Google Chrome.
In the karma.conf.js I simply use the Chrome browser:
[...],
browsers: ['Chrome'],
[...]
And I export the CHROME_BIN environment variable like this:
export CHROME_BIN='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
Karma successfully find Google Chrome, and a new tab is opened at the right URL when Karma is launched. However, I get this error:
Google chrome can't read and write to its data directory /tmp/karma-XXXX
I tried starting chrome as administrator and changing the cache folder to the root of my project but it doesn't work.
I assumed there was a issue with the format of the path that Karma give to Chrome (WSL path vs Windows path).
So I create a custom karma launcher specifying the chromeDataDir:
browsers: ['WindowsChrome'],
customLaunchers: {
WindowsChrome: {
base: 'Chrome',
chromeDataDir: 'D:\\'
}
}
By doing that a I don't have the previous error, a new instance of Chrome is launched but Chrome seems unable to resolve the URL, and karma timeout.
Moreover, a lot of Chrome folders are created inside my project.
Have someone already make karma work from WSL using Chrome or have any cue on what is going on ?

I found that if you create a C:\tmp\karma folder under Windows, this error goes away, and Chrome finds and uses this folder for temp files.
You can also change the temporary folder that Chrome uses for its data by setting the TEMP environment variable like so:
export TEMP='/path/to/your/folder'
The important thing is that C:\path\to\your\folder must exist under Windows.

Now in january 2022, on WSL2, tested on debian 11/WSL under windows 11, it's "easy" :
From windows command prompt :
SET CHROME_EXECUTABLE=C:\Program Files\Google\Chrome\Application\chrome.exe
Test :
echo %CHROME_EXECUTABLE%
C:\Program Files\Google\Chrome\Application\chrome.exe
Share this Windows env variable with WSL (doc. https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/) :
set WSLENV=CHROME_EXECUTABLE/p
From Windows command prompt, enter wsl, :
wsl
Verify the env variable is ok under wsl :
echo $CHROME_EXECUTABLE
/mnt/c/Program Files/Google/Chrome/Application/chrome.exe

Related

Default location of ChromeDriver binary and Chrome binary on windows 7

What is the default location of ChromeDriver binary and Chrome binary on windows 7 for triggering appium using java-client.jar? if i am using RemoteWebDriver and tries to initiate chrome browser, from where does the selenium initiates the chromedriver?
the code:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("userName", ReadProperties.Properties("MobileUsername"));
capabilities.setCapability("password", ReadProperties.Properties("MobilePassword"));
capabilities.setCapability("udid", ReadProperties.Properties("MobileUID"));
capabilities.setCapability("browserName", ReadProperties.Properties("MobileBrowser"));
capabilities.setCapability("platformName", ReadProperties.Properties("MobilePlatform"));
log.Info(capabilities.getVersion());
mobile_driver = new RemoteWebDriver(new URL(""+ReadProperties.Properties("MobileURL")+"/wd/hub"),capabilities);
chromedriver is not installed in your System by default. Users individually have to download chromedriver from ChromeDriver - WebDriver for Chrome page and you can place it anywhere within your system.
You must ensure that Chrome is installed at the optimum location as the server expects you to have Chrome installed in the default location for each system as per the snapshot below :
Note : For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. You can also override the Chrome binary location following the documentation Using a Chrome executable in a non-standard location.
The location will depend on your default download folder e.g. when you download something from the internet and it goes into the downloads folder, then that is your default download folder.
So if you downloaded chromedriver.exe the same way, then it will also be in the downloads folder.
If you are using 3rd party service to run your tests you should not care about chromedriver.
But when you run tests locally you have to download it yourself: https://chromedriver.storage.googleapis.com/index.html
And then use capability to set absolute path to this file.
Make sure you use chromedriver version compatible with your browser version.
I know it's an old question but none of the answers above helped me. I found a different solution that worked for me and it might help someone else in the future.
I have tried the below solution with only Windows 10 / Server 2016.
Step 1: Get to the Google Chrome install directory by right clicking on the Chrome icon and click on Properties. You will see the installed directory listed under 'Target' and 'Start in' options. The directory path should end with .../Chrome/Application/. Copy the whole path.
Step 2: Open File Explorer and go to the above copied path. You should see chrome.exe file with other files and folders. Copy the whole Application/ folder including chrome.exe file with other files and folders.
Step 3: Go to the below file path and paste the above Application folder.
C:\Users<YOUR USER>\AppData\Local\Google\Chrome\
After pasting the Application folder, you should have the chrome.exe file with other files and folders in the following file path:
C:\Users<YOUR USER>\AppData\Local\Google\Chrome\Application\
Now the ChromeDriver should be able to locate the Chrome Binary.

Google Chrome Path in Windows 10

Google repeatedly changed the path to the .exe of Chrome. Sometimes it's hidden in %APPDATA%, in Version 35/36 they changed the path back to program files. There are also differencies across the Windows versions.
Where is Google Chrome located in Windows 10?
Please see the screenshot which gives you the ability to seek for the current path of google chrome path or any other application
Task Manager - Windows 10
Windows 10:
%ProgramFiles%\Google\Chrome\Application\chrome.exe
%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe
%LocalAppData%\Google\Chrome\Application\chrome.exe
Windows 7:
C:\Program Files (x86)\Google\Application\chrome.exe
Vista:
C:\Users\UserName\AppDataLocal\Google\Chrome
XP:
C:\Documents and Settings\UserName\Local Settings\Application Data\Google\Chrome
There are also Registry Keys and environment variables to use. Check out this post for universal use for programming.
Chrome can be installed in various places on Windows, for a given user or "all users", in which case it's installed in Program Files.
To determine where it is programmatically:
Batch file:
set exe=
FOR /F "tokens=2* skip=2" %%a in ('reg query HKCR\ChromeHTML\shell\open\command /ve') do set exe=%%b
set exe=%exe:"=%
set exe=%exe:~0,-6%
PowerShell:
(gp Registry::HKCR\ChromeHTML\shell\open\command)."(Default)" -match '"(.*?)"' | Out-Null
$exe=$matches[1]
C#:
var exe = System.Text.RegularExpressions.Regex.Match((string)Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(#"ChromeHTML\shell\open\command").GetValue(null),
#"""(.*?)""",
System.Text.RegularExpressions.RegexOptions.None)
.Groups[1].Value;
Python
import winreg
import re
command = winreg.QueryValueEx(winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, "ChromeHTML\\shell\open\\command", 0, winreg.KEY_READ), "")[0]
exe=re.search("\"(.*?)\"", command).group(1)
VBA / VBScript
Set objShell = CreateObject("WScript.Shell")
cmd = objShell.RegRead("HKCR\ChromeHTML\shell\open\command\")
exe = Mid(cmd, 2, 999)
exe = Left(exe, InStr(exe, Chr(34)) - 1)
The answer I am writing is applicable for any software/application installed on windows.
Windows 10
Click on windows button and search for the application, in this case Chrome.
Right click on application name and click on "Open file location".
You will reach at location of the shortcut of that application. Again right click on the application shortcut and then click on "Open file location" and you will get the path from top url/path bar of explorer or you can click on properties to get the path as shown in image.
And you will get your path for desired application from tab shown in image.
PS: Doesn't works for apps installed from windows store.
Right click on the sub process to see the open file location :
Screenshot
To find the location of Google, type the following command...
chrome://version
And then look for Command Line on the left side of the screen.
I found something in the Registry when I installed Chrome Canary at the same time.
in a batch file, using chrome.exe it always opens Canary...
then I change from:
Equipo\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
"C:\Users\heratess\AppData\Local\Google\Chrome SxS\Application\chrome.exe"
To:
Equipo\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
C:\Program Files\Google\Chrome\Application\chrome.exe
and it worked for me.
maybe it could help you.

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

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.

Is there an option to enable json-loading from HDD in Chrome or Internet Explorer?

Is there an option to enable Chrome or the Internet Explorer to load (via ajax-get) an JSON file from the local harddisk?
Firefox does so by default. Internet Explorer says 'premission denied' at the line
request.open(method, url, true);
There are no simple cleaner way you can do this, you have to do some server-side coding.
I suggest you node.js this is very handy for this type of IO operations.
It looks very difficult for first time but it is very handy.
Download and install nodejs.
create a simple project to handle this.
In the directory you want files to get (e.x. D:\myfiles), create one file server.js, content of that js file would be following
var connect = require('connect');
var serveStatic = require('serve-static');
connect().use(serveStatic("./")).listen(105);
open command promp from and get to this directory (D:\myfiles)
Run these two commands npm install connect and npm install serve-static (up to this, is one time process)
Run node server.js - That's all your server is ready and running
call http://localhost:105/<file name> and you can get any files within that directory.
For chrome you can use following command line flags, taken from following question
--allow-file-access-from-files
--disable-web-security
As noted in that question you need to restart your all chrome browsers.
For internet explorer, trick is to use ActiveX version of the XMLHttpRequest object.
See following link.
https://social.msdn.microsoft.com/Forums/ie/en-US/9ae077e0-a7b9-433f-835f-2643aa1a7e09/ie11previewcannot-read-local-files-with-ajax-method-of-jquery?forum=iewebdevelopment