WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

WebView2: navigating to second page causes remote messenger error

Open aboma opened this issue 4 years ago • 7 comments

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 image

AB#31514510

aboma avatar Jan 20 '21 18:01 aboma

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.

champnic avatar Jan 22 '21 00:01 champnic

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.

aboma avatar Jan 22 '21 03:01 aboma

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?

champnic avatar Jan 23 '21 00:01 champnic

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.

aboma avatar Jan 25 '21 20:01 aboma

I have created a public repo that triggers the described errors: https://github.com/aboma/WebView2Samples

  1. Setup an IIS site for project WebServer mapped to path 'webview2test'.
  2. Run WinForms project.
  3. Open remote debugger at localhost:8077
  4. 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.

aboma avatar Jan 28 '21 19:01 aboma

Thanks so much for the repro! I've opened a bug on our backlog to take a closer look.

champnic avatar Jan 28 '21 22:01 champnic

Thank you. :)

aboma avatar Jan 28 '21 22:01 aboma