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

window.chrome.webview.hostObjects.sync.MyFunc return weird Error #3660

Closed
adamgogogo opened this issue Jul 24, 2023 · 5 comments
Closed

window.chrome.webview.hostObjects.sync.MyFunc return weird Error #3660

adamgogogo opened this issue Jul 24, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@adamgogogo
Copy link

Edge Webview2 is wonderful tool, but recently I encounter something weird...

When I call window.chrome.webview.hostObjects.sync.MyFunc.click, Javascript return the following errors:
VM3978:1 Uncaught TypeError: Cannot read properties of null (reading 'error') at RemoteMessenger.postSyncRequestMessage (<anonymous>:1:16326) at Function.getHostProperty (<anonymous>:1:33600) at Function._getAmbiguous (<anonymous>:1:20742) at Object.get (<anonymous>:1:23287)

When I use async await to call window.chrome.webview.hostObjects.MyFunc.click, Javascript not invoke MyFunc.click(), nothing happened.
(async () => { await window.chrome.webview.hostObjects.MyFunc.click(); })();

My Question is How can I resolve this problem? Thanks a lot!

@novac42 novac42 added bug Something isn't working status-circle back Check back after requesting general information. and removed question labels Jul 24, 2023
@novac42
Copy link
Contributor

novac42 commented Jul 24, 2023

Thanks for reporting the issue. Could you please provide some more information about this?

  • Framework (WinUI, Win32, WinForms, UWP, WPF, etc)
  • SDK and Runtime version
  • Operating System

@adamgogogo
Copy link
Author

Thanks for reporting the issue. Could you please provide some more information about this?

  • Framework (WinUI, Win32, WinForms, UWP, WPF, etc)
  • SDK and Runtime version
  • Operating System

Framework: wpf(.net7)
SDK and Runtime version: Microsoft.Web.WebView2(1.0.1823.32) win10
Operating System:windows server 2016 Microsoft.Edge.WebView2 Runtime(115.0.1901.183)

@novac42 novac42 removed the status-circle back Check back after requesting general information. label Jul 25, 2023
@ElyssaJyu
Copy link

Hi @adamgogogo,

Uncaught TypeError seems that there's a null reference in your code. It's possibly that MyFunc.click() is not defined or not accessible from the JavaScript. Make sure webview2 has been initialized before accessing the host object, and MyFunc is initilized and exposed to the JS context.

For async calling, could you use "try/catch" to caught the error when calling window.chrome.webview.hostObjects.MyFunc.click()?

Thanks.

@adamgogogo
Copy link
Author

Hi @adamgogogo,

Uncaught TypeError seems that there's a null reference in your code. It's possibly that MyFunc.click() is not defined or not accessible from the JavaScript. Make sure webview2 has been initialized before accessing the host object, and MyFunc is initilized and exposed to the JS context.

For async calling, could you use "try/catch" to caught the error when calling window.chrome.webview.hostObjects.MyFunc.click()?

Thanks.

Hi, @ElyssaJyu
When I print MyFunc, it seems a proxy object, it is abviouslly not a null reference like the following:
Proxy(Function) {_then: ƒ, _catch: ƒ, _isLocalProperty: ƒ, _tryCacheResult: ƒ, _ownKeys: ƒ, …} [[Handler]] : Object [[Target]] : ƒ CallableTarget() [[IsRevoked]] : false

I do use "try/catch" to caught the error:
TypeError: Cannot read properties of null (reading 'error') at RemoteMessenger.postSyncRequestMessage (<anonymous>:1:16326) at Function.getHostProperty (<anonymous>:1:33600) at Function._getAmbiguous (<anonymous>:1:20742) at Object.get (<anonymous>:1:23287)

Any other reasons? Thanks!

@adamgogogo
Copy link
Author

God, I found the problem cause I invoke myFunc in iframe.

Thanks a lots! @ElyssaJyu

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

3 participants