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

Compatibility problem for legacy-JS that access COM-API with "Name"-property as ".name" #641

Closed
pontusn opened this issue Nov 19, 2020 · 6 comments
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@pontusn
Copy link

pontusn commented Nov 19, 2020

Our host has a COM-API where almost every entity expose a "Name"-property. Common usage i legacy-JS hosted in IE/WebBrowser use ".name" to access the value.

For WebView2 this results in "CallableTarget" instead of actual value, ie. obj.Name !=== obj.name.

Problem originates from:

                createPublicObject(target) {
                    target = target || function CallableTarget() {}
                    ;
                    this.overwriteTargetObject(target);
                    const proxy = new Proxy(target,{
                        apply: (target,thisArg,argumentsList)=>target.applyHostFunction(argumentsList),
                        get: (target,prop,receiver)=>target._getAmbiguous(prop),
                        set: (target,prop,value)=>target._setAmbiguous(prop, value)
                    });
                    return proxy;
                }

Maybe this is an alternative to avoid an implicit name-property from Function-object?

                createPublicObject(target) {
                    target = target || {}
                    ;
                    this.overwriteTargetObject(target);
                    const proxy = new Proxy(target,{
                        apply: (target,thisArg,argumentsList)=>target.applyHostFunction(argumentsList),
                        get: (target,prop,receiver)=>target._getAmbiguous(prop),
                        set: (target,prop,value)=>target._setAmbiguous(prop, value)
                    });
                    return proxy;
                }

Version
SDK: GA
Runtime: GA
Framework: Win32
OS: Win10 x64

AB#30786383

@pontusn pontusn added the bug Something isn't working label Nov 19, 2020
@champnic champnic added the tracked We are tracking this work internally. label Nov 20, 2020
@champnic
Copy link
Member

I've added this bug to our backlog - thanks for the report!

@pontusn
Copy link
Author

pontusn commented Dec 6, 2020

Currently we work around this issue by applying carefully crafted regex to scripts when loaded. The workaround applied conditionally after detection to determine if Object name === Object.Name

@vbryh-msft
Copy link
Contributor

Hi @pontusn, I'm a dev looking into this issue. Could you please explain what are your expectations for host object .name property in WebView2? Also in which cases .name has to be equal to .Name and when it should not. Thanks.

@pontusn
Copy link
Author

pontusn commented Aug 30, 2021

COM APIs are case-insensitive, all case-variations for properties and method should yield same result.

In current WebView2 any local JS members take priority over proxied COM API, hence the built in "name" property overides "name", while all other variations are correctly mapped to underlying COM API "Name" via automation.

@pontusn
Copy link
Author

pontusn commented Aug 30, 2021

My recommendation in this case would be to avoid the implicit "name" property by using an anonymous object. If the "name" property is required for operation I would suggest using something with less risk for conflicts, any guid prefixed with a few underscore should be zero risk...

@champnic
Copy link
Member

This should be fixed in runtimes 96.0.1042.0+. Thanks!

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

No branches or pull requests

3 participants