How to send/receive a message using js

Hi all.
Hope you all are having a great Day!

I am Working on a project that connects to my website.

I want to send a message from My web app.
And receive a message in My web app.

However When i search the Community/Google.
I can’t find any Working answer.

Can you Guys show me An example of the codes needed to send messages to my app and receive Them in My web app?

Thank You


1 Like

Hi Luke,

You might have heard of this but just to confirm.

An example of the code goes as such.
Send Message to Website

Receive Message on Website

ThunkableWebviewerExtension.receiveMessage(function(message) {
  // Do something with your message

Send a Message From Your Website to Thunkable

Receive Message from Website

ThunkableWebviewerExtension.postMessage('hello world');

Happy Coding,



I explained here how to use the web viewer block to send data to .html file and receive data from .html file.

Thanks @jaythemanchs that helps out a lot.

I didn’t see that one.

1 Like

Hi all.
I’ve just added the post message code to my web app with this code:
but nothing happens:
Screenshot 2021-06-25 4.45.44 PM

1 Like

Have you added the Thunkable library?
Have you tested your html/js code that is runs and the xmlText actually has a value?


Did you check the Dev Tools and notices no errors?


i am looking into it.

it does throw some errors.
i am looking into the Google community seem to be not t he only one with this error.
Here is the error:

Uncaught ReferenceError: ThunkableWebviewerExtension is not defined
    at dGkXWjzwOBzA:519
1 Like

Can you start with a vanilla setup.

<!DOCTYPE html>

    const textData = "This is from my page";

See if this works then you know it is not the extension. If you save if to .html file and call it from your web viewer it should give you the result in the receive message event.

Hi @muneer the console doesn’t show a error anymore.

Had to change a Line of code.
However i am not sure CodePen is having server issues at the moment :frowning:
And can’t debug Because of this.

Anyways Thanks for helping

1 Like

Hi @muneer i got this error message in console while debugging:

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': HTMLUnknownElement object could not be cloned.
    at Object.postMessageToWebview [as postMessage] (
    at HTMLDocument.<anonymous> (
    at n (
    at Object.fireWith (
    at Function.ready (
    at HTMLDocument.B (
1 Like

This means you are declaring the Thunkable library in a wrong section of the .html file or it could not be parsed to the file.

Can you try my earlier suggestion of the vanilla file.


doesn’t work either :frowning:

1 Like

When you copy anything from the community posts, check the quotation marks, the community app converts them to accented marks while development environments expects simple quotations.

This could be a reason that prevents your .html file from being processed correctly.

Hi @muneer
Thank you so much with helping.
Managed to make it work.
Thanks a lot!!

1 Like

Good Luck on your project :100:

1 Like

Thank you mam