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

2 seconds delay is seen with Page navigation using WebView2 & SetVirtualHostNameToFolderMapping #2381

Open
sowrab1994 opened this issue Apr 21, 2022 · 10 comments
Assignees
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.

Comments

@sowrab1994
Copy link

sowrab1994 commented Apr 21, 2022

Description
When we load a local page using SetVirtualHostNameToFolderMapping and the domain is non-existent we see a 2 secondsdelay in the page navigation to complete.

Version
SDK: 1.0.1185.39
Runtime: 100.0.1185.44
Framework: WPF
OS: Win10

Repro Steps

  1. Create a sample WPF Application
  2. Create WebView2 instance and add it to a WPF grid.
  3. Set CoreWebView2.SetVirtualHostNameToFolderMapping to a virtual host name and folder consisting of sample HTML page.
  4. Register NavigationStarting and NavigationCompleted events and log the timestamps.
  5. Load the sample HTML Page inside the WebView.
  6. Run the application.

Note that the page loads after 2 seconds delay. That can be seen by taking the difference in timestamps logged in NavigationCompleted and NavigationStarting events.

Workaround
If we add a host file entry mapping valid IP address (machine's IP) and virtual hostname (provided in SetVirtualHostNameToFolderMapping), the page loads fine without any delay.

Additional context
It looks like it is trying to reach the host and causes the timeout.

AB#39415297

@sowrab1994 sowrab1994 added the bug Something isn't working label Apr 21, 2022
@santoshsampath
Copy link

santoshsampath commented Apr 21, 2022

Couple of other points:

  • We can always see DOMContentLoaded fires exactly after around 2s (in dev tools using performance.getEntries())
  • If we load directly using file:/// path it is always quick. But we want to load using virtualhost so that we can take advantage of all Web APIs, some of which are not available with file:/// origin

@david-risney david-risney added the tracked We are tracking this work internally. label Apr 21, 2022
@david-risney
Copy link
Contributor

Yes it looks like there's still a part of the code trying to resolve the hostname. Good bug thanks!

If you pick a name that causes hostname resolution to just wait and timeout after 2s you'll see that when navigating to a SetVirtualHostNameToFolderMapping URI. For example, if you use app.local or anything .local you'll see this behavior. As a workaround if you pick the special TLD *.example, like app.example hostname resolution should go very quick without hitting the network and no 2s timeout issue.

@david-risney david-risney self-assigned this Apr 21, 2022
@david-risney david-risney changed the title 2 seconds delay is seen with Page navigation using WebView2 2 seconds delay is seen with Page navigation using WebView2 & SetVirtualHostNameToFolderMapping Jun 1, 2022
lulzsun added a commit to lulzsun/RePlays that referenced this issue Aug 5, 2022
Now when debugging, we will display the interface using the node dev server for debug features such as live code editing. This may introduce some issues (#11) but we shall try anyways and see, since it benefits development.

+ minor perf. improvement when not using the local domain when using SetVirtualHostNameToFolderMapping. See related issue: MicrosoftEdge/WebView2Feedback#2381
@VAllens
Copy link

VAllens commented Sep 7, 2022

Couple of other points:

  • We can always see DOMContentLoaded fires exactly after around 2s (in dev tools using performance.getEntries())
  • If we load directly using file:/// path it is always quick. But we want to load using virtualhost so that we can take advantage of all Web APIs, some of which are not available with file:/// origin

Thank you so much. :)

I spent 4 hours using Edge DevTools to study why the DOMContentLoaded event is always triggered after a delay of 2 seconds. It drives me crazy!

file:// can solve my problem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
My issue is the same as that raised here.

But i did not use SetVirtualHostNameToFolderMapping.
I use AddWebResourceRequestedFilter and WebResourceRequested.
After getting the request, I get the stream from the assembly embedded resource and respond to it.

@VAllens
Copy link

VAllens commented Sep 7, 2022

After changing to file://, the delay is shortened from 2 seconds to 16 milliseconds, which is a tremendous progress.
image

@david-risney
Copy link
Contributor

The SetVirtualHostName and file: URIs are handled by the browser process. The WebResourceRequested event raises its event to you on the WebView2 UI thread in your host app. This means the WebResourceRequested event will be potentially much slower because it has a second process hop and it has to wait for the UI thread to be available. If all you need is to access local files, SetVirtualHostName or file: URIs are a better option than WebResourceRequested. But if you need the flexibility of providing your own custom stream then WebResourceRequested is required.

@VAllens
Copy link

VAllens commented Sep 7, 2022

Yes, I embed all static resources(html, js, css, png, etc...) into assembly resources.
So I need to custom handle requests and responses in WebResourceRequested event.

@bzuillsmith
Copy link

bzuillsmith commented Jul 25, 2023

Thank you @VAllens for the suggested workaround using file://. It worked great! Just so no one is confused, it's not an issue of WebResourceRequested taking a long time because of interprocess communication that's happening. It's also not an issue of the initial load of the control. When using the WebResourceRequested event, the browser shows the file is downloaded in very few ms (the interprocess communication is done). Then it waits until the 2s mark to actually render. There were no other indicators in the dev tools as to what was taking so long.

Also note that using NavigateToString is extremely fast and I can even load the entire google.com search page in 1.2s. It's only the WebResourceRequested approach that has this issue, possibly only when using a real looking http(s) url.

@github-actions github-actions bot added the priority-low We have considered this issue and decided that we will not be able to address it in the near future. label Mar 26, 2024
@SteveJobsCousin
Copy link

SteveJobsCousin commented May 1, 2024

@david-risney , i'm facing the same slow loading when using any hostName rather then "app.example", despite the issue was reported in 2022 why it still exist till today in 2024 ? ( and btw i'm using the latest version of webiew2 for wpf )

@VAllens
Copy link

VAllens commented May 6, 2024

Is there any progress on this issue?

@jochenkirstaetter
Copy link

Any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low We have considered this issue and decided that we will not be able to address it in the near future. tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

7 participants