Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: When [Frame]NavigationStarting event handler runs, args.Request.Headers never has Referer header #4766

Open
Manish3177 opened this issue Aug 22, 2024 · 2 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@Manish3177
Copy link

Manish3177 commented Aug 22, 2024

What happened?

When [Frame]NavigationStarting event handler runs, args.Request.Headers doesn't have the Referer header even if the actual request to the target URL has it. Specifically, args.Request.Headers.Contains("Referer") returns false. We have some logic in [Frame]NavigationStarting event handler that uses the Referer header to decide (a) whether to set args.Cancel = true and (b) whether to a UI (MessageBox) to the user indicating that the navigation was cancelled.

This is particularly odd given that the request is dispatched before the event handler actually runs as noted in #4765. Also, for what it's worth, the header is present in the WebResourceRequested event handler but we are unable to use because it's unreliable as noted in #4689.

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

127.0.2651.105

SDK Version

1.0.2535.41

Framework

Winforms

Operating System

Windows 11

OS Version

10.0.22631.4037

Repro steps

Set up a [Frame]NavigationStarting event handler to record/log the value of args.Request.Headers.Contains("Referer"). Attempt a few navigations while recording network traffic with dev tools or Fiddler. Observe the recorded/logged value is always false even if some navigations have the Referer header.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

AB#53476110

@Manish3177 Manish3177 added the bug Something isn't working label Aug 22, 2024
@yildirimcagri-msft
Copy link
Member

yildirimcagri-msft commented Aug 27, 2024

We added this to our backlog, but this may not be a simple fix because Chromium network stack adds such headers as Referrer after the navigation event is reported to us. Ideally, you can also use WebResourceRequested event for this.

@yildirimcagri-msft yildirimcagri-msft added the tracked We are tracking this work internally. label Aug 27, 2024
@Manish3177
Copy link
Author

Manish3177 commented Sep 3, 2024

Hi Çağrı, Thanks for the update. I wanted to mention an alternative solution if it will be relatively easier to implement. If #4604 was addressed by providing a FrameInfo property of type CoreWebView2FrameInfo on NavigationStartingEventArgs, then we can access args.FrameInfo.ParentFrameInfo.Source to get something equivalent. I realize that's not exactly the same thing but from a user point of view that may actually work better. Also, there is a potential problem with "Referer" header that it will likely be susceptible to breaking if the parent website specifies Referrer-Policy as no-referrer. We are not too worried about that but the alternative solution is likely not going to be affected by that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

2 participants