Selenium - Chrome is not starting when I try to load an extension - google-chrome

Since Firefox does not support the GWT DevMode any more, I want to switch to Chrome for developing selenium tests for my application.
However, it fails to load the GWT-dev-plugin extension. The test does not return from
driver = new ChromeDriver(capabilities);
Without configuring the extension, in works in the sense that a Chrome instance is at least started, however, without GWT plugin.
This is the way I configure the webDriver:
package the GWT plugin of your Chrome installation (described here http://www.mythoughts.co.in/2013/09/seleinum-webdriver-loading-chrome.html#.U0ZTFFfKGno)
use the path of the plugin .crx package as pluginPath in the following code
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(pluginPath));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
File driverExecutable = new File("test-selenium/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", driverExecutable.getAbsolutePath());
driver = new ChromeDriver(capabilities);
The only logging is a WARNING concerning the plugin key:
[14.899][WARNING]: Public key in crx header is different from key in manifest
key from header: ....
generated extension id from header key: godampgacipeiboepncogmjpfbgcpfba
generated extension id from manifest key: jpjpnpmbddbjkfaccnmhnkdgjideieim

Related

PuppeteerSharp: Failed to launch Chromium

The error started to happen after updating google chrome to the latest version: 89.0.4389.82 (Official Build) (64-bit).
OS: Windows 10
Error:
PuppeteerSharp.ChromiumProcessException:
Failed to launch Chromium! [0309/160320.924:ERROR:os_crypt_win.cc(70)] Failed to encrypt: The system cannot find the file specified. (0x2)
Help, please!
I too got the same error while launching the chrome in the server using an application. I did upgrade google chrome manually and everything worked fine as normal.
after much faffing around trying to get this working in an asp.net app running in a production server environment (windows server 2019 in azure VM), i wanted to elaborate on vidya's answer "upgrade google chrome manually":
set the version number manually based on the latest version on this URL:
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win_x64/
in my case that version is 890410. set your code to use this version instead of DefaultChromiumRevision
const string ChromiumRevision = "890410";
var options = new BrowserFetcherOptions();
options.Path = HttpContext.Current.Server.MapPath("/App_Data");
var bf = new BrowserFetcher(options);
await bf.DownloadAsync(ChromiumRevision);
string exePath = bf.GetExecutablePath(ChromiumRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = exePath,
Args = new string[]{"--disable-gpu","--no-sandbox"}
});

Selenium not starting portable chrome but local installation

I have a problem with the Selenium web driver. What I'm trying to do is to start a "portable" chrome instead of my local installation, because it has different settings.
The problem is that the portable Chrome (from PortableApps) seems to only start when using GoogleChromePortable.exe. If I use the Chrome binary directly, it will start my local installation.
With Selenium it seems that no matter what Chrome path I pass to it (GoogleChromePortable.exe or binary path), it starts my local installation.
Here is my code:
String chromePath = "M:/my/path";
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
capabilities.setCapability("chrome.binary", chromePath);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Any ideas how to be able to start my portable chrome?
Thanks
For anyone else stumbling upon this problem, here is how I managed to get the portable Chrome starting:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(binaryPath);
driver = new ChromeDriver(chromeOptions);
I'm using Python 3.7 on Windows 10 and got Chrome Portable from PortableApps.com.
comments by #mario.schlipf and #SeJaPy were helpful, but I noticed that in the newer Webdriver releases, the setbinary method has been replaced by binary_location
This is how it actually worked for me:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chromedriverpath='M:/my/chromedriver.exe'
chromePath = 'M:/my/App/Chrome-bin/chrome.exe' # <== IMPORTANT! See note below.
chromeoptions = Options()
chromeoptions.add_argument('--incognito')
chromeoptions.binary_location = chromePath
browser = webdriver.Chrome(executable_path=chromedriverpath, options=chromeoptions)
NOTE:
The chromePath variable must point to the Chrome executable in the portabilized environment.
In packages obtained from PortableApps.com, you have two executables: a GoogleChromePortable.exe in the install (actually, unpack) directory and a chrome.exe in [installdirectory]/App/Chrome-bin, the first being "just" a launcher which provides the portabilized app with a consistent environment.
As I could observe, chromedriver needs to directly interact with the "real" Chrome executable, otherwise the script will launch the browser (via the launcher) but will eventually crash with error message:
unknown error: DevTools Active Port file doesn't exist
and no browser session will be returned as a result.
This may seem obvious to many people... but it was not to me, so I decided to put this note in order to make some clarity for the less clever guys (myself included) :).
String chromePath = "M:/my/googlechromeporatble.exe path";
String chromedriverpath="M:/my/chromedriver.exe path";
ChromeOptions options = new ChromeOptions();
options.setBinary(chromepath);
System.setProperty("webdriver.chrome.driver",chromedriverpath);
driver = new ChromeDriver(options);
This will invoke portable chrome rather than local installation.
First set google chrome portable path and then invoke chromeriver.exe
Depending on the settings you have in ChromePortable, maybe you could default ChromeDriver with Capabilities & ChromeOptions?
I'm thinking especially on custom profile. If you somehow could get that from your ChromePortable and load it with default ChromeDriver?
EDIT: Maybe this could help

