MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: SourceChanged doesn't detect view-source:

Open
#5,488 4 comments 0 reactions 1 assignee View on GitHub

@prija-microsoft is already working on this.

Since May 21, 2026.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

I'm trying to display the correct url when view source is solicited just like normal browsers do.

The problem is that when I do, for example: webView->Navigate(L"view-source:http://example.com/");

webView->add_SourceChanged(
	Callback<ICoreWebView2SourceChangedEventHandler>(
		[this](ICoreWebView2* sender, ICoreWebView2SourceChangedEventArgs* args) -> HRESULT
		{
			wil::unique_cotaskmem_string uri;
			sender->get_Source(&uri);
			RmLogF(rm, LOG_DEBUG, L"SourceChanged - source URL: %s", uri);

			return S_OK;
		}
	).Get(), nullptr
);

It logs:
SourceChanged - source URL: http://example.com/
without "view-source:".

In fact, no event returns the URL string with the view-source string included but the NewWindowRequested event, where this:

webView->add_NewWindowRequested(
	Callback<ICoreWebView2NewWindowRequestedEventHandler>(
		[this](ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args) -> HRESULT
		{
			wil::unique_cotaskmem_string destinationUri;
			args->get_Uri(&destinationUri);
			wil::unique_cotaskmem_string initialUri;
			sender->get_Source(&initialUri);
			RmLogF(rm, LOG_DEBUG, L"NewWindowRequested - Initial URL: %s", initialUri);
			RmLogF(rm, LOG_DEBUG, L"NewWindowRequested - Destination URL: %s", destinationUri);

			return S_OK;
		}
	).Get(), nullptr
);

Correctly logs:
NewWindowRequested - Initial URL: http://example.com/
NewWindowRequested - Destination URL: view-source:http://example.com/

An event that has similar options is the NavigationStarting one:

webView->add_NavigationStarting(
	Callback<ICoreWebView2NavigationStartingEventHandler>(
		[this](ICoreWebView2* sender, ICoreWebView2NavigationStartingEventArgs* args) -> HRESULT
		{
			wil::unique_cotaskmem_string initialUri;
			sender->get_Source(&initialUri);
			wil::unique_cotaskmem_string destinationUri;
			args->get_Uri(&destinationUri);
			RmLogF(rm, LOG_DEBUG, L"NavigationStarting - Initial URL: %s", initialUri);
			RmLogF(rm, LOG_DEBUG, L"NavigationStarting - Destination URL: %s", destinationUri);

			return S_OK;
		}
	).Get(), nullptr
);

But that, incorrectly logs:
NavigationStarting - Initial URL: http://example.com/
NavigationStarting - Destination URL: http://example.com/

So unless the navigation comes from a new window request (like pressing Ctrl + U), then it's not possible to display the correct url. For example, it is impossible to do so if the user navigates from a view-source page to a normal page, then returns to the view-source page through GoBack(), since the user didn't enter the url directly to an input I can read, and no event is risen that informs me that the view-source was solicited.

Ideally, all events should include the view-source string when requested.

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

143.0.3650.96

SDK Version

1.0.3650.58

Framework

Win32

Operating System

Windows 11

OS Version

No response

Repro steps

Navigate to a view-source: page using navigate()

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.