From 35ced7c07a7641f37c0a6b1b973d7c78750a2249 Mon Sep 17 00:00:00 2001 From: JonnyShuali <7735338+JonnyShuali@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:30:44 +0000 Subject: [PATCH] Honor the latest WebRTC policy across flag merges --- server/lib/chromiumflags/chromiumflags.go | 11 +++++++- .../lib/chromiumflags/chromiumflags_test.go | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/server/lib/chromiumflags/chromiumflags.go b/server/lib/chromiumflags/chromiumflags.go index 226c1d62..a2f780c1 100644 --- a/server/lib/chromiumflags/chromiumflags.go +++ b/server/lib/chromiumflags/chromiumflags.go @@ -204,7 +204,8 @@ func ReadOptionalFlagFile(path string) ([]string, error) { // both lists Chromium disables it — disable wins over enable. // // Non-feature, non-extension flags from both base and runtime are combined with deduplication -// (first occurrence preserved). +// (first occurrence preserved), except the singleton WebRTC policy, whose last +// occurrence wins as it does in Chromium. func MergeFlags(baseTokens, runtimeTokens []string) []string { // Buckets var ( @@ -265,9 +266,14 @@ func MergeFlags(baseTokens, runtimeTokens []string) []string { combined := append(append([]string{}, baseNonExt...), runtimeNonExt...) combined = append(combined, featureFlags...) combined = append(combined, extFlags...) + var webRTCPolicy string seen := make(map[string]struct{}, len(combined)) final := make([]string, 0, len(combined)) for _, tok := range combined { + if name, _, _ := strings.Cut(tok, "="); name == "--webrtc-ip-handling-policy" { + webRTCPolicy = tok + continue + } if tok == "" { continue } @@ -277,6 +283,9 @@ func MergeFlags(baseTokens, runtimeTokens []string) []string { seen[tok] = struct{}{} final = append(final, tok) } + if webRTCPolicy != "" { + final = append(final, webRTCPolicy) + } return final } diff --git a/server/lib/chromiumflags/chromiumflags_test.go b/server/lib/chromiumflags/chromiumflags_test.go index 553ec34b..44d6dc38 100644 --- a/server/lib/chromiumflags/chromiumflags_test.go +++ b/server/lib/chromiumflags/chromiumflags_test.go @@ -494,3 +494,28 @@ func TestMergeFeatureEntries(t *testing.T) { }) } } + +func TestWebRTCPolicyLastValueSurvivesRuntimeMerge(t *testing.T) { + const prefix = "--webrtc-ip-handling-policy=" + for _, tc := range []struct{ base, previous, want string }{ + {"default", "emulated", "default"}, + {"disable_non_proxied_udp", "emulated", "disable_non_proxied_udp"}, + {"emulated", "default", "emulated"}, + {"default", "disable_non_proxied_udp", "emulated"}, + } { + t.Run(tc.base+"/"+tc.want, func(t *testing.T) { + // Persist a policy update, then merge that file with the original launch. + overlay := MergeFlags([]string{prefix + tc.base, prefix + tc.previous}, []string{prefix + tc.want}) + flags := MergeFlagsWithRuntimeTokens(prefix+tc.base, overlay) + var policies []string + for _, flag := range flags { + if strings.HasPrefix(flag, prefix) { + policies = append(policies, flag) + } + } + if !reflect.DeepEqual(policies, []string{prefix + tc.want}) { + t.Fatalf("merged policies = %#v, want latest %q", policies, tc.want) + } + }) + } +}