What do I need to verify? An uncaught TypeError has occurred in the promise, indicating that the property 'MyFunctionName' cannot be read from an undefined URL

The issue arises solely in the compiled application, leading me to believe it's a browser-specific problem. However, I'm uncertain:

I've inserted the following script into a webpage:

async function exportChatAsXMLHelper(params){
    let displayname     = params[0];
    let includeMedia    = params[1];
    let debug           = params[2];
    
    await exportChatAsXML(displayname, includeMedia, debug);
}

async function exportChatAsXML(displayname, includeMedia, debug)
{

    let chat = (await WPP.chat.list()).find(m => m.contact && m.contact.name && m.contact.name.includes(displayname));
    await WPP.chat.openChatBottom(chat.id);
    let msgs = await WPP.chat.getMessages(chat.id, {count : -1});

    const log = (obj) => debug && console.log(obj);
    
    log('Total messages: ' + msgs.length);

    let count=msgs.length;

    for (var i = 0; i < count; i++) {
        log('Message number: ' + i);

        let message = msgs[i];
        let xml='';
        xml+= '<message>';
        xml+= '<sender>'+ message.from.user +'</sender>';
        xml+= '<receiver>'+ message.to.user +'</receiver>';

        xml+= '<type>'+ (message.type || '') +'</type>';

        if(message.type == 'chat')
        {
            xml+= '<body>'+ message.body +'</body>';
        }

        if(message.type != 'chat' && includeMedia) 
        {
            xml+= '<media>';
            xml+= '<caption>'+ (message.caption || '') +'</caption>';
            xml+= '<filename>'+ (message.filename || '') +'</filename>';

            log('Downloading media');

            try
            {
                let mediabody = await mediatoBase64(message.id);
                xml+= '<MediaDownloadStatus>success</MediaDownloadStatus>';
                xml+= '<base64>'+ mediabody +'</base64>';
            }
            catch(e)
            {
                xml+= '<base64></base64>';
                xml+= '<MediaDownloadStatus>fail</MediaDownloadStatus>';
            }
            xml+= '</media>';
        }

        xml+= '</message>';

        alert('before'); //this is still shown

        //where is JSCallbackReceiver defined? it is from vb6
       window.JSCallbackReceiver.OnWhatsAppXMLReceived(i, count, xml);
       
       alert('after'); //this is not shown

       xml='';
    }
}


//-----
async function mediatoBase64(msgid) {
    let blob = await WPP.chat.downloadMedia(msgid);
    return new Promise((resolve, _) => {
        const reader = new FileReader();
        reader.onloadend = () => resolve(reader.result);
        reader.readAsDataURL(blob);
    });
}

It performs well on my developer's device but throws an error on a client's machine:

Uncaught (in promise) TypeError: Cannot read property 'OnWhatsAppXMLReceived' of undefined https://web.whatsapp.com/ 80

To pinpoint the exact cause, I've included some alerts.

   window.JSCallbackReceiver.OnWhatsAppXMLReceived(i, count, xml);
   alert('after');

What could be done to diagnose the disparities between environments?

The callback object is initially set up in VB6 like this:

Private m_JSCallback As clsJSCallbackReceiver

Set m_JSCallback = New clsJSCallbackReceiver
Me.webkit1.AddObject "JSCallbackReceiver", m_JSCallback

Does the error imply that the browser cannot locate the object added via AddObject?

I am utilizing mobileFx webkit browser, which derives from Chromium, although I reckon that's inconsequential.

The appearance of the class clsJSCallbackReceiver in VB6 is as follows:

Option Explicit
    
Public Sub OnWhatsAppXMLReceived(ByVal uIndex As Long, ByVal uCount As Long, ByVal uXml As String)

     Debug.Print("I was called!")
    
 End Sub

 Public Sub SaySomething(ByVal u As String)
     MsgBox(u)
 End Sub

Thank you!

Edit:

The issue arises only when compiled. It runs smoothly within the VB6 IDE.

Even after encountering the error, executing

m_JSCallback.SaySomething("Hello!")

yields the intended outcome.

Hence, the object persists but seems disconnected from the browser.

Answer №1

After reading through this helpful document, I stumbled upon a passage related to their provided example:

"Given that the Instancing property of the class is set to PublicNotCreatable, it is essential for the project to offer a method for clients to create an instance of the object. A new function in a standard module should be added for this purpose, using clsEmployee as the class name. Furthermore, ensure that this function is not placed within a private module."

Interestingly, your code appears to go against this guideline.

Answer №2

The error message indicates that at a certain line:

window.JSCallbackReceiver.OnWhatsAppXMLReceived(i, count, xml);

The object window.JSCallbackReceiver is not defined.

To resolve this issue, you should replace the line with:

if (window.JSCallbackReceiver) {
    window.JSCallbackReceiver.OnWhatsAppXMLReceived(i, count, xml);
}

However, this will only suppress the error and not fix the underlying problem.

You must investigate why JSCallbackReceiver is undefined on your customer's browser.

In order to receive more assistance, provide the source code related to JSCallbackReceiver.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

activate a single on.click event to trigger additional actions - utilizing javascript and jQuery

