Skip to content

Commit ed35158

Browse files
committed
And from context
1 parent 34377ba commit ed35158

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,50 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2525

2626
public class BrowsingContextNetworkModule(BrowsingContext context, NetworkModule networkModule)
2727
{
28-
public async Task<Intercept> InterceptRequestAsync(Func<BeforeRequestSentEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
28+
public async Task<Intercept> InterceptRequestAsync(Func<InterceptedRequest, Task> handler, InterceptRequestOptions? options = null)
2929
{
30-
AddInterceptOptions addInterceptOptions = new(interceptOptions)
30+
AddInterceptOptions addInterceptOptions = new(options)
3131
{
3232
Contexts = [context]
3333
};
3434

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

37-
await intercept.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);
37+
await intercept.OnBeforeRequestSentAsync(
38+
async req => await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator)),
39+
new BrowsingContextsSubscriptionOptions(null) { Contexts = [context] }).ConfigureAwait(false);
3840

3941
return intercept;
4042
}
4143

42-
public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
44+
public async Task<Intercept> InterceptResponseAsync(Func<InterceptedResponse, Task> handler, InterceptResponseOptions? options = null)
4345
{
44-
AddInterceptOptions addInterceptOptions = new(interceptOptions)
46+
AddInterceptOptions addInterceptOptions = new(options)
4547
{
4648
Contexts = [context]
4749
};
4850

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

51-
await intercept.OnResponseStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);
53+
await intercept.OnResponseStartedAsync(
54+
async res => await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response)),
55+
new BrowsingContextsSubscriptionOptions(null) { Contexts = [context] }).ConfigureAwait(false);
5256

5357
return intercept;
5458
}
5559

56-
public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task> handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
60+
public async Task<Intercept> InterceptAuthAsync(Func<InterceptedAuth, Task> handler, InterceptAuthOptions? options = null)
5761
{
58-
AddInterceptOptions addInterceptOptions = new(interceptOptions)
62+
AddInterceptOptions addInterceptOptions = new(options)
5963
{
6064
Contexts = [context]
6165
};
6266

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

65-
await intercept.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }).ConfigureAwait(false);
69+
await intercept.OnAuthRequiredAsync(
70+
async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response)),
71+
new BrowsingContextsSubscriptionOptions(null) { Contexts = [context] }).ConfigureAwait(false);
6672

6773
return intercept;
6874
}
@@ -127,3 +133,9 @@ public Task<Subscription> OnAuthRequiredAsync(Action<AuthRequiredEventArgs> hand
127133
return networkModule.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] });
128134
}
129135
}
136+
137+
public record InterceptRequestOptions : BrowsingContextAddInterceptOptions;
138+
139+
public record InterceptResponseOptions : BrowsingContextAddInterceptOptions;
140+
141+
public record InterceptAuthOptions : BrowsingContextAddInterceptOptions;

0 commit comments

Comments
 (0)