Skip to content

Commit 144751b

Browse files
RenderMichaelsandeepsuryaprasad
authored andcommitted
[dotnet] Annotate CDP as AOT-unsafe (SeleniumHQ#14637)
* [dotnet] Add trimming attributes, address some trim warnings * Make DomainType struct readonly * center preprocessor directives on .net 8+ * Add file header to `TrimmingAttributes.cs` * Tweak #if location * Hide `Assembly.CodeBase` from .NET 8 compilation * Remove changes from `DevToolsDomains` * remove remaining changes from `DevToolsDomains` * Annotate CDP as AOT-unsafe * Annotate CDP as fully AOT-unsafe * Improve AOT incompatibility message
1 parent 2e27028 commit 144751b

File tree

12 files changed

+499
-1
lines changed

12 files changed

+499
-1
lines changed

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public void SetPermission(string permissionName, string permissionValue)
299299
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
300300
/// </summary>
301301
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
302+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
303+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
302304
public DevToolsSession GetDevToolsSession()
303305
{
304306
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = DevToolsSession.AutoDetectDevToolsProtocolVersion });
@@ -308,6 +310,8 @@ public DevToolsSession GetDevToolsSession()
308310
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
309311
/// </summary>
310312
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
313+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
314+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
311315
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
312316
{
313317
if (this.devToolsSession == null)
@@ -349,6 +353,8 @@ public DevToolsSession GetDevToolsSession(DevToolsOptions options)
349353
/// <param name="devToolsProtocolVersion">The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.</param>
350354
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
351355
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
356+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
357+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
352358
public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)
353359
{
354360
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = devToolsProtocolVersion });

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.Internal.Logging;
2121
using System;
2222
using System.Collections.Concurrent;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Globalization;
2425
using System.Net.Http;
2526
using System.Text.Json;
@@ -35,8 +36,12 @@ namespace OpenQA.Selenium.DevTools
3536
/// Represents a WebSocket connection to a running DevTools instance that can be used to send
3637
/// commands and receive events.
3738
///</summary>
39+
[RequiresUnreferencedCode(CDP_AOTIncompatibilityMessage)]
40+
[RequiresDynamicCode(CDP_AOTIncompatibilityMessage)]
3841
public class DevToolsSession : IDevToolsSession
3942
{
43+
internal const string CDP_AOTIncompatibilityMessage = "CDP is not compatible with trimming or AOT.";
44+
4045
/// <summary>
4146
/// A value indicating that the version of the DevTools protocol in use
4247
/// by the browser should be automatically detected.

dotnet/src/webdriver/DevTools/IDevTools.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using System;
21+
using System.Diagnostics.CodeAnalysis;
2122

2223
#nullable enable
2324

@@ -37,6 +38,8 @@ public interface IDevTools
3738
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
3839
/// </summary>
3940
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
41+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
42+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
4043
DevToolsSession GetDevToolsSession();
4144

4245
/// <summary>
@@ -45,6 +48,8 @@ public interface IDevTools
4548
/// <param name="options">The options for the DevToolsSession to use.</param>
4649
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
4750
/// <exception cref="ArgumentNullException">If <paramref name="options"/> is <see langword="null"/>.</exception>
51+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
52+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
4853
DevToolsSession GetDevToolsSession(DevToolsOptions options);
4954

5055
/// <summary>
@@ -53,11 +58,15 @@ public interface IDevTools
5358
/// <param name="protocolVersion">The specific version of the Developer Tools debugging protocol to use.</param>
5459
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
5560
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
61+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
62+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
5663
DevToolsSession GetDevToolsSession(int protocolVersion);
5764

5865
/// <summary>
5966
/// Closes a DevTools session
6067
/// </summary>
68+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
69+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
6170
void CloseDevToolsSession();
6271
}
6372
}

dotnet/src/webdriver/DevTools/IDevToolsSession.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using System;
21+
using System.Diagnostics.CodeAnalysis;
2122
using System.Text.Json;
2223
using System.Text.Json.Nodes;
2324
using System.Threading;
@@ -63,6 +64,8 @@ public interface IDevToolsSession : IDisposable
6364
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
6465
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
6566
/// <exception cref="ArgumentNullException">If <paramref name="command"/> is <see langword="null"/>.</exception>
67+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
68+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
6669
Task<ICommandResponse<TCommand>?> SendCommand<TCommand>(TCommand command, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived)
6770
where TCommand : ICommand;
6871

@@ -77,6 +80,8 @@ public interface IDevToolsSession : IDisposable
7780
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
7881
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
7982
/// <exception cref="ArgumentNullException">If <paramref name="command"/> is <see langword="null"/>.</exception>
83+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
84+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
8085
Task<TCommandResponse?> SendCommand<TCommand, TCommandResponse>(TCommand command, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived)
8186
where TCommand : ICommand
8287
where TCommandResponse : ICommandResponse<TCommand>;
@@ -91,6 +96,8 @@ public interface IDevToolsSession : IDisposable
9196
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
9297
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
9398
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
99+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
100+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
94101
Task<JsonElement?> SendCommand(string commandName, JsonNode @params, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived);
95102
}
96103
}

dotnet/src/webdriver/DevTools/Json/JsonEnumMemberConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
using System;
2121
using System.Collections.Generic;
22+
using System.Diagnostics.CodeAnalysis;
2223
using System.Linq;
2324
using System.Runtime.Serialization;
2425
using System.Text.Json;
@@ -28,7 +29,7 @@
2829

2930
namespace OpenQA.Selenium.DevTools.Json
3031
{
31-
internal sealed class JsonEnumMemberConverter<TEnum> : JsonConverter<TEnum>
32+
internal sealed class JsonEnumMemberConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TEnum> : JsonConverter<TEnum>
3233
where TEnum : struct, Enum
3334
{
3435
private readonly Dictionary<TEnum, string> _enumToString = new Dictionary<TEnum, string>();

dotnet/src/webdriver/INetwork.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using System;
21+
using System.Diagnostics.CodeAnalysis;
2122
using System.Threading.Tasks;
2223

2324
#nullable enable
@@ -79,12 +80,16 @@ public interface INetwork
7980
/// Asynchronously starts monitoring for network traffic.
8081
/// </summary>
8182
/// <returns>A task that represents the asynchronous operation.</returns>
83+
[RequiresUnreferencedCode("Network monitoring is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported")]
84+
[RequiresDynamicCode("Network monitoring is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported.")]
8285
Task StartMonitoring();
8386

8487
/// <summary>
8588
/// Asynchronously stops monitoring for network traffic.
8689
/// </summary>
8790
/// <returns>A task that represents the asynchronous operation.</returns>
91+
[RequiresUnreferencedCode("Network monitoring is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported")]
92+
[RequiresDynamicCode("Network monitoring is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported.")]
8893
Task StopMonitoring();
8994
}
9095
}

0 commit comments

Comments
 (0)