Chrome Debugger Api Attach Extension Error

Task: Debug other extensions using chrome debugger api.
Expected Output: http request logs made by other installed extensions.
Method: Running chrome webdriver with selenium in python setting flag chromeopts.add_argument('--silent-debugger-extension-api' ). Inside my extension, On event chrome.management.onInstalled using following code
chrome.debugger.attach({ extensionId: info.id }, version, onAttach.bind(null, info.id));
chrome.debugger.sendCommand({ extensionId: info.id }, "Network.enable");
chrome.debugger.onEvent.addListener(onEvent);
Error: Cannot access a chrome-extension:// URL of different extension
To debug the background page of another extension, you need to set two flags:
--silent-debugger-extension-api
To allow debugging of background pages.
--extensions-on-chrome-urls
To allow debugging of other extensions.

How to launch the REST Console URL using selenium webdriver?

public static void main(String args[]) throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\pugazd\\Desktop\\chromedriver.exe");
String url2="chrome-extension://cokgbflfommojglbmbpenpphppikmonn/index.html";
WebDriver driver = new ChromeDriver();
driver.get(url2);
}
I try to launch the URL with chrome browser, the browser opens with the error.
Error: The webpage at chrome-extension://cokgbflfommojglbmbpenpphppikmonn/index.html might be temporarily down or it may have moved permanently to a new web address.
Error code: ERR_FAILED.
How do I open the REST Console ?
Thanks in Advance
Thyagu
By default Chrome does not load any extensions in the window launched by Selenium. (You can verify this by loading driver.get("http://www.Google.com") and checking the list of extensions.
And obviously your extension should be loaded into Chrome, for the URL (which you tried) to work.
To enable ChromeDriver to load extensions, use
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);

How can I launch Chrome with an unpacked extension?

I'm using Selenium WebDriver to test a Google Chrome extension I'm developing. I noticed that ChromeDriver can be customised to add extensions to the instance of Chrome that it launches. This can be achieved using the AddExtension and AddExtensions methods of the ChromeOptions class.
The documentation for these methods indicates that they require extensions to be provided as crx files. Since I'm developing the extension, I don't have a crx file. I would like to be able to load the unpacked extension, but I couldn't find a method to do this.
I tried putting the extension files in a zip file and specifying this for the AddExtension method, but this caused an exception to occur since it wasn't a crx file. I also tried passing in the directory containing the unpacked files, but this produced a FileNotFoundException.
How can I do this?
I was able to achieve this by using the AddArgument method to directly pass the information to Chrome. Here's what it looks like in C#:
options = new ChromeOptions();
options.AddArgument("--load-extension=" + unpackedExtensionPath);
For packed extensions (a .crx file)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
For unpacked extensions (a local folder)
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=/path/to/extension");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
source
It may be late but for future users:
https://sites.google.com/a/chromium.org/chromedriver/extensions
The unpacked extension error popped up for me and I requested for removing the restrictions in chrome which was enforced as organizational policy. Once the restrictions were removed, I am able to run the program with out any errors. ChromeBrowser-GPO-Deny - this was the one which was removed. You can check in Settings - Extensions - Check on Developer mode and see if the load unpacked extensions is checked once the restrictions are removed. You should be good then. All the above will work only when the chrome is not restricted.
In Python3 it can be done like this:
from selenium.webdriver import Chrome, ChromeOptions
options = ChromeOptions()
options.add_argument("load-extension=/path/to/unpacked_ext")
driver = Chrome("/path/to/chromedriver", options=options)
# (optional) Look at the uploaded extension
driver.get("chrome://extensions")
Here is apython example using webdriver_manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
# loading the extension Edit-This-Cookie
options.add_argument("--load-extension=./Edit-This-Cookie")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
driver.get("https://google.com")
The Selenium documentation has an example like this for a packed ( not unpacked) extension:
capabilities.setCapability("platform", "Windows 8" );
capabilities.setCapability("version", "10");
capabilities.setCapability("name", testname);
capabilities.setCapability("screen-resolution", "1280x1024");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
if (isLocal) driver = new ChromeDriver(capabilities);