diff --git a/lib/PuppeteerSharp.Tests/NavigationTests/PageGotoTests.cs b/lib/PuppeteerSharp.Tests/NavigationTests/PageGotoTests.cs index 9e79f8846..613eaa4d4 100644 --- a/lib/PuppeteerSharp.Tests/NavigationTests/PageGotoTests.cs +++ b/lib/PuppeteerSharp.Tests/NavigationTests/PageGotoTests.cs @@ -507,7 +507,7 @@ await Task.WhenAll( Server.WaitForRequest("/digits/1.png", r => referer2 = r.Headers["Referer"]), Page.GoToAsync(TestConstants.ServerUrl + "/grid.html", new NavigationOptions { - ReferrerPolicy = "no-referer" + ReferrerPolicy = "no-referrer" }) ); diff --git a/lib/PuppeteerSharp/Cdp/CdpFrame.cs b/lib/PuppeteerSharp/Cdp/CdpFrame.cs index 12d07c03b..147914080 100644 --- a/lib/PuppeteerSharp/Cdp/CdpFrame.cs +++ b/lib/PuppeteerSharp/Cdp/CdpFrame.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using PuppeteerSharp.Cdp.Messaging; @@ -114,7 +115,7 @@ async Task NavigateAsync() { Url = url, Referrer = referrer ?? string.Empty, - ReferrerPolicy = referrerPolicy ?? string.Empty, + ReferrerPolicy = ReferrerPolicyToProtocol(referrerPolicy), FrameId = Id, }).ConfigureAwait(false); @@ -335,4 +336,12 @@ internal void UpdateClient(CDPSession client, bool keepWorlds = false) /// protected internal override DeviceRequestPromptManager GetDeviceRequestPromptManager() => FrameManager.GetDeviceRequestPromptManager(Client); + + // See https://chromedevtools.github.io/devtools-protocol/tot/Page/#type-ReferrerPolicy. + private static string ReferrerPolicyToProtocol(string referrerPolicy) + { + // Transform kebab-case to camelCase + return string.IsNullOrEmpty(referrerPolicy) ? null : + Regex.Replace(referrerPolicy, "-(.)", match => match.Groups[1].Value.ToUpperInvariant()); + } }