diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index ed3388a4..27544063 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -320,6 +320,7 @@ pub fn BrowserContext(comptime CDP_T: type) type { inspector: Inspector, isolated_world: ?IsolatedWorld, + http_proxy_before: ??std.Uri = null, const Self = @This(); @@ -374,6 +375,8 @@ pub fn BrowserContext(comptime CDP_T: type) type { self.node_registry.deinit(); self.node_search_list.deinit(); self.cdp.browser.notification.unregisterAll(self); + + if (self.http_proxy_before) |prev_proxy| self.cdp.browser.http_client.http_proxy = prev_proxy; } pub fn reset(self: *Self) void { diff --git a/src/cdp/domains/target.zig b/src/cdp/domains/target.zig index c0d76ec0..5b2a4f73 100644 --- a/src/cdp/domains/target.zig +++ b/src/cdp/domains/target.zig @@ -66,11 +66,30 @@ fn getBrowserContexts(cmd: anytype) !void { } fn createBrowserContext(cmd: anytype) !void { + const params = try cmd.params(struct { + disposeOnDetach: bool = false, + proxyServer: ?[]const u8 = null, + proxyBypassList: ?[]const u8 = null, + originsWithUniversalNetworkAccess: ?[]const []const u8 = null, + }); + if (params) |p| { + if (p.disposeOnDetach or p.proxyBypassList != null or p.originsWithUniversalNetworkAccess != null) std.debug.print("Target.createBrowserContext: Not implemented param set\n", .{}); + } + const bc = cmd.createBrowserContext() catch |err| switch (err) { error.AlreadyExists => return cmd.sendError(-32000, "Cannot have more than one browser context at a time"), else => return err, }; + if (params) |p| { + if (p.proxyServer) |proxy| { + // For now the http client is not in the browser context so we assume there is just 1. + bc.http_proxy_before = cmd.cdp.browser.http_client.http_proxy; + const proxy_cp = try cmd.cdp.browser.http_client.allocator.dupe(u8, proxy); + cmd.cdp.browser.http_client.http_proxy = try std.Uri.parse(proxy_cp); + } + } + return cmd.sendResult(.{ .browserContextId = bc.id, }, .{});