⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

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

@RicardoTM05

Description

@RicardoTM05

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions