8000 [dotnet] use correct devtools session id after reinitialization (#13768) · SeleniumHQ/selenium@12ed6cc · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
[dotnet] use correct devtools session id after reinitialization (#13768)
Browse files Browse the repository at this point in the history
Fix regression issue, appeared in v4.17. Closing a tab breaks the devtools session

Fixes #13755
  • Loading branch information
schrufygroovy authored Apr 5, 2024
1 parent 38829c7 commit 12ed6cc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
16 changes: 8 additions & 8 deletions dotnet/src/webdriver/DevTools/DevToolsSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,15 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
//[DebuggerStepThrough]
public Task<JToken> SendCommand(string commandName, JToken commandParameters, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
public async Task<JToken> SendCommand(string commandName, JToken commandParameters, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
{
return SendCommand(commandName, ActiveSessionId, commandParameters, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
if (this.attachedTargetId == null)
{
LogTrace("Session not currently attached to a target; reattaching");
await this.InitializeSession().ConfigureAwait(false);
}

return await SendCommand(commandName, this.ActiveSessionId, commandParameters, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
}

/// <summary>
Expand All @@ -262,12 +268,6 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
millisecondsTimeout = Convert.ToInt32(CommandTimeout.TotalMilliseconds);
}

if (this.attachedTargetId == null)
{
LogTrace("Session not currently attached to a target; reattaching");
await this.InitializeSession().ConfigureAwait(false);
}

var message = new DevToolsCommandData(Interlocked.Increment(ref this.currentCommandId), sessionId, commandName, commandParameters);

if (this.connection != null && this.connection.IsActive)
Expand Down
32 changes: 32 additions & 0 deletions dotnet/test/common/DevTools/DevToolsTabsTest.cs