You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the CreateCoreWebView2Environment callback it uses AddScriptToExecuteOnDocumentCreated to set up a mutation observer.
Then a timer queue is used to run the following function at regular intervals to poll for mutations.
void MutationsTick()
{
//Force the window to update otherwise the following script execute will miss some mutations
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
HRESULT result = WebView->ExecuteScript(
L"var mutationString = null;\
if(window.__webview_observers__['chat-list__lines'].mutations.length > 0) {\
mutationString = window.__webview_observers__['chat-list__lines'].mutations[0];\
window.__webview_observers__['chat-list__lines'].mutations.splice(0, 1);\
}\
mutationString;",
Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
[](HRESULT errorCode, LPCWSTR resultObjectAsJson) -> HRESULT {
std::wstring Result = std::wstring(resultObjectAsJson);
if(Result != L"null")
{
const std::scoped_lock<std::mutex> lock(MutationsMutex);
Mutations.push(Result);
}
return S_OK;
}).Get());
}
My issue is that very rarely ExecuteScript will return a ERROR_INVALID_STATE for its result, I believe the message for this error was "the group or resource is not in the correct state".
Once ExecuteScript returns that error then other WebView functions such as Reload and Navigate will return the same.
My question is: what could cause the WebView to enter an invalid state?
The text was updated successfully, but these errors were encountered:
Once the WebView2 is closed, most methods return that error (doc). The WebView2 can enter that state via calling the Close method, when the last reference to the WebView2 is gone (implicit cleanup - shouldn't be happening here), or if one of the WebView2 processes crash. In the crashing case you should see the ProcessFailed event firing.
I have a program which uses WebView2 to watch for changes to the DOM of a page.
The webview is set up to use the local app data folder for its user data folder (just in case this is relevant):
In the CreateCoreWebView2Environment callback it uses
AddScriptToExecuteOnDocumentCreated
to set up a mutation observer.Then a timer queue is used to run the following function at regular intervals to poll for mutations.
My issue is that very rarely
ExecuteScript
will return aERROR_INVALID_STATE
for its result, I believe the message for this error was "the group or resource is not in the correct state".Once
ExecuteScript
returns that error then other WebView functions such asReload
andNavigate
will return the same.My question is: what could cause the WebView to enter an invalid state?
The text was updated successfully, but these errors were encountered: