Skip to content

JS bridge callback is not always invoked #336

@sergeys-opera

Description

@sergeys-opera

I have an app with the following JS bridge setup:

window.momi = {
    callNative: function (methodName, params) {
        return new Promise((resolve, reject) => {
            if (typeof window.momiBridge !== "undefined") {
                window.momiBridge.callNative(methodName, JSON.stringify(params), (responseBlob) => {
                    let response = JSON.parse(atob(responseBlob));
                    if ("error" in response && response.error != null) {
                        reject(response.error);
                    } else if ("result" in response && response.result != null) {
                        resolve(response.result);
                    } else {
                        reject({
                            code: 1,
                            message: "No `result` neither `error` returned from the host"
                        });
                    }
                });
            } else {
                let errorMessage = "No `window.momiBridge` injected!";
                console.error(errorMessage);
                reject({
                    code: 1,
                    message: errorMessage
                });
            }
        });
    },
};

I inject the script on every page load and it works well most of the time. However, sometimes the callNative callback does not get called.
I see, for example, onCallback: 12, ... printed in the console but on the JS side the callNative callback is not invoked.
Note that during the same page session, I do get successful method calls (even for the same failing method). In fact most of the time the JS bridge works, it fails only occasionally.

Is there anything I'm doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions