Skip to content

Commit 6f5141d

Browse files
committed
browser context proxyServer
1 parent 9b35736 commit 6f5141d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/cdp/cdp.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
319319

320320
inspector: Inspector,
321321
isolated_world: ?IsolatedWorld,
322+
http_proxy_before: ??std.Uri = null,
322323

323324
const Self = @This();
324325

@@ -373,6 +374,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
373374
self.node_registry.deinit();
374375
self.node_search_list.deinit();
375376
self.cdp.browser.notification.unregisterAll(self);
377+
378+
if (self.http_proxy_before) |prev_proxy| self.cdp.browser.http_client.http_proxy = prev_proxy;
376379
}
377380

378381
pub fn reset(self: *Self) void {

src/cdp/domains/target.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,30 @@ fn getBrowserContexts(cmd: anytype) !void {
6666
}
6767

6868
fn createBrowserContext(cmd: anytype) !void {
69+
const params = try cmd.params(struct {
70+
disposeOnDetach: bool = false,
71+
proxyServer: ?[]const u8 = null,
72+
proxyBypassList: ?[]const u8 = null,
73+
originsWithUniversalNetworkAccess: ?[]const []const u8 = null,
74+
});
75+
if (params) |p| {
76+
if (p.disposeOnDetach or p.proxyBypassList != null or p.originsWithUniversalNetworkAccess != null) std.debug.print("Target.createBrowserContext: Not implemented param set\n", .{});
77+
}
78+
6979
const bc = cmd.createBrowserContext() catch |err| switch (err) {
7080
error.AlreadyExists => return cmd.sendError(-32000, "Cannot have more than one browser context at a time"),
7181
else => return err,
7282
};
7383

84+
if (params) |p| {
85+
if (p.proxyServer) |proxy| {
86+
// For now the http client is not in the browser context so we assume there is just 1.
87+
bc.http_proxy_before = cmd.cdp.browser.http_client.http_proxy;
88+
const proxy_cp = try cmd.cdp.browser.http_client.allocator.dupe(u8, proxy);
89+
cmd.cdp.browser.http_client.http_proxy = try std.Uri.parse(proxy_cp);
90+
}
91+
}
92+
7493
return cmd.sendResult(.{
7594
.browserContextId = bc.id,
7695
}, .{});

0 commit comments

Comments
 (0)