MicrosoftEdge / MicrosoftEdge/WebView2Samples
doubt to synchronize!
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1k
- Forks
- 521
- Avg merge
- 13m
- Merged PRs (30d)
- 1
Description
I tried to do some ways to synchronize Callback (NavigationCompleted), but I was unsuccessful.
For example, I want to execute (ExecuteScript or PostWebMessageAsString). But I need to make sure the page loads before! I know that AddScriptToExecuteOnDocumentCreated exists and I could use it, but it's not just in the creation, in some moments if I need to run a script I have no way of knowing if the full navigation was done.
One of the examples I tested:
webviewWindow->add_NavigationCompleted(Callback<IWebView2NavigationCompletedEventHandler>(
[&](IWebView2WebView* webview, IWebView2NavigationCompletedEventArgs * args) -> HRESULT {
SetEvent(NavigationCompletedEvent.Get());
return S_OK;
}).Get(), &token);
ResetEvent(NavigationCompletedEvent.Get());
webviewWindow->Navigate(GetFullPathFor(L"htmls\\MyAppWeb.htm"));
WaitForSingleObjectEx(NavigationCompletedEvent.Get(), INFINITE, FALSE);
// Scripting Check Page HTML is READ to CLOSE!
webviewWindow->ExecuteScript(L"window.fnIsReadyToClose();", Callback<IWebView2ExecuteScriptCompletedHandler>(
[](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {
LPCWSTR IsReadyToClose = resultObjectAsJson;
//Close Window or change page etc...
}).Get());
I tried how to run with Navigate with RunAsync (using POSTMESSAGE), but nothing!
From what I saw it is on the same thread and does not run async on another! I also didn't see anything like std :: future using a myFuture.wait (); I tried with CreateEvent and condition_variable, but it ends up the same.
I don't know if it's the best way! What do you suggest?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the shown NavigationCompleted callback and the Navigate, ExecuteScript, and PostWebMessageAsString calls. Compare their callback and threading behavior in the WebView2 samples or API documentation, then define a reproducible navigation-and-scripting sequence and the expected completion point.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100