"WebDriver:SwitchToWindow" fails with "TypeError: this.args is null" when print preview is open
Categories
(Remote Protocol :: Marionette, defect, P3)
Tracking
(Not tracked)
People
(Reporter: HSerg, Unassigned)
References
Details
(Whiteboard: [webdriver:backlog])
Steps to reproduce:
Trying to switch to a window with opened print preview.
Windows 11, Firefox 132.0.2 (64-bit), GeckoDriver 0.34.0 (64-bit), Selenium Java 4.26.0
import org.openqa.selenium.WindowType;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirefoxStackOverflowError {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
try {
String firstWindow = driver.getWindowHandle();
driver.executeScript("setTimeout(function () { window.print(); }, 300);");
Thread.sleep(2000);
driver.switchTo().newWindow(WindowType.WINDOW);
driver.switchTo().window(firstWindow);
} catch (Exception e) {
e.printStackTrace();
} finally {
driver.quit();
}
}
}
Actual results:
Exception in thread "main" java.lang.StackOverflowError
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:553)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:592)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:596)
at org.openqa.selenium.remote.RemoteWebDriver.getWindowHandles(RemoteWebDriver.java:443)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1124)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:1125)
...
1732152379745 geckodriver INFO Listening on 127.0.0.1:55555
1732152388147 webdriver::server DEBUG -> POST /session {
"capabilities": {
"firstMatch": [
{
}
]
}
}
1732152388148 geckodriver::capabilities DEBUG Trying to read firefox version from ini files
1732152388148 geckodriver::capabilities DEBUG Found version 132.0.2
1732152388162 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "-no-remote" "-profile" "C:\\Users\\user\\AppData\\Local\\Temp\\rust_mozprofileCzAn5V"
1732152388168 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1
1732152388168 geckodriver::browser TRACE Failed to open C:\Users\user\AppData\Local\Temp\rust_mozprofileCzAn5V\MarionetteActivePort
1732152388168 geckodriver::marionette TRACE Retrying in 100ms
console.warn: services.settings: Ignoring preference override of remote settings server
console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
1732152388268 geckodriver::browser TRACE Failed to open C:\Users\user\AppData\Local\Temp\rust_mozprofileCzAn5V\MarionetteActivePort
1732152388268 geckodriver::marionette TRACE Retrying in 100ms
1732152388363 Marionette INFO Marionette enabled
...
1732152388504 Marionette INFO Listening on port 49416
1732152388506 Marionette DEBUG Marionette is listening
Read port: 49416
1732152388590 Marionette DEBUG Accepted connection 0 from 127.0.0.1:49421
1732152388598 geckodriver::marionette DEBUG Connection to Marionette established on 127.0.0.1:49416.
1732152388605 Marionette DEBUG 0 -> [0,1,"WebDriver:NewSession",{}]
1732152388607 Marionette DEBUG Waiting for initial application window
1732152389881 Marionette TRACE Received observer notification browser-idle-startup-tasks-finished
1732152389883 RemoteAgent TRACE [8] ProgressListener Start: expectNavigation=false resolveWhenStarted=false unloadTimeout=5000 waitForExplicitStart=false
1732152389883 RemoteAgent TRACE [8] ProgressListener Setting unload timer (5000ms)
1732152389884 RemoteAgent TRACE [8] Wait for initial navigation: isInitial=false, isLoadingDocument=false
1732152389884 RemoteAgent TRACE [8] Document already finished loading: about:blank
1732152389884 RemoteAgent TRACE [8] ProgressListener Stop: has error=false url=about:blank
1732152389890 Marionette DEBUG 0 <- [1,1,null,{"sessionId":"52f5425f-f6dc-4093-8bc6-f37af2a5a748","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"132.0.2","platformName":"windows","unhandledPromptBehavior":"dismiss and notify","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0","moz:buildID":"20241110231641","moz:headless":false,"moz:platformVersion":"10.0","moz:processID":50960,"moz:profile":"C:\\Users\\user\\AppData\\Local\\Temp\\rust_mozprofileCzAn5V","moz:shutdownTimeout":60000,"pageLoadStrategy":"normal","timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"setWindowRect":true,"strictFileInteractability":false,"moz:accessibilityChecks":false,"moz:webdriverClick":true,"moz:windowless":false,"proxy":{}}}]
1732152389893 webdriver::server DEBUG <- 200 OK {"value":{"sessionId":"52f5425f-f6dc-4093-8bc6-f37af2a5a748","capabilities":{"acceptInsecureCerts":false,"browserNa ... avior":"dismiss and notify","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0"}}}
1732152389939 webdriver::server DEBUG -> GET /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window
1732152389946 Marionette DEBUG 0 -> [0,2,"WebDriver:GetWindowHandle",{}]
1732152389947 Marionette DEBUG 0 <- [1,2,null,{"value":"3d77ef0d-f006-45b7-9da0-0b334080c500"}]
1732152389947 webdriver::server DEBUG <- 200 OK {"value":"3d77ef0d-f006-45b7-9da0-0b334080c500"}
1732152389950 webdriver::server DEBUG -> POST /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/execute/sync {
"script": "setTimeout(function () { window.print(); }, 300);",
"args": [
]
}
1732152389951 Marionette DEBUG 0 -> [0,3,"WebDriver:ExecuteScript",{"args":[],"script":"setTimeout(function () { window.print(); }, 300);"}]
1732152389953 RemoteAgent TRACE WebDriverProcessData actor created for PID 48980
1732152389954 Marionette TRACE [8] MarionetteCommands actor created for window id 8589934593
1732152389956 Marionette DEBUG 0 <- [1,3,null,{"value":null}]
1732152389956 webdriver::server DEBUG <- 200 OK {"value":null}
1732152391969 webdriver::server DEBUG -> GET /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window
1732152391970 Marionette DEBUG 0 -> [0,4,"WebDriver:GetWindowHandle",{}]
1732152391970 Marionette DEBUG 0 <- [1,4,null,{"value":"3d77ef0d-f006-45b7-9da0-0b334080c500"}]
1732152391970 webdriver::server DEBUG <- 200 OK {"value":"3d77ef0d-f006-45b7-9da0-0b334080c500"}
1732152391972 webdriver::server DEBUG -> POST /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window/new {
"type": "window"
}
1732152391972 Marionette DEBUG 0 -> [0,5,"WebDriver:NewWindow",{"type":"window"}]
1732152391980 RemoteAgent TRACE Received observer notification domwindowopened
1732152392076 Marionette TRACE Received observer notification browser-delayed-startup-finished
1732152392076 RemoteAgent TRACE [15] ProgressListener Start: expectNavigation=false resolveWhenStarted=false unloadTimeout=5000 waitForExplicitStart=false
1732152392076 RemoteAgent TRACE [15] ProgressListener Setting unload timer (5000ms)
1732152392076 RemoteAgent TRACE [15] Wait for initial navigation: isInitial=true, isLoadingDocument=false
1732152392102 RemoteAgent TRACE [15] ProgressListener Loading state: isStart=true isStop=false status=0x0, loadType=0x1
1732152392102 RemoteAgent TRACE [15] ProgressListener Started loading about:blank
1732152392103 RemoteAgent TRACE [15] ProgressListener Cleared the unload timer
1732152392109 RemoteAgent TRACE [15] ProgressListener Loading state: isStart=false isStop=true status=0x0, loadType=0x1
1732152392109 RemoteAgent TRACE [15] ProgressListener Stop: has error=false url=about:blank
1732152392109 Marionette DEBUG 0 <- [1,5,null,{"handle":"fe9e52c5-79c4-442c-ad81-966cc2cbe9eb","type":"window"}]
1732152392110 webdriver::server DEBUG <- 200 OK {"value":{"handle":"fe9e52c5-79c4-442c-ad81-966cc2cbe9eb","type":"window"}}
1732152392113 webdriver::server DEBUG -> POST /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window {
"handle": "fe9e52c5-79c4-442c-ad81-966cc2cbe9eb"
}
1732152392113 Marionette DEBUG 0 -> [0,6,"WebDriver:SwitchToWindow",{"handle":"fe9e52c5-79c4-442c-ad81-966cc2cbe9eb"}]
1732152392115 Marionette DEBUG 0 <- [1,6,null,{"value":null}]
1732152392117 webdriver::server DEBUG <- 200 OK {"value":null}
1732152392119 webdriver::server DEBUG -> POST /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window {
"handle": "3d77ef0d-f006-45b7-9da0-0b334080c500"
}
1732152392119 Marionette DEBUG 0 -> [0,7,"WebDriver:SwitchToWindow",{"handle":"3d77ef0d-f006-45b7-9da0-0b334080c500"}]
1732152392119 RemoteAgent TRACE Found open tab modal prompt
1732152392120 Marionette ERROR TypeError: this.args is null(chrome://remote/content/shared/Prompt.sys.mjs:118:16) JS Stack trace: get isWindowModal@Prompt.sys.mjs:118:16
GeckoDriver.prototype.setWindowHandle@driver.sys.mjs:1353:16
1732152392120 Marionette DEBUG 0 <- [1,7,{"error":"no such window","message":"Unable to locate window: 3d77ef0d-f006-45b7-9da0-0b334080c500","stacktrace":"RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8\nWebDriverError@chrome://remote/content/shared/webdriver/Er ... ebdriver/Errors.sys.mjs:679:5\nGeckoDriver.prototype.switchToWindow@chrome://remote/content/marionette/driver.sys.mjs:1282:11\n"},null]
1732152392121 webdriver::server DEBUG <- 404 Not Found {"value":{"error":"no such window","message":"Unable to locate window: 3d77ef0d-f006-45b7-9da0-0b334080c500" ... ver/Errors.sys.mjs:679:5\nGeckoDriver.prototype.switchToWindow@chrome://remote/content/marionette/driver.sys.mjs:1282:11\n"}}
1732152392130 webdriver::server DEBUG -> GET /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window
1732152392131 Marionette DEBUG 0 -> [0,8,"WebDriver:GetWindowHandle",{}]
1732152392131 Marionette DEBUG 0 <- [1,8,null,{"value":"3d77ef0d-f006-45b7-9da0-0b334080c500"}]
1732152392131 webdriver::server DEBUG <- 200 OK {"value":"3d77ef0d-f006-45b7-9da0-0b334080c500"}
1732152392133 webdriver::server DEBUG -> GET /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window/handles
1732152392133 Marionette DEBUG 0 -> [0,9,"WebDriver:GetWindowHandles",{}]
1732152392133 Marionette DEBUG 0 <- [1,9,null,["3d77ef0d-f006-45b7-9da0-0b334080c500","fe9e52c5-79c4-442c-ad81-966cc2cbe9eb"]]
1732152392133 webdriver::server DEBUG <- 200 OK {"value":["3d77ef0d-f006-45b7-9da0-0b334080c500","fe9e52c5-79c4-442c-ad81-966cc2cbe9eb"]}
1732152392135 webdriver::server DEBUG -> POST /session/52f5425f-f6dc-4093-8bc6-f37af2a5a748/window {
"handle": "3d77ef0d-f006-45b7-9da0-0b334080c500"
}
1732152392135 Marionette DEBUG 0 -> [0,10,"WebDriver:SwitchToWindow",{"handle":"3d77ef0d-f006-45b7-9da0-0b334080c500"}]
1732152392135 RemoteAgent TRACE Found open tab modal prompt
1732152392135 Marionette ERROR TypeError: this.args is null(chrome://remote/content/shared/Prompt.sys.mjs:118:16) JS Stack trace: get isWindowModal@Prompt.sys.mjs:118:16
GeckoDriver.prototype.setWindowHandle@driver.sys.mjs:1353:16
...
1732152281351 webdriver::server DEBUG -> GET /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window
1732152281351 webdriver::server DEBUG <- 200 OK {"value":"f82d5c35-3a01-4525-92e4-287f585cbb5b"}
1732152281351 webdriver::server DEBUG -> GET /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window/handles
1732152281351 webdriver::server DEBUG <- 200 OK {"value":["f82d5c35-3a01-4525-92e4-287f585cbb5b","717617a7-86c4-4b03-b437-69130e1270ec"]}
1732152281352 webdriver::server DEBUG -> POST /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window {
"handle": "f82d5c35-3a01-4525-92e4-287f585cbb5b"
}
1732152281352 webdriver::server DEBUG <- 404 Not Found {"value":{"error":"no such window","message":"Unable to locate window: f82d5c35-3a01-4525-92e4-287f585cbb5b" ... ver/Errors.sys.mjs:679:5\nGeckoDriver.prototype.switchToWindow@chrome://remote/content/marionette/driver.sys.mjs:1282:11\n"}}
1732152281353 webdriver::server DEBUG -> GET /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window
1732152281353 webdriver::server DEBUG <- 200 OK {"value":"f82d5c35-3a01-4525-92e4-287f585cbb5b"}
1732152281353 webdriver::server DEBUG -> GET /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window/handles
1732152281354 webdriver::server DEBUG <- 200 OK {"value":["f82d5c35-3a01-4525-92e4-287f585cbb5b","717617a7-86c4-4b03-b437-69130e1270ec"]}
1732152281354 webdriver::server DEBUG -> POST /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window {
"handle": "f82d5c35-3a01-4525-92e4-287f585cbb5b"
}
1732152281355 webdriver::server DEBUG <- 404 Not Found {"value":{"error":"no such window","message":"Unable to locate window: f82d5c35-3a01-4525-92e4-287f585cbb5b" ... ver/Errors.sys.mjs:679:5\nGeckoDriver.prototype.switchToWindow@chrome://remote/content/marionette/driver.sys.mjs:1282:11\n"}}
1732152281355 webdriver::server DEBUG -> GET /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window
1732152281355 webdriver::server DEBUG <- 200 OK {"value":"f82d5c35-3a01-4525-92e4-287f585cbb5b"}
1732152281356 webdriver::server DEBUG -> GET /session/10988a30-7864-42d3-b2d2-3d3616621fc9/window/handles
1732152281356 webdriver::server DEBUG <- 200 OK {"value":["f82d5c35-3a01-4525-92e4-287f585cbb5b","717617a7-86c4-4b03-b437-69130e1270ec"]}
1732152281359 webdriver::server DEBUG -> DELETE /session/10988a30-7864-42d3-b2d2-3d3616621fc9
1732152281637 webdriver::server DEBUG Teardown session
1732152281837 geckodriver::browser DEBUG Browser process stopped: exit code: 0
1732152281863 webdriver::server DEBUG <- 200 OK {"value":null}
Expected results:
Switching to the specified window without any errors/exceptions.
Reporter | ||
Comment 1•7 months ago
|
||
Also reported to https://github.com/SeleniumHQ/selenium/issues/14782
Comment 2•7 months ago
|
||
Thank you for the report. I've taken a look at the trace log and the interesting lines are:
1732152392119 Marionette DEBUG 0 -> [0,7,"WebDriver:SwitchToWindow",{"handle":"3d77ef0d-f006-45b7-9da0-0b334080c500"}]
1732152392119 RemoteAgent TRACE Found open tab modal prompt
The original window that you are trying to switch to again has a modal dialog open - which in your case is the print dialog. This is not a regular user prompt as usually handled by the WebDriver specification so this could indeed cause a problem. Did you try the same test with other browsers as well? What is their behavior? If you could do such a check I would appreciate given that I'm out some days and wont be able to do such checks as early as beginning of next week.
Updated•7 months ago
|
Reporter | ||
Comment 3•7 months ago
|
||
Chrome, Edge - successfully switches to the window with print preview without any errors.
Safari - no way to open the print dialog during an automation session.
Comment 4•7 months ago
|
||
Thanks for checking!
Here is a minimized Marionette test that reproduces the problem:
def test(self):
handle = self.marionette.current_window_handle
self.marionette.execute_script(
"setTimeout(function () { window.print(); }, 300);")
result = self.marionette.open(type="tab")
self.marionette.switch_to_window(result["handle"])
time.sleep(2)
self.marionette.switch_to_window(handle)
In the WebDriver specification we do not yet handle beforeprint
kind-of user prompts. Maybe we should оust treat them as normal user prompts, and allow to accept
or dismiss
them. Maybe that's what Chrome and Edge are doing.
So at the minimum we should fix the access to .args
argument so it's not null
. For that kind of dialog there is no window.Dialog
class available, and maybe it's related that it actually loads a HTML page (print.html).
Lets first check for the expected behavior.
Reporter | ||
Comment 5•7 months ago
|
||
Maybe that's what Chrome and Edge are doing.
From the Selenium's point of view - Chrome/Edge (or ChromeDriver/EdgeDriver) lock window with original page and add a extra window with url chrome://print
and print dialog content as regular html page. It is possible to switch between them, but part of the API becomes inaccessible (due to timeouts) for the locked window.
Reporter | ||
Comment 6•7 months ago
|
||
It was a pretty simple implementation for them - https://codereview.chromium.org/1162473006/
Comment 7•7 months ago
|
||
Note that this is custom behavior and not part of the WebDriver specification. The issue here is that it is conflating the window handles with ids that are not top-level browsing contexts (navigables) and as such will cause side effects. We will discuss that in our next triage meeting.
Comment 8•7 months ago
|
||
We discussed today and given there is no support for Print Preview
in the WebDriver specification I filed an issue to further discuss this kind of pop-up dialog in more detail with other stakeholders. The issue can be found at https://github.com/w3c/webdriver/issues/1862.
Until it's clear how to handle the Print Preview
we are not going to fix that type error.
Description
•