My website features dynamically generated buttons that lead to specific pages. The challenge I'm facing is retrieving the automatically generated data-num value for each button and using it as a jQuery selector to redirect users to the corresponding p ...

Is "Invalid Date" indicating an incorrect date?

Have you ever wondered why JavaScript returns 'Invalid Date' when setting an (invalid) date? It can be quite confusing and make it difficult to handle errors. So, what is the optimal way to deal with this issue? One approach is to check the date ...

Unexpected error: JSON data at line 1 column 1 of the JSON data is incomplete

I've encountered an issue with my script related to a JSON response error. Below is the code snippet in question: $(document).ready(function() { $('#btndouble').click(function(){ var address = $('#btcaddress').val(); ...

What is the reason for the hotel's Object _id not being saved in MongoDB?

Can you assist with troubleshooting this issue? This is the HotelRoom Module: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const HotelRoomSchema = new Schema({ name : { type : String, require : true ...

Optimizing SEO with asynchronous image loading

I've been developing a custom middleman gem that allows for asynchronous loading of images, similar to the effect seen on Medium. Everything is functioning smoothly, but I'm uncertain about the impact on SEO. The image tag in question looks like ...

Steps for triggering a function when the 'Enter' key is pressed in a TextInput in a React Native application

I'm currently working on creating a Search Bar feature. I would like the user to input text into the TextInput field, and when they press 'Enter', I want it to trigger my function. <TextInput //when the user presses Enter, call the functi ...

Executing PHP script simultaneously in the background with jQuery

I have a PHP script that performs time-consuming tasks in the background. All I want is to display a simple message to the user: "Command executed. Invites pending." The rest of the processing will happen behind the scenes in my .php file. I'm consid ...

Tips for altering the browser tab color on a PC or Mac with HTML or JavaScript

While I am aware of the method to change theme colors on mobile devices using <meta name="theme-color" content=" #0000ffbb" />, I prefer browsing on my laptop. Are there ways to customize browser tab appearance using HTML or JS fo ...

Creating a route-guard in a Vue.js/Firebase authentication system for secure navigation

I have created a Vue.js/Firebase authentication interface following a tutorial. The app is mostly functioning properly, but I am experiencing issues with the route guard. Upon signing in and redirecting from "http://localhost:8080/home" to "http://localh ...

What are some methods for resolving the problem of CORS policy blocking access to retrieve data from Yahoo Finance?

Currently, I am attempting to retrieve the price of a stock within my pure React App by utilizing fetch. When I try to fetch without any options or configurations, using fetch(url), I encounter the following error: Access to fetch at 'https://quer ...

Incorporating SEO for a Flash-Based Website

After reading through various discussions on this topic, it seems like my question still remains unanswered. We are gearing up to revamp our company's website in the coming months. Currently, our site is mostly text-based, which has helped us achieve ...

Interactive pop-up window featuring conversational chat boxes

Trying to create a comment box within a Modal dialog box that is half of the width. The comments in this box should be read-only and created using div tags. Attempted reducing the width and using col-xs-6, but ending up with columns spanning the entire w ...

Distributing Back-end Information to a JavaScript File

Recently, I developed a blog site from scratch that includes features such as posts, users, and comments. To build this site, I utilized MongoDB, NodeJS, and Express while implementing an EJS view. However, I encountered an issue when attempting to create ...

Tracking the progress of an AJAX call with a progress bar or progress status

Using an ajax call, I want to display progress status inside a text box. Below is the code for the ajax call: <input type="text" name="cm" id="cm" /> <script type="text/javascript" language="javascript"> $('#cm').blur(function() ...

Issue with Submit Button Functionality in Django Form Submission

I'm currently facing an issue with an HTML template I built using Bootstrap. My problem lies in the fact that I have a JavaScript function that dynamically adds rows to a Django form with specific fields whenever I need to. However, when I add a row, ...

"Troubleshooting issue: Module fails to reload following JSON.parse error

For QA testing purposes, we have a test page that allows our QA team to replicate server behavior by passing JSON to a mock service. Everything functions correctly when valid JSON is used, but if invalid JSON is provided, an error is returned - which is ex ...

Error: Unable to locate module during module creation

I encountered an error while trying to import a module in my test application. ../fetchModule/index.js Module not found: Can't resolve './Myfetch' in '/Users/******/nodework/fetchModule' Here is the folder structure: https:/ ...

exchanging the positions of two animated flipdivs

Hey there! I'm facing a little challenge with my two divs (let's call them div1 and div2). One of them has a flip animation on hover, while the other flips on toggle click. My goal is to swap these two divs by dragging and dropping them. I' ...

It ceases to function when transferred to another file

I have a function written in coffeescript that goes like this: _skip_version = (currentVersion, skippedVersions) -> if (currentVersion.indexOf(skippedVersions) == -1) return false return true This function is currently located in my archive.sp ...

Tips on showcasing Javascript filter outcomes after at least 2 characters have been entered

Currently, I have implemented a filter search box that displays results as soon as a single letter is inputted. However, due to the large amount of data that needs to be filtered through, I would like the search to only show results when a minimum of two l ...