WebView2: navigating to second page causes remote messenger error
Description Navigating the webview2 browser to a web page with host objects bound, making calls to window.chrome.webview.hostObjects, and then later navigating to another page seems to reprocess existing remote messenger responses, which then generates a host of javascript errors because the response has already been processed. This seems like a bug with webview2 or am I doing something wrong? Is there presently a workaround?
VM6:1 Assertion failed: no call detail for 98
_handleResponse @ VM6:1
(anonymous) @ VM6:1
(anonymous) @ VM7:1
(anonymous)
Version SDK: 1.0.664.37 Runtime: 87.0.664.55 Framework: WinForms OS: Win10
Repro Steps 1). Create webview2 instance and bind a hostObject. 2) Load URL 3) Make calls to hostObject via window.chrome.webview.hostObject 4) Navigate to new URL (google.com) via window.location = or reload the page. 5) Error is generated by in RemoteMessager class. Interface appears to be reprocessing already processed responses to hostObjects.
Screenshots

Where does the code for calling the host object on the Javascript side live? Is it in script that you inject with AddScriptToExecuteOnDocumentCreated? If so, your script will be reloaded when navigating to a new site (which triggers DocumentCreated) and may be the reason for the multiple calls into the host object.
I am loading a single-page application embedded in Excel and using CoreWebView2.AddHostObjectToScript() to attach a few COM objects. When navigating to the next page, it merely loads a new view in the single-page application. The COM interfaces continue to work properly after second navigation except about a dozen of these errors are generated. WebView2 appears to be re-processing remote message responses that have already been processed.
Thanks for the info. For you step 3) above, would you be able to share your javascript code that is calling into the host object? And is that javascript code that's on the page itself, injected using AddScriptToExecuteOnDocumentCreated, or ExecuteScript?
The javascript is loaded by the page and is not injected. Only the COM objects are injected. The loaded javascript utilizes the injected COM host objects to call into the CLR.
I am currently attempting to reproduce the problems in a public repo.
I have created a public repo that triggers the described errors: https://github.com/aboma/WebView2Samples
- Setup an IIS site for project WebServer mapped to path 'webview2test'.
- Run WinForms project.
- Open remote debugger at localhost:8077
- Click on button to change window.location -> errors immediately appear in console.
Note: if you reduce the frequency of calls the errors appear to go away. Also, this appears to be triggered by changing the page location, even if just a hash change.
Thanks so much for the repro! I've opened a bug on our backlog to take a closer look.
Thank you. :)