Skip to content

Element not found when using async API #2772

Open
@MarkTao0

Description

@MarkTao0

Description
Calling the injection object in async manner from .net6 project, it reported "Element not found" sometimes。

Version
SDK: 1.0.1293.44
Runtime: 103.0.1264.77
Framework: .net6
OS: NA

Repro Steps
`
// On my .net side

  [ClassInterface(ClassInterfaceType.None)]
  [ComVisible(true)]
  public class RpcClientWrapper
  {
       public RpcClient MakeRequestAsync(string request, object successCallback, object errorCallback,
          object progressCallback)
       {
          var rpcClient = new RpcClient();
          // ... do something 
          return rpcClient;
     }
 }

[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class Launcher
{
    public void QueryUriSupportAsync(string request, object successCallback)
    {
        // ... do something 
    }
}


[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class InjectoinRoot {
    private RpcClientWrapper _RpcClient;

    public static InjectoinRoot Instance { get; } = new InjectoinRoot();

    public RpcClientWrapper RpcClient
    {
        get
        {
            _RpcClient ??= new RpcClientWrapper();
            return _RpcClient;
        }
    }

    public Launcher Launcher = new Launcher();
}

webView.CoreWebView2.AddHostObjectToScript("vantageAPI", InjectoinRoot.Instance);


// on web side

// case 1:
window.shimContext = {
    asyncAPI: window.top.chrome.webview.hostObjects.vantageAPI
}

function makeRequestAsync(request: string): void {
    const rpcClient = shimContext.asyncAPI.VantageRpcClient.MakeRequestAsync(
      request,
      (response: string) => {
        // do something
      },
      (intermediate: string) => {
        // do something
      },
      (response: string) => {
        // do something
      },
    );
}

// ... do something
makeRequestAsync('something');
// ... do something


// case 2
function getAsyncAPI() {
    return window.top.chrome.webview.hostObjects.vantageAPI;
}

function promisize<T>(injectedAPI: any, args: any[]) {
    return new Promise<T>((resolve, reject) => {
      try {
        // ... some simle logic
        injectedAPI(...args, (result)=> {resolve(result)}, ()=> {}, (ex)=>{reject(ex)});
      } catch (ex: any) {
        console.error(`promisize - reject ${JSON.stringify(args)}`, ex);
        reject(ex.message);
      }
    });
}

// ... do something
const promiseResult = promisize(getAsyncAPI().Launcher.QueryUriSupportAsync, 'some url');
// ... do something

`

Screenshots
// see error log in console -- log 1
you can see the "Sending remote release message 698" happened for 'VantageRpcClient' then the subsequence request(callId: 16305) for its property will then fail.
`
/*
Line 18678: VM8:3071 post remote message {remoteObjectId: 1, methodName: 'VantageRpcClient', parameters: {…}, callId: 16126, sync: undefined}
Line 23301: VM8:3071 Sending remote release message 698 undefined
Line 24169: VM8:3071 remoteproxycall event {remoteObjectId: 0, methodName: '', parameters: {…}, callId: 16126}

VM8:3071 post remote message {remoteObjectId: 698, methodName: 'MakeRequestAsync', parameters: {…}, callId: 16305, sync: undefined}

VM8:3071 remoteproxycall event {remoteObjectId: 0, methodName: '', parameters: {…}, callId: 16305}
core.js:6498

ERROR Error: Uncaught (in promise): Object: {"remoteObjectId":0,"methodName":"","parameters":{"error":"Element not found. (0x80070490)","kind":"response"},"callId":16305}
*/
`

// see error log in console -- log 2
you can see the "Sending remote release message 866" happened for 'VantageRpcClient' then the subsequence request(callId: 11970) for its property will then fail.
`
...
Line 19078: VM8:3071 watching for cleanup of 7656 (QueryUriSupportAsync) undefined
Line 32760: VM8:3071 post remote message {remoteObjectId: 866, methodName: 'QueryUriSupportAsync', parameters: {…}, callId: 10821, sync: undefined}
Line 32807: VM8:3071 watching for cleanup of 11775 (QueryUriSupportAsync) undefined
Line 32808: VM8:3071 watching for cleanup of 11776 (QueryUriSupportAsync) undefined

Line 32257: VM8:3071 post remote message {remoteObjectId: 1, methodName: 'Launcher', parameters: {…}, callId: 10664, sync: undefined}
Line 32759: VM8:3071 watching for cleanup of 11757 (Launcher) undefined
Line 35671: VM8:3071 post remote message {remoteObjectId: 1, methodName: 'Launcher', parameters: {…}, callId: 11755, sync: undefined}


Line 37051: VM8:3071 Sending remote release message 866 undefined


Line 38467: VM8:3071 watching for cleanup of 13116 (Launcher) undefined
Line 38468: VM8:3071 post remote message {remoteObjectId: 866, methodName: 'QueryUriSupportAsync', parameters: {…}, callId: 11970, sync: undefined}callId: 11970methodName: "QueryUriSupportAsync"parameters: {kind: 'request', options: {…}, parameters: Array(0)}remoteObjectId: 866sync: undefined[[Prototype]]: Object
Line 38572: Launcher.queryUriSupportAsync @ VM277:2763
VM8:3071 remoteproxycall event {remoteObjectId: 0, methodName: '', parameters: {…}, callId: 11970}
zone.js:1061 
    
   Unhandled Promise rejection: {remoteObjectId: 0, methodName: '', parameters: {…}, callId: 11970} ; Zone: <root> ; Task: Promise.then ; Value: {remoteObjectId: 0, methodName: '', parameters: {…}, callId: 11970}callId: 11970methodName: ""parameters: error: "Element not found. (0x80070490)"kind: "response"[[Prototype]]: ObjectremoteObjectId: 0[[Prototype]]: Object undefined
   

Line 43899: VM8:3071 post remote message {remoteObjectId: 1, methodName: 'Launcher', parameters: {…}, callId: 13742, sync: undefined}
Line 43910: VM8:3071 post remote message {remoteObjectId: 1, methodName: 'Launcher', parameters: {…}, callId: 13745, sync: undefined}
Line 43912: VM8:3071 watching for cleanup of 15149 (Launcher) undefined
Line 43913: VM8:3071 post remote message {remoteObjectId: 933, methodName: 'QueryUriSupportAsync', parameters: {…}, callId: 13746, sync: undefined}
Line 43922: VM8:3071 watching for cleanup of 15153 (Launcher) undefined

`

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions