selenium
selenium copied to clipboard
[🐛 Bug]: Selenium 4 WebSocket exception during performing basic authorization C#
What happened?
Hello, currently we are under investigation of the possibility to use Selenium 4 on our project and we are faced with the next issue: During performing the basic authorization, authorization is passing successfully but at the same time we have the next exception
There is already one outstanding 'SendAsync' call for this WebSocket instance. ReceiveAsync and SendAsync can be called simultaneously, but at most one outstanding operation for each of them is allowed at the same time.
Could you please take a look at this issue?
How can we reproduce the issue?
static void Main(string[] args)
{
var options = new ChromeOptions();
var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(2));
NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
{
UriMatcher = d => d.Host.Contains("jigsaw.w3.org"),
Credentials = new PasswordCredentials("guest", "guest")
};
var networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(handler);
networkInterceptor.StartMonitoring();
driver.Navigate().GoToUrl("https://jigsaw.w3.org/HTTP/Basic/");
networkInterceptor.StopMonitoring();
driver.Quit();
}
Relevant log output
Starting ChromeDriver 95.0.4638.69 (6a1600ed572fedecd573b6c2b90a22fe6392a410-refs/branch-heads/4638@{#984}) on port 61026
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
DevTools listening on ws://127.0.0.1:61029/devtools/browser/046fbea2-493a-4b0e-89a4-e0390b253469
[15732:36144:1118/170820.587:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
[15732:37544:1118/170820.587:ERROR:device_event_log_impl.cc(214)] [17:08:20.587] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[15732:36144:1118/170820.587:ERROR:chrome_browser_main_extra_parts_metrics.cc(233)] crbug.com/1216328: Checking Bluetooth availability ended.
[15732:36144:1118/170820.588:ERROR:chrome_browser_main_extra_parts_metrics.cc(236)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.
[15732:36144:1118/170820.596:ERROR:chrome_browser_main_extra_parts_metrics.cc(240)] crbug.com/1216328: Checking default browser status ended.
Unhandled Exception:
Unhandled Exception: System.InvalidOperationException: There is already one outstanding 'SendAsync' call for this WebSocket instance. ReceiveAsync and SendAsync can be called simultaneously, but at most one outstanding operation for each of them is allowed at the same time.
at System.Net.WebSockets.WebSocketBase.<SendAsyncCore>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at OpenQA.Selenium.DevTools.DevToolsSession.<SendCommand>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.DevTools.DevToolsSession.<SendCommand>d__34`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.DevTools.V95.Fetch.FetchAdapter.<ContinueRequest>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.DevTools.V95.V95Network.<ContinueResponseWithoutModification>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at OpenQA.Selenium.NetworkManager.<OnResponsePaused>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
System.Net.WebSockets.WebSocketException: The 'System.Net.WebSockets.InternalClientWebSocket' instance cannot be used for communication because it has been transitioned into the 'Aborted' state. ---> System.Net.WebSockets.WebSocketException: The 'System.Net.WebSockets.InternalClientWebSocket' instance cannot be used for communication because it has been transitioned into the 'Aborted' state.
at System.Net.WebSockets.WebSocketProtocolComponent.ThrowIfSessionHandleClosed(WebSocketBase webSocket)
at System.Net.WebSockets.WebSocketProtocolComponent.WebSocketGetAction(WebSocketBase webSocket, ActionQueue actionQueue, Buffer[] dataBuffers, UInt32& dataBufferCount, Action& action, BufferType& bufferType, IntPtr& actionContext)
at System.Net.WebSockets.WebSocketBase.WebSocketOperation.<Process>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.WebSockets.WebSocketBase.<SendAsyncCore>d__47.MoveNext()
--- End of inner exception stack trace ---
at System.Net.WebSockets.WebSocketBase.ThrowIfAborted(Boolean aborted, Exception innerException)
at System.Net.WebSockets.WebSocketBase.ThrowIfConvertibleException(String methodName, Exception exception, CancellationToken cancellationToken, Boolean aborted)
at System.Net.WebSockets.WebSocketBase.<SendAsyncCore>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at OpenQA.Selenium.DevTools.DevToolsSession.<SendCommand>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.DevTools.DevToolsSession.<SendCommand>d__34`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.DevTools.V95.Fetch.FetchAdapter.<ContinueRequest>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at OpenQA.Selenium.DevTools.V95.V95Network.<ContinueResponseWithoutModification>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at OpenQA.Selenium.NetworkManager.<OnResponsePaused>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Operating System
Windows 10
Selenium version
Selenium 4.0.0, .Net Framework 4.7.2 (C# 8)
What are the browser(s) and version(s) where you see this issue?
Chrome 95
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 95.0.4638.69
Are you using Selenium Grid?
no
@lopukhDA, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template
label.
If the issue is a question, add the I-question
label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted
label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C),
add the applicable G-*
label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer
label.
Thank you!
@lopukhDA What happens if you use await networkInterceptor.StartMonitoring();
instead of using it without the await
as you've done here?
@jimevans Thanks for your suggestion, but it doesn't work. I have the same error.
@lopukhDA I absolutely cannot reproduce your issue in my environment, even copying and pasting your code into a new project. The only differences are that I'm using 4.1.0 of the .NET bindings and Chrome/chromedriver 96. However, I would encourage you to at least update to 4.0.1, which did contain some refactoring of how websocket communications are handled.
@jimevans I tried updating selenium to version 4.1 and chrome to 96 but it didn't work for me
https://github.com/lopukhDA/Selenium4_WebSocket_Exception
Can you try the same experiment using .NET 5 as the framework version to see if it’s an issue inside .NET? That’s not a solution, or even a workaround, I’m just trying to gather appropriate data.
@jimevans Yes, you are correct, this code does work with .NET Core 5, but does not work with .NET Framework 4.7.2.
@lopukhDA just wondering, is this still valid on 4.4.0?
Facing similar problems with Selenium.WebDriver 4.5.1 in a .NET Framework 4.7.2 test project. Though I don't use authentication but use network interception, there is a chance that the problem has a wider scope. According to experience of me and my other colleagues (including those who experiment specifically with authentication) there are general problems with CDP WebSocket handling. Everyone who has incorporated WebDriver's Network
into .NET Framework tests are facing freezes, slowdowns and intermittent failures up to things like Error while creating session with the driver service. Stopping driver service: Driver server process died prematurely.
(our definite winner).
Still broken? :(
Supporting .NET Framework with websocket features is unfortunately a low priority for us at this point. The overall BiDi implementation for this language needs some updates, and that might fix things for 4.7, or it might might include a complete rewrite of the .NET bindings to make all the libraries Async. We'll update when we have an idea of which direction we're going with it.
this way maybe work, it's work for me.
driver.Navigate().GoToUrl("https://....com/app/my-clients/created");
driver.FindElement(By.TagName("Button")).Click();
Task.Run(async () => {
NetworkManager manager = new NetworkManager(driver);
manager.NetworkRequestSent += Network_NetworkRequestSent;
await manager.StartMonitoring();
});
Hi @titusfortner is there any update about this issue?
No updates.
TPAC is in a few weeks and our primary lead on BiDi work will return from leave in a few weeks, so I'm expecting us to have a long conversation about where we are going soon.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.