MicrosoftEdge / MicrosoftEdge/WebView2Samples

HelloWebView contains race condition

Open
#228 2 comments 0 reactions 1 assignee View on GitHub

@pieths-ms is already working on this.

Since Dec 11, 2023.

Dominant language
C++
Stars
1k
Forks
521
Avg merge
13m
Merged PRs (30d)
1

Description

I based my usage of WebView2 on the HelloWebView.cpp sample, however, a recent windows update (sometime on or before Decmber 11, 2023) broke our application because the startup scripts are no longer executed. We fixed the issue by moving the calls to AddScriptToExecuteOnDocumentCreated to occur before calling Navigate. I recommend updating the samples to do the same (such as https://github.com/MicrosoftEdge/WebView2Samples/blob/85e53c9dc4245ed74fc737554640644d4b0f3bb5/GettingStartedGuides/Win32_GettingStarted/HelloWebView.cpp).

I've investigated a bit more and determined this race condition seems to always occur if you are navigating to a local file URL, i.e.

webview->AddScriptToExecuteOnDocumentCreated(L"console.log('A')", nullptr);
webview->Navigate(L"file:///C:/temp/testpage.html");
webview->AddScriptToExecuteOnDocumentCreated(L"console.log('B')", nullptr);

In that example the first console log will show up, but not the second. If you modify the example to go to an HTTP URL, both will show up.

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.