Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: AddHostObjectToScript doesn't add to chrome.webview.hostObjects #4910

Closed
aimcosoftware opened this issue Nov 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@aimcosoftware
Copy link

What happened?

I have a very simple project in Vb.Net 4.6.2, AddHostObjectToScript doesn't throw an error, but the object is not added to the JS side. Are there any known issues with this?

<ClassInterface(ClassInterfaceType.AutoDual)>
<ComVisible(True)>
Public Class DOMHost
	Sub connectHost(Msg As String)
	End Sub
End Class

Private Host as New DOMHost
Private Sub Browser_CoreWebView2InitializationCompleted(sender As Object, e As CoreWebView2InitializationCompletedEventArgs) Handles Browser.CoreWebView2InitializationCompleted
		Core = Browser.CoreWebView2
		Core.AddHostObjectToScript("DOMHost", Host)
		Core.AddScriptToExecuteOnDocumentCreatedAsync(My.Resources.DOM_Main_min)
	End Sub

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

130.0.2849.56

SDK Version

1.0.2.2849.39

Framework

Winforms

Operating System

Windows 10

OS Version

10.0.19045

Repro steps

Nothing added to chrome.webview.hostObjects

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@aimcosoftware aimcosoftware added the bug Something isn't working label Nov 8, 2024
@sivMSFT
Copy link

sivMSFT commented Nov 22, 2024

Hi @aimcosoftware,

Could you please:

  1. Double-check that your DOMHost class has the correct attributes
  2. Ensure that the CoreWebView2 instance is fully initialized before adding the host object
  3. Make sure that the JavaScript code is correctly accessing the host object

Please let us know if you continue to experience any problems.

@aimcosoftware
Copy link
Author

Yes have done all that, I did include the code, but have a workaround now using Messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants