From 920ae57f9ae41f841fd52c0fde7ca222baaef0fa Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 13 Apr 2026 11:16:33 +0200 Subject: [PATCH] cdp: ignore UA containing Mozilla Instead of returning an error when the UA contains Mozilla, we ignore the option and log an message. --- src/cdp/domains/emulation.zig | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cdp/domains/emulation.zig b/src/cdp/domains/emulation.zig index db8d3a41..7248b76c 100644 --- a/src/cdp/domains/emulation.zig +++ b/src/cdp/domains/emulation.zig @@ -95,7 +95,11 @@ pub fn setUserAgentOverride(cmd: *CDP.Command) !void { // Reject user agents containing "mozilla" (case-insensitive) if (std.ascii.indexOfIgnoreCase(ua, "mozilla") != null) { - return cmd.sendError(-32602, "User agent must not contain Mozilla", .{}); + // go-rod client automatically set a Mozilla/ user agent. + // Since we don't want to stop this client to work, let's ignore the + // new user-agent and add a log instead. + log.warn(.not_implemented, "Emulation.setUserAgentOverride", .{ .param = "userAgent", .value = ua, .info = "User agent must not contain Mozilla" }); + return cmd.sendResult(null, .{}); } const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; @@ -122,7 +126,7 @@ test "cdp.Emulation: setUserAgentOverride with valid user agent" { try ctx.expectSentResult(null, .{ .id = 1 }); } -test "cdp.Emulation: setUserAgentOverride rejects mozilla" { +test "cdp.Emulation: setUserAgentOverride ignores mozilla" { var ctx = try testing.context(); defer ctx.deinit(); _ = try ctx.loadBrowserContext(.{ .id = "BID-UA2" }); @@ -133,10 +137,11 @@ test "cdp.Emulation: setUserAgentOverride rejects mozilla" { .params = .{ .userAgent = "Mozilla/5.0 (Windows NT 10.0)" }, }); - try ctx.expectSentError(-32602, "User agent must not contain Mozilla", .{ .id = 2 }); + try ctx.expectSentResult(null, .{}); + try testing.expect(ctx.cdp().browser_context.?.user_agent_changed == false); } -test "cdp.Emulation: setUserAgentOverride rejects mozilla case insensitive" { +test "cdp.Emulation: setUserAgentOverride ignores mozilla case insensitive" { var ctx = try testing.context(); defer ctx.deinit(); _ = try ctx.loadBrowserContext(.{ .id = "BID-UA3" }); @@ -147,7 +152,8 @@ test "cdp.Emulation: setUserAgentOverride rejects mozilla case insensitive" { .params = .{ .userAgent = "MOZILLA/5.0 test" }, }); - try ctx.expectSentError(-32602, "User agent must not contain Mozilla", .{ .id = 3 }); + try ctx.expectSentResult(null, .{}); + try testing.expect(ctx.cdp().browser_context.?.user_agent_changed == false); } test "cdp.Emulation: setUserAgentOverride rejects non-printable characters" {