Skip to content

Commit 1092962

Browse files
committed
Annotate CDP as fully AOT-unsafe
1 parent f1fce52 commit 1092962

File tree

9 files changed

+52
-10
lines changed

9 files changed

+52
-10
lines changed

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Collections.ObjectModel;
25+
using System.Diagnostics.CodeAnalysis;
2526
using System.IO;
2627
using System.Threading.Tasks;
2728

@@ -278,6 +279,8 @@ public object ExecuteCdpCommand(string commandName, Dictionary<string, object> c
278279
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
279280
/// </summary>
280281
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
282+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
283+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
281284
public DevToolsSession GetDevToolsSession()
282285
{
283286
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = DevToolsSession.AutoDetectDevToolsProtocolVersion });
@@ -287,6 +290,8 @@ public DevToolsSession GetDevToolsSession()
287290
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
288291
/// </summary>
289292
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
293+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
294+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
290295
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
291296
{
292297
if (this.devToolsSession == null)
@@ -329,6 +334,8 @@ public DevToolsSession GetDevToolsSession(DevToolsOptions options)
329334
/// <param name="devToolsProtocolVersion">The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.</param>
330335
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
331336
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
337+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
338+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
332339
public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)
333340
{
334341
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = devToolsProtocolVersion });

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ namespace OpenQA.Selenium.DevTools
3434
/// Represents a WebSocket connection to a running DevTools instance that can be used to send
3535
/// commands and recieve events.
3636
///</summary>
37+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
38+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
3739
public class DevToolsSession : IDevToolsSession
3840
{
3941
/// <summary>
@@ -149,8 +151,6 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
149151
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
150152
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
151153
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
152-
[RequiresUnreferencedCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
153-
[RequiresDynamicCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
154154
public async Task<ICommandResponse<TCommand>> SendCommand<TCommand>(TCommand command, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
155155
where TCommand : ICommand
156156
{
@@ -184,8 +184,6 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
184184
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
185185
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
186186
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
187-
[RequiresUnreferencedCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
188-
[RequiresDynamicCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
189187
public async Task<ICommandResponse<TCommand>> SendCommand<TCommand>(TCommand command, string sessionId, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
190188
where TCommand : ICommand
191189
{
@@ -219,8 +217,6 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
219217
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
220218
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
221219
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
222-
[RequiresUnreferencedCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
223-
[RequiresDynamicCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
224220
public async Task<TCommandResponse> SendCommand<TCommand, TCommandResponse>(TCommand command, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
225221
where TCommand : ICommand
226222
where TCommandResponse : ICommandResponse<TCommand>

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
namespace OpenQA.Selenium.DevTools
2324
{
@@ -35,13 +36,17 @@ public interface IDevTools
3536
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
3637
/// </summary>
3738
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
39+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
40+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
3841
DevToolsSession GetDevToolsSession();
3942

4043
/// <summary>
4144
/// Creates a session to communicate with a browser using a specific version of the Developer Tools debugging protocol.
4245
/// </summary>
4346
/// <param name="options">The options for the DevToolsSession to use.</param>
4447
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
48+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
49+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
4550
DevToolsSession GetDevToolsSession(DevToolsOptions options);
4651

4752
/// <summary>
@@ -50,11 +55,15 @@ public interface IDevTools
5055
/// <param name="protocolVersion">The specific version of the Developer Tools debugging protocol to use.</param>
5156
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
5257
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
58+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
59+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
5360
DevToolsSession GetDevToolsSession(int protocolVersion);
5461

5562
/// <summary>
5663
/// Closes a DevTools session
5764
/// </summary>
65+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
66+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
5867
void CloseDevToolsSession();
5968
}
6069
}

dotnet/src/webdriver/DevTools/IDevToolsSession.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public interface IDevToolsSession : IDisposable
6060
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
6161
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
6262
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
63-
[RequiresUnreferencedCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
64-
[RequiresDynamicCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
63+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
64+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
6565
Task<ICommandResponse<TCommand>> SendCommand<TCommand>(TCommand command, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived)
6666
where TCommand : ICommand;
6767

@@ -75,8 +75,8 @@ Task<ICommandResponse<TCommand>> SendCommand<TCommand>(TCommand command, Cancell
7575
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
7676
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
7777
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
78-
[RequiresUnreferencedCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
79-
[RequiresDynamicCode("SendCommand is not compatible with trimming or AOT. Use the overload that takes JsonNode parameters instead")]
78+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
79+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
8080
Task<TCommandResponse> SendCommand<TCommand, TCommandResponse>(TCommand command, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived)
8181
where TCommand : ICommand
8282
where TCommandResponse : ICommandResponse<TCommand>;
@@ -90,6 +90,8 @@ Task<TCommandResponse> SendCommand<TCommand, TCommandResponse>(TCommand command,
9090
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
9191
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
9292
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
93+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
94+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
9395
Task<JsonElement?> SendCommand(string commandName, JsonNode @params, CancellationToken cancellationToken, int? millisecondsTimeout, bool throwExceptionIfResponseNotReceived);
9496
}
9597
}

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
namespace OpenQA.Selenium
@@ -77,12 +78,16 @@ public interface INetwork
7778
/// Asynchronously starts monitoring for network traffic.
7879
/// </summary>
7980
/// <returns>A task that represents the asynchronous operation.</returns>
81+
[RequiresUnreferencedCode("Network monitoring is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported")]
82+
[RequiresDynamicCode("Network monitoring is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported.")]
8083
Task StartMonitoring();
8184

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

dotnet/src/webdriver/JavaScriptEngine.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using OpenQA.Selenium.Internal;
2222
using System;
2323
using System.Collections.Generic;
24+
using System.Diagnostics.CodeAnalysis;
2425
using System.Globalization;
2526
using System.IO;
2627
using System.Linq;
@@ -32,6 +33,8 @@ namespace OpenQA.Selenium
3233
/// <summary>
3334
/// Provides methods allowing the user to manage settings in the browser's JavaScript engine.
3435
/// </summary>
36+
[RequiresUnreferencedCode("JavaScriptEngine is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported")]
37+
[RequiresDynamicCode("JavaScriptEngine is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported.")]
3538
public class JavaScriptEngine : IJavaScriptEngine
3639
{
3740
private readonly string MonitorBindingName = "__webdriver_attribute";

dotnet/src/webdriver/NetworkManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.DevTools;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Threading.Tasks;
2425

2526
namespace OpenQA.Selenium
@@ -38,6 +39,8 @@ public class NetworkManager : INetwork
3839
/// Initializes a new instance of the <see cref="NetworkManager"/> class.
3940
/// </summary>
4041
/// <param name="driver">The <see cref="IWebDriver"/> instance on which the network should be monitored.</param>
42+
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Warnings are added to StartMonitoring and StopMonitoring")]
43+
[UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "Warnings are added to StartMonitoring and StopMonitoring")]
4144
public NetworkManager(IWebDriver driver)
4245
{
4346
// Use of Lazy<T> means this exception won't be thrown until the user first
@@ -69,6 +72,8 @@ public NetworkManager(IWebDriver driver)
6972
/// Asynchronously starts monitoring for network traffic.
7073
/// </summary>
7174
/// <returns>A task that represents the asynchronous operation.</returns>
75+
[RequiresUnreferencedCode("NetworkManager is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported")]
76+
[RequiresDynamicCode("NetworkManager is currently implemented with CDP. When it is implemented with BiDi, AOT will be supported.")]
7277
public async Task StartMonitoring()
7378
{
7479
this.session.Value.Domains.Network.RequestPaused += OnRequestPaused;
@@ -83,6 +88,8 @@ public async Task StartMonitoring()
8388
/// Asynchronously stops monitoring for network traffic.
8489
/// </summary>
8590
/// <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.")]
8693
public async Task StopMonitoring()
8794
{
8895
this.session.Value.Domains.Network.ResponsePaused -= OnResponsePaused;

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.IO.Compression;
2727
using System.Linq;
2828
using System.Threading.Tasks;
29+
using System.Diagnostics.CodeAnalysis;
2930

3031
namespace OpenQA.Selenium.Remote
3132
{
@@ -426,6 +427,8 @@ public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelec
426427
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
427428
/// </summary>
428429
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
430+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
431+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
429432
public DevToolsSession GetDevToolsSession()
430433
{
431434
if (this.Capabilities.GetCapability(CapabilityType.BrowserName) is "firefox")
@@ -443,6 +446,8 @@ public DevToolsSession GetDevToolsSession()
443446
/// Creates a session to communicate with a browser using a Developer Tools debugging protocol.
444447
/// </summary>
445448
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
449+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
450+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
446451
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
447452
{
448453
if (options is null)
@@ -498,6 +503,8 @@ public DevToolsSession GetDevToolsSession(DevToolsOptions options)
498503
/// <param name="protocolVersion">The specific version of the Developer Tools debugging protocol to use.</param>
499504
/// <returns>The active session to use to communicate with the Developer Tools debugging protocol.</returns>
500505
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
506+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
507+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
501508
public DevToolsSession GetDevToolsSession(int protocolVersion)
502509
{
503510
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = protocolVersion });
@@ -576,6 +583,8 @@ public void DeleteDownloadableFiles()
576583
/// <summary>
577584
/// Closes a DevTools session.
578585
/// </summary>
586+
[RequiresUnreferencedCode("CDP is not compatible with trimming or AOT.")]
587+
[RequiresDynamicCode("CDP is not compatible with trimming or AOT.")]
579588
public void CloseDevToolsSession()
580589
{
581590
if (this.devToolsSession != null)

dotnet/src/webdriver/Response.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.Internal;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Globalization;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -210,6 +211,9 @@ public static Response FromErrorJson(string value)
210211
/// Returns this object as a JSON-encoded string.
211212
/// </summary>
212213
/// <returns>A JSON-encoded string representing this <see cref="Response"/> object.</returns>
214+
215+
[RequiresUnreferencedCode("Free-form JSON serialization.")]
216+
[RequiresDynamicCode("Free-form JSON serialization.")]
213217
public string ToJson()
214218
{
215219
return JsonSerializer.Serialize(this);

0 commit comments

Comments
 (0)