Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d0f063a
[dotnet] Avoid exceptions in cdp logging on file upload
RenderMichael Dec 28, 2024
cce9b94
Revert "[java] JSpecify annotations for wrappers (#14396)"
RenderMichael Jan 8, 2025
5ca2f54
Accept invalid UTF16 strings in DevTools JSON responses
RenderMichael Jan 8, 2025
e0679f4
Merge branch 'trunk' into devtools-file-upload
RenderMichael Jan 8, 2025
43fc198
Reapply "[java] JSpecify annotations for wrappers (#14396)"
RenderMichael Jan 8, 2025
1010456
Revert "[dotnet] Avoid exceptions in cdp logging on file upload"
RenderMichael Jan 8, 2025
4bb41e9
[dotnet] Enable nullability on `DevToolsSessionDomains`
RenderMichael Jan 8, 2025
253e135
Merge branch 'trunk' into devtools-file-upload
RenderMichael Jan 8, 2025
187dcc4
Move DevTools JSON serialization options to base non-generated `DevTo…
RenderMichael Jan 8, 2025
cb16a00
Merge branch 'devtools-file-upload' of https://github.com/RenderMicha…
RenderMichael Jan 8, 2025
5a2bd35
remove accidental push
RenderMichael Jan 8, 2025
442b392
remove unnecessary diff
RenderMichael Jan 8, 2025
1588354
Use explicit type instead of `var`
RenderMichael Jan 8, 2025
6c09888
PR feedback
RenderMichael Jan 8, 2025
0f0ed1b
Apply suggestions from code review
RenderMichael Jan 8, 2025
4ae49b4
Move DevTools JSON options to a separate type
RenderMichael Jan 8, 2025
9fb4159
PR feedback
RenderMichael Jan 8, 2025
c3e257f
PR feedback
RenderMichael Jan 8, 2025
4d11714
Change `DevToolsJsonOptions` instance to `Default`
RenderMichael Jan 8, 2025
55f69d5
Improve comment in `StringConverter`
RenderMichael Jan 8, 2025
f13a6d9
Add file headers
RenderMichael Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions dotnet/src/webdriver/DevTools/DevToolsSessionDomains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
// under the License.
// </copyright>

using System;
using System.ComponentModel;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -26,6 +34,15 @@ public abstract class DevToolsSessionDomains
{
private CommandResponseTypeMap responseTypeMap = new CommandResponseTypeMap();

[EditorBrowsable(EditorBrowsableState.Never)] // Generated code use only
internal static JsonSerializerOptions DevToolsSerializerOptions { get; } = new JsonSerializerOptions()
{
Converters =
{
new InvalidUtf16Converter(),
}
};

/// <summary>
/// Initializes a new instance of the <see cref="DevToolsSessionDomains"/> class.
/// </summary>
Expand All @@ -43,5 +60,29 @@ protected DevToolsSessionDomains()
/// Populates the command response type map.
/// </summary>
protected abstract void PopulateCommandResponseTypeMap();

private sealed class InvalidUtf16Converter : JsonConverter<string>
{
public override bool HandleNull => true;

public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
try
{
return reader.GetString();
}
catch (InvalidOperationException)
{
var bytes = reader.ValueSpan;
var sb = new StringBuilder(bytes.Length);
foreach (byte b in bytes)
sb.Append(Convert.ToChar(b));
return sb.ToString();
}
}

public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) =>
writer.WriteStringValue(value);
}
}
}
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/cdp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add an entry for version `<N>` to the `SupportedDevToolsVersions` dictionary ini
6. In [`//dotnet/src/webdriver:WebDriver.csproj.prebuild.cmd`](https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/WebDriver.csproj.prebuild.cmd),
add the following block (substituting the proper value for `<N>`):

```
```bash
if not exist "%1..\..\..\bazel-bin\dotnet\src\webdriver\cdp\v<N>\DevToolsSessionDomains.cs" (
echo Generating CDP code for version <N>
pushd "%1..\..\.."
Expand All @@ -29,7 +29,7 @@ if not exist "%1..\..\..\bazel-bin\dotnet\src\webdriver\cdp\v<N>\DevToolsSessio
7. In [`//dotnet/src/webdriver:WebDriver.csproj.prebuild.sh`](https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/WebDriver.csproj.prebuild.sh),
add the following block (substituting the proper value for `<N>`):

```
```bash
if [[ ! -f "$1../../../bazel-bin/dotnet/src/webdriver/cdp/v<N>/DevToolsSessionDomains.cs" ]]
then
echo "Generating CDP code for version <N>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace {{rootNamespace}}.{{domain.Name}}
if (m_eventMap.ContainsKey(e.EventName))
{
var eventData = m_eventMap[e.EventName];
var eventArgs = e.EventData.Deserialize(eventData.EventArgsType);
var eventArgs = e.EventData.Deserialize(eventData.EventArgsType, OpenQA.Selenium.DevTools.DevToolsSessionDomains.DevToolsSerializerOptions);
eventData.EventInvoker(eventArgs);
}
}
Expand Down