I'm dabbing into switching over our acceptance tests to the Capybara/Apparition driver. I want to add specific Chrome browser preferences for the download path.
I can't find any documentation on this, and by the look of things I can't use a Chrome options object like I would with Capybara, Selenium and chromedriver, such as:
#options = Selenium::WebDriver::Chrome::Options.new
def specific_chrome_options
preferences = {
prompt_for_download: false,
default_directory: FilesDownloadHelper::PATH # custom profile needed to test file downloads
}
#options.add_preference(:download, preferences)
I've tried to set this with a '--user-data-dir' args and preferences file created during run, but it doesn't seem like it is picking it up.
Perhaps the driver is still in a beta state for these kind of things?
With apparition downloads should go to whatever directory Capybara.save_path is set to.
Related
We are setting kiosk-type workstations with chromium browser running in incognito mode. There is a need to have redux-devtools extension for development purposes.
We managed in install it using scripts. Basically uploaded bundles and manifest.json to
/usr/share/chromium-browser/extensions
In non-incognito mode it works. And there is a way to enable it in incognito move using UI (settings for the extension).
But the thing is that we have no access for this interaction and we have to do it somehow programmatically. Looks like its not some browser setting but extension's one. Is there any way to do it using bash or smth. similar?
There is no direct way to do it. But I've manage to do this in no so obvious way. I made it work by directly modifying preferences file. To make it work all chrome instances should be closed. Also instead of installing extension just unpack it somewhere you know. So here is how to start chrome
`chrome --incognito --load-extension=<path/to/unpacked/extension>`
This will start chrome with extension installed meaning that some preference entries will be created. Now we need to modify value that responsible for allowing extension in incognito mode. For this I wrote a small python3 script:
extension_incognito_enabled.py
import json
import os
import sys
google_chrome_preferences ="/home/j2ko/.config/google-chrome/Default/Preferences"
incognito_value = (False, True)[sys.argv[1] == "true"]
print("Closing all chrome instances")
os.system('killall chrome')
#As we load extension using --load-extension flag we can use path to it
field_to_compare="path"
field_value_to_compare_with="/home/j2ko/Downloads/isAllowedAccess"
jsonPreferences =""
with open(google_chrome_preferences, "r+") as jsonFile:
jsonPreferences = json.load(jsonFile)
settings = jsonPreferences["extensions"]["settings"]
for extension_name in settings:
extension_setting = settings[extension_name]
if extension_setting[field_to_compare] == field_value_to_compare_with:
extension_setting["incognito"] = incognito_value
print("Successfully modified file. Now incognito mode value is ", incognito_value)
break
with open(google_chrome_preferences, "w+") as jsonFile:
json.dump(jsonPreferences, jsonFile)
I've tested it using isAllowedAccess. So to suit your needs you need to modify script and provide proper values for field_value_to_compare_with (which actually equals to --load-extension value) and provide correct google_chrome_preferences value.
You can use script as :
extension_incognito_enabled.py true # to enable
extension_incognito_enabled.py false # to disable
If you only have python2 simply remove print lines and it should work as well.
I've synced my User folder with sublime settings.
But what if I want to use different settings for different machines? For example, in settings of terminal package I define path to Git Bash, and it's
"terminal": "C:/Program Files (x86)/Git/bin/sh.exe"
on one machine, and
"terminal": "C:/Program Files/Git/bin/sh.exe"
on another.
I've tried to use default settings, but they refresh all the time.
Maybe look into this package: https://packagecontrol.io/packages/PackageSync
I've never used it, but according to the README,
PackageSync provides the following user configurable settings:
...
ignore_files [array]
The list of files to ignore when backing up.
So you would want to create a PackageSync.sublime_settings file that has this in it:
{
"ignore_files": "Terminal.sublime_settings"
}
This isn't ideal since it prevents the enitre file from syncing, not just that one entry (the "terminal": "C:/Program Files (x86)/Git/bin/sh.exe" entry), but it should work. (Disclaimer: I have not tried this myself)
Alternative: Possible workaround:
You could also just use the line "terminal" : "~/my_custom_terminal_shortcut" in your settings and then create a ~/my_custom_terminal_shortcut file on each computer that links to the appropriate location
When I run Karma (formerly Testacular) with 'browsers' configured to 'Chrome' and 'Firefox', 2 browser instances indeed open, however the extensions/plugins appear to be missing while I want them running with my tests.
I've configured:
CHROME_BIN=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe and FIREFOX_BIN=C:\Program Files (x86)\Mozilla Firefox\firefox.exe
It kinda looks like the launched Chrome instance is of a different installation or something, as it doesn't have all my Chrome bookmarks (neither the extensions, as written).
Any idea?
If you change the index.js like this:
this._getOptions = function(url) {
// Chrome CLI options
// http://peter.sh/experiments/chromium-command-line-switches/
return [
'--user-data-dir=' + this._tempDir,
'--no-default-browser-check',
'--no-first-run',
'--disable-default-apps',
'--disable-popup-blocking',
'--start-maximized',
'--load-extension=' + '<your path to the extension>/2.0_0'
].concat(flags, [url]);
where
<your path to the extionsion>
is something like this:
/Users/dannyb/Library/Application Support/Google/Chrome/Default/Extensions/hmhgeddbohgjknpmjagkdomcpobmllji
That weird number is the extionsion ID that you can find in your extensions page in chrome.
If you look at how chrome is run on karma, along with some other command line flags, it disables default apps
on start up. I myself am looking for how to turn these features off, but no luck yet.
https://github.com/karma-runner/karma-chrome-launcher/blob/master/index.js
I added the preference ExtensionInstallSources (as per: http://www.chromium.org/administrators/policy-list-3#ExtensionInstallSources ), it still is not allowing me to install my "app.crx" from my URL. I added it as follows:
File: /home/myuser/.config/google-chrome/Default/Preferences
"extensions": {
"ExtensionInstallSources": [ "http://myurl.com/*" ],
...elided...
Yet, when I go to the url http://myurl.com/myapp/app.crx it tells me it cannot install from that url. How do I fix this?
MORE INFO:
It appears that Preferences file is not the correct one to edit. I downloaded an example on from here: http://dl.google.com/dl/edgedl/chrome/policy/policy_templates.zip as specified here: http://support.google.com/chrome/a/bin/answer.py?hl=en&answer=187945
That provides a "chrome.json" file but does not specify where to install this. I tried installing it in the .config/chrome/Default folder but that doesn't work.
My chrome.js file is:
// Policy template for Linux.
// Uncomment the policies you wish to activate and change their values to
// something useful for your case. The provided values are for reference only
// and do not provide meaningful defaults!
{
"ExtensionInstallSources": ["http://myurl.lamp/*"]
}
It still does not work!
2ND UPDATE:
I put the setting in /etc/opt/chrome/policies/managed/test_policy.json as specified here: http://www.chromium.org/administrators/linux-quick-start and it still does not work!
3RD UPDATE:
I checked chrome://policy and it shows the permission is there! It still won't let me install crx's from the URL though! It shows the value for ExtensionInstallSources is:
http://myurl.lamp/*,http://localhost/*,http://192.168.1.109/*,*://myurl.lamp/*,file:///*
But none of those work!
I just tried this using chrome unstable (35.0.1908.4) in a test ubuntu virtual machine and it worked fine. Did you restart chrome after changing the policy file?
I've looked through various sources online and done a number of Google searches, but I can't seem to find any specific instructions as to how to work with the V8 --trace-* flags in Google Chrome. I've seen a few "You can do this as well in Chrome", but I haven't been able to find what I'm looking for, which is output like this: (snippets are near the near bottom of the post) Optomizing for V8.
I found reference that the data is logged to a file: Profiling Chromium with V8 and I've found that the file is likely named v8.log: (Lost that link) but I haven't found any clues as to how to generate that file, or where it is located. It didn't appear to be in the chrome directory or the user directory.
Apparently I need to enable .map files for chrome.dll as well, but I wasn't able to find anything to help me with that.
The reason I would prefer to use Chrome's V8 for this as opposed to building V8 and using a shell is because the JavaScript I would like to test makes use of DOM, which I do not believe would be included in the V8 shell. However if it is, that would be great to know, then I can rewrite the code to work sans-html file and test. But my guess is that V8 by itself is sans-DOM access, like node.js
So to sum things up;
Running Google Chrome Canary on Windows 7 ultimate x64
Shortcut target is "C:\Users\ArkahnX\AppData\Local\Google\Chrome SxS\Application\chrome.exe" --no-sandbox --js-flags="--trace-opt --trace-bailout --trace-deop" --user-data-dir=C:\chromeDebugProfile
Looking for whether this type of output can be logged from chrome
If so, where would the log be?
If not, what sort of output should I expect, and again, where could I find it?
Thank you for any assistance!
Amending with how I got the answer to work for me
Using the below answer, I installed python to it's default directory, and modified the script so it had the full path to chrome. From there I set file type associations to .py files to python and executed the script. Now every time I open Chrome Canary it will run that python script (at least until I restart my pc, then I'll have to run that script again)
The result is exactly what I was looking for!
On Windows stdout output is suppressed by the fact that chrome.exe is a GUI application. You need to flip Subsystem field in the PE header from IMAGE_SUBSYSTEM_WINDOWS_GUI to WINDOWS_SUBSYSTEM_WINDOWS_CUI to see what V8 outputs to stdout.
You can do it with the following (somewhat hackish) Python script:
import mmap
import ctypes
GUI = 2
CUI = 3
with open("chrome.exe", "r+b") as f:
map = mmap.mmap(f.fileno(), 1024, None, mmap.ACCESS_WRITE)
e_lfanew = (ctypes.c_uint.from_buffer(map, 30 * 2).value)
subsystem = ctypes.c_ushort.from_buffer(map, e_lfanew + 4 + 20 + (17 * 4))
if subsystem.value == GUI:
subsystem.value = CUI
print "patched: gui -> cui"
elif subsystem.value == CUI:
subsystem.value = GUI
print "patched: cui -> gui"
else:
print "unknown subsystem: %x" % (subsystem.value)
Close all Chrome instances and execute this script. When you restart chrome.exe you should see console window appear and you should be able to redirect stdout via >.
If your not keen on hacking the PE entry of chrome then there is alternative for windows.
Because the chrome app doesn't create a console stdout on windows all tracing in v8 (also d8 compiler) is sent to the OutputDebugString instead.
The OutputDebugString writes to a shared memory object that can be read by any other application.
Microsoft has a tool called DebugView which monitors and if required also stream to a log file.
DebugView is free and downloadable from microsoft: http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx