Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorDeniedAsync(SetD
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new BrowserJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ public async Task<Subscription> OnUserPromptClosedAsync(Action<UserPromptClosedE
return await SubscribeAsync("browsingContext.userPromptClosed", handler, options, _jsonContext.UserPromptClosedEventArgs).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new InternalIdConverter(BiDi));
jsonSerializerOptions.Converters.Add(new HandleConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new InternalIdConverter(bidi));
jsonSerializerOptions.Converters.Add(new HandleConverter(bidi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new BrowsingContextJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<Interception> InterceptRequestAsync(Func<InterceptedRequest, T

var interceptResult = await networkModule.AddInterceptAsync([InterceptPhase.BeforeRequestSent], addInterceptOptions).ConfigureAwait(false);

Interception interception = new(context.BiDi, interceptResult.Intercept);
Interception interception = new(networkModule, interceptResult.Intercept);

await interception.OnBeforeRequestSentAsync(
async req => await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator, req.Intercepts)),
Expand All @@ -53,7 +53,7 @@ public async Task<Interception> InterceptResponseAsync(Func<InterceptedResponse,

var interceptResult = await networkModule.AddInterceptAsync([InterceptPhase.ResponseStarted], addInterceptOptions).ConfigureAwait(false);

Interception interception = new(context.BiDi, interceptResult.Intercept);
Interception interception = new(networkModule, interceptResult.Intercept);

await interception.OnResponseStartedAsync(
async res => await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response, res.Intercepts)),
Expand All @@ -71,7 +71,7 @@ public async Task<Interception> InterceptAuthAsync(Func<InterceptedAuth, Task> h

var interceptResult = await networkModule.AddInterceptAsync([InterceptPhase.AuthRequired], addInterceptOptions).ConfigureAwait(false);

Interception interception = new(context.BiDi, interceptResult.Intercept);
Interception interception = new(networkModule, interceptResult.Intercept);

await interception.OnAuthRequiredAsync(
async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response, auth.Intercepts)),
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public async Task<SetGeolocationOverrideResult> SetGeolocationPositionErrorOverr
return await ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options, _jsonContext.SetGeolocationOverrideCommand, _jsonContext.SetGeolocationOverrideResult).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new EmulationJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/BiDi/Input/InputModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public async Task<Subscription> OnFileDialogOpenedAsync(Action<FileDialogInfo> h
return await SubscribeAsync("input.fileDialogOpened", handler, options, _jsonContext.FileDialogInfo).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new HandleConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new HandleConverter(bidi));

_jsonContext = new InputJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
10 changes: 5 additions & 5 deletions dotnet/src/webdriver/BiDi/Log/LogModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public async Task<Subscription> OnEntryAddedAsync(Action<LogEntry> handler, Subs
return await SubscribeAsync("log.entryAdded", handler, options, _jsonContext.LogEntry).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new RealmConverter(BiDi));
jsonSerializerOptions.Converters.Add(new InternalIdConverter(BiDi));
jsonSerializerOptions.Converters.Add(new HandleConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new RealmConverter(bidi));
jsonSerializerOptions.Converters.Add(new InternalIdConverter(bidi));
jsonSerializerOptions.Converters.Add(new HandleConverter(bidi));

_jsonContext = new LogJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
7 changes: 2 additions & 5 deletions dotnet/src/webdriver/BiDi/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ namespace OpenQA.Selenium.BiDi;

public abstract class Module
{
protected BiDi BiDi { get; private set; } = null!;

private Broker Broker { get; set; } = null!;

protected Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options, JsonTypeInfo<TCommand> jsonCommandTypeInfo, JsonTypeInfo<TResult> jsonResultTypeInfo)
Expand All @@ -51,18 +49,17 @@ public Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Func<TEve
return Broker.SubscribeAsync(eventName, eventHandler, options, jsonTypeInfo);
}

protected abstract void Initialize(JsonSerializerOptions jsonSerializerOptions);
protected abstract void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions);

internal static TModule Create<TModule>(BiDi bidi, Broker broker, JsonSerializerOptions jsonSerializerOptions)
where TModule : Module, new()
{
TModule module = new()
{
BiDi = bidi,
Broker = broker
};

module.Initialize(jsonSerializerOptions);
module.Initialize(bidi, jsonSerializerOptions);

return module;
}
Expand Down
16 changes: 8 additions & 8 deletions dotnet/src/webdriver/BiDi/Network/NetworkModule.HighLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<Interception> InterceptRequestAsync(Func<InterceptedRequest, T
{
var interceptResult = await AddInterceptAsync([InterceptPhase.BeforeRequestSent], options).ConfigureAwait(false);

Interception interception = new(BiDi, interceptResult.Intercept);
Interception interception = new(this, interceptResult.Intercept);

await interception.OnBeforeRequestSentAsync(async req => await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator, req.Intercepts))).ConfigureAwait(false);

Expand All @@ -41,7 +41,7 @@ public async Task<Interception> InterceptResponseAsync(Func<InterceptedResponse,
{
var interceptResult = await AddInterceptAsync([InterceptPhase.ResponseStarted], options).ConfigureAwait(false);

Interception interception = new(BiDi, interceptResult.Intercept);
Interception interception = new(this, interceptResult.Intercept);

await interception.OnResponseStartedAsync(async res => await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response, res.Intercepts))).ConfigureAwait(false);

Expand All @@ -52,7 +52,7 @@ public async Task<Interception> InterceptAuthAsync(Func<InterceptedAuth, Task> h
{
var interceptResult = await AddInterceptAsync([InterceptPhase.AuthRequired], options).ConfigureAwait(false);

Interception interception = new(BiDi, interceptResult.Intercept);
Interception interception = new(this, interceptResult.Intercept);

await interception.OnAuthRequiredAsync(async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response, auth.Intercepts))).ConfigureAwait(false);

Expand Down Expand Up @@ -128,15 +128,15 @@ public Task ContinueAsync(ContinueWithAuthCancelCredentialsOptions? options = nu
}
}

public sealed record Interception(BiDi BiDi, Intercept Intercept) : IAsyncDisposable
public sealed record Interception(NetworkModule Network, Intercept Intercept) : IAsyncDisposable
{
IList<Subscription> OnBeforeRequestSentSubscriptions { get; } = [];
IList<Subscription> OnResponseStartedSubscriptions { get; } = [];
IList<Subscription> OnAuthRequiredSubscriptions { get; } = [];

public async Task RemoveAsync()
{
await BiDi.Network.RemoveInterceptAsync(Intercept).ConfigureAwait(false);
await Network.RemoveInterceptAsync(Intercept).ConfigureAwait(false);

foreach (var subscription in OnBeforeRequestSentSubscriptions)
{
Expand All @@ -156,21 +156,21 @@ public async Task RemoveAsync()

public async Task OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, SubscriptionOptions? options = null)
{
var subscription = await BiDi.Network.OnBeforeRequestSentAsync(async args => await Filter(args, handler), options).ConfigureAwait(false);
var subscription = await Network.OnBeforeRequestSentAsync(async args => await Filter(args, handler), options).ConfigureAwait(false);

OnBeforeRequestSentSubscriptions.Add(subscription);
}

public async Task OnResponseStartedAsync(Func<ResponseStartedEventArgs, Task> handler, SubscriptionOptions? options = null)
{
var subscription = await BiDi.Network.OnResponseStartedAsync(async args => await Filter(args, handler), options).ConfigureAwait(false);
var subscription = await Network.OnResponseStartedAsync(async args => await Filter(args, handler), options).ConfigureAwait(false);

OnResponseStartedSubscriptions.Add(subscription);
}

public async Task OnAuthRequiredAsync(Func<AuthRequiredEventArgs, Task> handler, SubscriptionOptions? options = null)
{
var subscription = await BiDi.Network.OnAuthRequiredAsync(async args => await Filter(args, handler), options).ConfigureAwait(false);
var subscription = await Network.OnAuthRequiredAsync(async args => await Filter(args, handler), options).ConfigureAwait(false);

OnAuthRequiredSubscriptions.Add(subscription);
}
Expand Down
10 changes: 5 additions & 5 deletions dotnet/src/webdriver/BiDi/Network/NetworkModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ public async Task<Subscription> OnAuthRequiredAsync(Action<AuthRequiredEventArgs
return await SubscribeAsync("network.authRequired", handler, options, _jsonContext.AuthRequiredEventArgs).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new CollectorConverter(BiDi));
jsonSerializerOptions.Converters.Add(new InterceptConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new CollectorConverter(bidi));
jsonSerializerOptions.Converters.Add(new InterceptConverter(bidi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new NetworkJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public async Task<SetPermissionResult> SetPermissionAsync(PermissionDescriptor d
return await ExecuteCommandAsync(new SetPermissionCommand(@params), options, _jsonContext.SetPermissionCommand, _jsonContext.SetPermissionResult).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new PermissionsJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
12 changes: 6 additions & 6 deletions dotnet/src/webdriver/BiDi/Script/ScriptModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ public async Task<Subscription> OnRealmDestroyedAsync(Action<RealmDestroyedEvent
return await SubscribeAsync("script.realmDestroyed", handler, options, _jsonContext.RealmDestroyedEventArgs).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new PreloadScriptConverter(BiDi));
jsonSerializerOptions.Converters.Add(new RealmConverter(BiDi));
jsonSerializerOptions.Converters.Add(new InternalIdConverter(BiDi));
jsonSerializerOptions.Converters.Add(new HandleConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new PreloadScriptConverter(bidi));
jsonSerializerOptions.Converters.Add(new RealmConverter(bidi));
jsonSerializerOptions.Converters.Add(new InternalIdConverter(bidi));
jsonSerializerOptions.Converters.Add(new HandleConverter(bidi));

_jsonContext = new ScriptJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/BiDi/Session/SessionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public async Task<EndResult> EndAsync(EndOptions? options = null)
return await ExecuteCommandAsync(new EndCommand(), options, _jsonContext.EndCommand, _jsonContext.EndResult).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new SessionJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/BiDi/Storage/StorageModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public async Task<SetCookieResult> SetCookieAsync(PartialCookie cookie, SetCooki
return await ExecuteCommandAsync(new SetCookieCommand(@params), options, _jsonContext.SetCookieCommand, _jsonContext.SetCookieResult).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi));
jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi));
jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi));

_jsonContext = new StorageJsonSerializerContext(jsonSerializerOptions);
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public async Task<UninstallResult> UninstallAsync(Extension extension, Uninstall
return await ExecuteCommandAsync(new UninstallCommand(@params), options, _jsonContext.UninstallCommand, _jsonContext.UninstallResult).ConfigureAwait(false);
}

protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)
{
jsonSerializerOptions.Converters.Add(new WebExtensionConverter(BiDi));
jsonSerializerOptions.Converters.Add(new WebExtensionConverter(bidi));

_jsonContext = new WebExtensionJsonSerializerContext(jsonSerializerOptions);
}
Expand Down