Fixing NavigationException: Protocol Error (Page.navigate): Invalid referrerPolicy in PuppeteerSharp
While working with PuppeteerSharp for browser automation or web scraping tasks, the following error may appear during navigation:
NavigationException: Protocol error (Page.navigate): Invalid referrerPolicy
at PuppeteerSharp.Frame.d__84.MoveNext()
This error is typically triggered by an unsupported or incorrect value provided for the referrerPolicy parameter in the navigation options. Let’s explore the root cause and the approach that successfully resolves it.
🧩 Understanding the Error
PuppeteerSharp interacts with Chromium via the DevTools Protocol, where strict validation is enforced on input parameters. When Chromium receives a navigation request containing an unrecognized referrerPolicy, it rejects the request with a protocol-level error—preventing the page from loading.
This issue is not unique to PuppeteerSharp and can also appear in other DevTools-based automation frameworks if an invalid policy value is provided.
✅ Solution That Worked
The issue was resolved by explicitly setting the ReferrerPolicy to a valid value recognized by Chromium. The working implementation is as follows:
var response = await page.GoToAsync(url, new NavigationOptions
{
WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded },
Timeout = timeoutMilliseconds, // e.g., 5 minutes
ReferrerPolicy = "origin"
});
This change ensures compatibility with Chromium’s expectations for referrerPolicy and prevents the navigation exception from occurring.
📚 Accepted Values for ReferrerPolicy
To avoid triggering protocol errors, only valid referrerPolicy values should be used. The Chromium DevTools Protocol currently supports the following:
no-referrerno-referrer-when-downgradeoriginorigin-when-cross-originsame-originstrict-originstrict-origin-when-cross-originunsafe-url
Each value follows a lowercase, kebab-case format, and any deviation—such as using camelCase or unsupported strings—can result in errors.
🔍 Additional Observations
-
If navigation does not depend on a specific referrer policy, it is safe to omit the
ReferrerPolicyfield. Chromium will default to a policy such asno-referrer-when-downgrade, depending on the browser version and configuration. -
It is beneficial to verify the Chromium version being used, especially when working with older browser builds, as not all values may be supported consistently across versions.
🧪 Summary
The Invalid referrerPolicy exception in PuppeteerSharp occurs due to non-compliant values passed during navigation. To prevent this:
- Ensure that
ReferrerPolicyuses one of the officially supported values. - Prefer values such as
"origin", which are both widely supported and privacy-conscious. - Avoid typos and incorrect casing.
- Keep the Chromium revision up to date when possible.
By following these guidelines, we can ensure more reliable navigation behavior in automated browser sessions using PuppeteerSharp.
Leave a comment