BUG: Cannot Resize Window when ChromeDriver is running in incognito mode
Meta -
OS: Mac El Capitan -10.11.4 Selenium Version: 2.53.0 Browser: Google ChromeDriver 2.21 Browser Version: 49.0.2623.87 is the installed Chrome browser on my computer
My Pom.xml:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.53.0</version> </dependency>
Expected Behavior -
I should be able to resize a chrome window when its running in incognito mode.
Actual Behavior -
After starting the browser, an exception is thrown when I try to resize().
Note, if you remove the adding of the options to the desired capabilities, the code will work just fine (resizes correctly when not in incognito mode).
Steps to reproduce -
(In Java)
//Build Active Driver
ChromeOptions options = new ChromeOptions();
options.addArguments("-incognito");
LoggingPreferences loggingprefs = new LoggingPreferences();
loggingprefs.enable(LogType.BROWSER, Level.ALL);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingprefs); //Setup Logging
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
//Sets up Chrome for local usage.
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/chromedriver");
driver = new ChromeDriver(capabilities);
//Sets Script timeout to 5 seconds. Used for Synthetic Actions (executing of Javascript)
driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
//Set default Explicit wait times to default wait time (currently 30 seconds instead of 10).
waiter = new WebDriverWait(driver, defaultTimeOutInSeconds);
//Ignore StaleElementReferenceExceptions while waiting in addition to the NotFoundException.
waiter.ignoring(StaleElementReferenceException.class);
//Create Javascript Executor object for directly executing Javascript in the browser.
js = (JavascriptExecutor) driver;
//Sets browser window size to 1280x1024
driver.manage().window().setSize(new Dimension(1280, 1024)); //Fails Here
When executing the last line, I get the following stack trace:
org.openqa.selenium.WebDriverException: unknown error: No current window JavaScript stack: Error: No current window at checkForExtensionError (chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/background.js:14:17) at Object.callback (chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/background.js:67:5) at safeCallbackApply (extensions::sendRequest:21:15) at handleResponse (extensions::sendRequest:72:7) (Session info: chrome=49.0.2623.110) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.4 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 148 milliseconds Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46' System info: host: 'MacBook-Pro.local', ip: '10.0.21.150', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.8.0_60' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/_3/1bmspbg951b41lnrh70jp8_c0000gn/T/.org.chromium.Chromium.1700q1}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.110, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 3f4e4ad8de0c282b79e73e39699caec1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:891)
try this code to resize window on MAC:
Point targetPosition = new Point(0, 0);
driver.manage().window().setPosition(targetPosition);
java.awt.Dimension screenSize = Toolkit.getDefaultToolkit()
.getScreenSize();
int width = (int) screenSize.getWidth();
int height = (int) screenSize.getHeight();
if (LOG.isDebugEnabled()) {
LOG.debug("Screen resolution is: " + width + " x " + height);
}
Dimension targetSize = new Dimension(width, height);
driver.manage().window().setSize(targetSize);
what is LOG.debug? I cannot import this.
Just going to use console output....
I am using import java.awt.Toolkit; for Toolkit
Doesn't get that far - now fails on driver.manage().window().setPosition(targetPosition); with the same error message
org.openqa.selenium.WebDriverException: unknown error: No current window JavaScript stack: Error: No current window at checkForExtensionError (chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/background.js:14:17) at Object.callback (chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/background.js:67:5) at safeCallbackApply (extensions::sendRequest:21:15) at handleResponse (extensions::sendRequest:72:7) (Session info: chrome=49.0.2623.110) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.4 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 135 milliseconds Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46' System info: host: 'MacBook-Pro.local', ip: '10.0.21.150', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.8.0_60' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=/var/folders/_3/1bmspbg951b41lnrh70jp8_c0000gn/T/.org.chromium.Chromium.dKvqhx}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=49.0.2623.110, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 791e080f8c1d95ee7d965cf2709ec102 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setPosition(RemoteWebDriver.java:902)
for chromedriver issues please log them on the chromedriver project:
https://bugs.chromium.org/p/chromedriver/issues/list
Hi @lukeis,
I know that this is a pretty old issue , but can you please reopen it?
I've got the same problem today with the latest version which is in the master using a selenium grid with selenium hub and two chrome node. I've build the hub and chrome_debug Docker images
OS: Ubuntu 16.04 Selenium: 3.2.0 Chromedriver: 2.28
My test uses the incognito mode and I'm also setting the screen size. I've also noted that some other commands do not get executed properly.
I've did some research and some testing and I have noticed on the extensions page "chrome://extensions" that the "Chrome Automation Extension" is used to control the browser. The problem with setting the windows size is because this extension is not enabled in incognito mode.
I've tried pausing my test and click on the "Allow in incognito" checkbox, hoping that the setting will be saved, but it was not.
I guess the extension configuration is loaded from some other place. I also had started my tests with disabled extensions at first, but that when I saw that the chrome automation extension is being used, removed that from my browser capabilities configuration.
I think that we should at least add a description in the readme file that the selenium tests which are run in chrome will not run if chrome is started in incognito mode and with disabled extensions.
If test in incognito mode should be enabled, the chrome configuration should be adjusted so that the Chrome Automation Extension is active in incognito mode as well.
Best Regards, Jovan
@chombium no, the bug belongs to the chromedriver project. I'd suggest logging a bug with them, link in previous comment.
@lukeis thanks for the suggestion. I thought that there is some kind of configuration how the browser is started, but now I see that that's not the case.