#Call to window.postMessage 'Cannot read properties of undefined (reading 'data')

1 messages · Page 1 of 1 (latest)

lean cobalt
#

I’m using the AppSmith forms widget inside a Cordova app, opened with the InAppBrowser plugin. When the user presses the "cancel" or "submit" button, I need to send a message to my app to determine whether to close the opened window. On form submission, I’m calling the following JavaScript function:

export default {
    _data: {
        event: 'submit'
    },
    FallbackEvent () {
        let message = JSON.stringify(this._data);
        postWindowMessage(message, 'window', '*');
    },
    MessageAppEvent () {
        let _targetParentWindow = window?.cordova_iab ?? 
                window?.webkit?.messageHandlers?.cordova_iab ?? 
                window?.opener ?? 
                window?.parent ?? 
                window;

        let _message = JSON.stringify(this._data);
        _targetParentWindow.postMessage(_message);
    },
    Button1onClick () {
        try {
            console.info('Call MessageAppEvent()');
            this.MessageAppEvent();
        } catch(error) {
            console.error('MessageAppEvent failed');
            console.error(error);

            console.info('Calling FallbackEvent()');
            this.FallbackEvent();
        }
    }
}

The issue is that I’m receiving the following error:

TypeError: Cannot read properties of undefined (reading 'data')

Additionally, when calling from the InAppBrowser context, I need to use window.cordova_iab to properly receive the event. I've tried handling the error by calling FallbackEvent(), but the issue persists.

Could you help me resolve this issue and confirm if my implementation of postMessage is correct?

Thank you in advance for your support.

#

It's possible that when calling to postMessage it's being overrided somehow by Appsmith?

severe schoonerBOT
#

It appears you've shared an image, but as a text-based support bot, I'm unable to directly view or analyze images. If there's specific text or error messages in the image that you need help with, please transcribe the text or describe the issue, and I'll do my best to assist you!

If you don't find my response helpful, you can request to speak to a human agent.

lean cobalt
#

I'm trying to call a custom function for postMessage

let _targetParentWindow = window?.cordova_iab ??
window?.webkit?.messageHandlers?.cordova_iab ??
window?.opener ??
window?.parent ??
window;

    let _message = JSON.stringify(this._data);
    _targetParentWindow.postMessage(_message);

but im receiving TypeError: Cannot read properties of undefined (reading 'data') error