Questions tagged [postmessage]

The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.

Filter by
Sorted by
Tagged with
125 votes
3 answers
160k views

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned

I'm trying to call parent.postMessage(obj, 'whatever'); from within an iframe and I'm getting this error: Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be ...
nieve's user avatar
  • 4,937
103 votes
3 answers
186k views

How do you use window.postMessage across domains?

It seems like the point of window.postMessage is to allow safe communication between windows/frames hosted on different domains, but it doesn't actually seem to allow that in Chrome. Here's the ...
Kevin Montrose's user avatar
93 votes
8 answers
74k views

Is cross-origin postMessage broken in IE10?

I'm trying to make a trivial postMessage example work... in IE10 between windows/tabs (vs. iframes) across origins Remove any one of these conditions, and things work fine :-) But as far as I can ...
Bosh's user avatar
  • 8,428
66 votes
2 answers
30k views

jQuery doesn't support postmessage event?

When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e) { var data = e.data; // data = undefined }); data is undefined! I'm sure that I have ...
stefan's user avatar
  • 2,427
53 votes
1 answer
134k views

How to postMessage into iFrame?

I am developing a Chrome extension to use with my own Web-application, processing Web-pages (including cross-domain ones), loaded into iFrame on my application's main page. So I have to send message, ...
Kostiantyn Ivashchenko's user avatar
51 votes
5 answers
52k views

Access localStorage from service worker

I want to periodically call an API from my service worker to send data stored in the localStorage. This data will be produced and saved in localStorage when a user browses my website. Consider it ...
Faiz's user avatar
  • 613
39 votes
7 answers
53k views

javascript: listen for postMessage events from specific iframe

I have multiple iframes in a page. Now I have one message event listener for the page, which gets the messages from all of the iframes. I have a workaround to know from which iframe the message is ...
forresto's user avatar
  • 12.3k
36 votes
5 answers
37k views

Can the PostMessage API be used to communicate with an Android WebView?

I usually use the HTML5 PostMessage API to communicate information from my iframed content to the parent frame. Recently I've had my content used inside an Android WebView (as far as I can tell this ...
Brian Putnam's user avatar
30 votes
5 answers
45k views

javascript postMessage not working

I don't know what to do. I tried several sample codes from different sources, I tried them in different browsers (from Chrome 9 to FF 4), and still nothing seems to be working with the "postMessage" ...
Cystack's user avatar
  • 3,431
29 votes
3 answers
10k views

Specifying multiple targetOrigin uris in postmessage

Window.postMessage() has a targetOrigin parameter that can be set to a URI (to ensure the message reaches only a specific url). It can also be set to * of course (not recommended), but is there a way ...
Michael Berry's user avatar
29 votes
4 answers
33k views

postMessage still broken on IE11?

It seems that window.postMessage is still broken on IE 11 when the message is between a window and a child popup/tab with window.open when it's sent from different domains [or same domain in some ...
bumpmann's user avatar
  • 685
25 votes
1 answer
71k views

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin 'my_page' in a call to 'postMessage'

i have following script Parent Page(pair_pixel_filter.php): window.addEventListener("message", function(e) { $('#log').append("Received message: " + (e.data)); }, false); $('....
noobie-php's user avatar
  • 7,025
25 votes
2 answers
20k views

Any good debugger for HTML5 Javascript postMessage API? [closed]

Is there any good tool out there that allows developers to correctly debug messages sent between windows with postMessage? Or maybe a plugin for Firebug?
Pierre Duplouy's user avatar
24 votes
2 answers
6k views

Does window.postMessage guarantee the order of events?

window.onmessage = ... window.postMessage('1', '*'); window.postMessage('2', '*'); Does postMessage (http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#queue-a-task) ...
4esn0k's user avatar
  • 10.1k
23 votes
6 answers
24k views

postMessage Source IFrame

I'm working on a website with cross-domain iframes that are resized to the correct height using postMessage. The only problem I'm having is identifying which iframe has which height. The way I've ...
skimberk1's user avatar
  • 2,084
23 votes
3 answers
13k views

How to make postMessage applicable to all subdomains

In window.postMessage second attribute specifies domain to which my message can be sent. Is there any way to specify that it is applicable to all subdomains. Things tried: iframe.contentWindow....
user559126's user avatar
22 votes
2 answers
31k views

window.postMessage not working from iframe to parent document [duplicate]

I'm trying to send a simple message from a child document (an iframe) back to its direct parent using the window.postMessage API. Within the parent document I have the following: window....
chris.wilkinson's user avatar
21 votes
4 answers
40k views

PostMessage with multiple functions or custom callbacks

So far I've only seen tutorials for postmessage where one window sends a single kind of message, and the other window interprets the message in only a single way. What if I want to have many ...
johnnietheblack's user avatar
20 votes
3 answers
3k views

top.postMessage origin error not caught

I'm trying to implement communication with postMessage. There is the main page which opens a popup with an iframe which comes from a different domain. This works fine so far but I want to catch the ...
Arikael's user avatar
  • 2,065
19 votes
2 answers
43k views

Problems with window.postMessage on Chrome

I have been stuck on this for hours. I have a.html on http://example.com that contains an iframe with src to b.html on http://subdomain.example.com. a.html has some JS code to postMessage to the ...
user1437328's user avatar
  • 15.7k
19 votes
3 answers
4k views

Cross-domain, cross-tab communication between co-operating pages

Say I have two tabs, each with a web-page loaded on a different domain. The pages in the two tabs want to communicate. The simplest solution I could see was this one (my answer on a closely-related ...
cloudfeet's user avatar
  • 12.6k
17 votes
3 answers
23k views

How to send a string via PostMessage?

Inside my app, I want to send a message to a dialog from a different thread. I want to pass an std::exception derived class reference to the dialog. Something like this: try { //do stuff } ...
LLucasAlday's user avatar
  • 2,461
16 votes
1 answer
13k views

communication between two iframe children using postMessage

I have some embed code that users can put on their sites. It creates two children iframes on the page. I'd like to have those children be able to communicate. I'm using javascript's window....
Brian Armstrong's user avatar
16 votes
1 answer
41k views

Does window.addEventListener('message') overwrite other listeners? [duplicate]

I've got some code that communicates with an iframe using .postMessage(), meaning it needs to add a listener on message to receive communication from the iframe. I'm using the usual code for that: ...
Chris Wilson's user avatar
  • 6,689
16 votes
1 answer
46k views

"DataCloneError: The object could not be cloned." in FireFox 34

Using given function to post message, but getting error "DataCloneError: The object could not be cloned." at Line "target['postMessage'](message, target_url.replace( /([^:]+://[^/]+).*/, '$1'));" in ...
Krishna's user avatar
  • 161
14 votes
4 answers
25k views

Chrome ServiceWorker postMessage

I try to postMessage between a web application and the corresponding service worker. The service worker is successfully registered and working so far. Unfortunately, I noticed some strange behavior: ...
user24502's user avatar
  • 1,712
14 votes
1 answer
5k views

Uncaught DOMException: Failed to execute 'postMessage' on 'Window'

I'm getting error content-script.js:24 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned. at Object.t.messageJumpContext (chrome-...
Neenu Chandran's user avatar
14 votes
2 answers
7k views

PostMessage from a sandboxed iFrame to the main window, origin is always null

There's something I don't get about the event origin with javascript postMessage event. Here is my main page: <html> <body> <h1>Test</h1> <h2>Outside</h2> <...
rekam's user avatar
  • 1,081
14 votes
1 answer
10k views

Flutter Web listen to Events posted through iFrame

my goal is to integrate a flutter widget with the help of an iframe on my main page. The main page is not written in flutter. However, I need an interface through which the main page can communicate ...
Jannik's user avatar
  • 644
14 votes
1 answer
2k views

javascript - postMessage to sandboxed iframe, why is recipient window origin null?

2 postMessage calls in the test: 1 using an asterisk for targetOrigin, one using the same https url of both the parent and child documents. button 1: $('.iframed')[0].contentWindow.postMessage( ...
Crite's user avatar
  • 151
14 votes
1 answer
1k views

Securing postMessage() on Cordova

My Cordova mobile app uses an iframe to load in a website. I want to send and receive contents over the iframe with postMessage(). However, through my testing my mobile app origin is always localhost:...
user avatar
13 votes
1 answer
5k views

Difference between custom event and postMessage

In order to send a message to another document (let's say an iframe), you can use both postMessage and createEvent functions. Assume this: var event = document.createEvent('CustomEvent'); event....
Afshin Mehrabani's user avatar
13 votes
2 answers
12k views

Sending message back with postmessage

I am currently making an application where it is neccessary to send information between two domains (will be on the loading of the page). Website 1: Creates iFrame > Sends Postmessage to website 2 ...
Mick's user avatar
  • 184
13 votes
1 answer
18k views

Communicating cross-origin from parent to child iframe

I'm working through Third Party Javascript. I'm particularly interested in communication between a parent page and a child frame from a different origin. Using window.postMessage, it's trivial to ...
Ben Jacobs's user avatar
  • 2,526
13 votes
3 answers
10k views

How can I send an event from child window to its parent window

My main goal is: Going to my application, open a link there in a new tab, make something in the new tab and send an event to the parent-main tab to refresh. I have learned 2 techniques that doesn't ...
Alon's user avatar
  • 7,668
12 votes
5 answers
30k views

How to execute a function through postMessage

I have this code inside a iframe: window.addEventListener('message', function(e){ if(e.data == 'test') console.log(e); }, false); and this inside the parent document: $('#the_iframe').get(0)...
Alex's user avatar
  • 67k
12 votes
4 answers
8k views

detect which iframe sent post message

Assume I have several iframes on the page and one of them sent a post message. Is there a simple and crossbrowser way to detect which one did it and be able to reply? I see the source property of the ...
user2281966's user avatar
12 votes
8 answers
7k views

Allowing two sites to communicate to know the current URL of an iframe

I'm trying to figure out a solution to allow an website to know what URL the user is on through an iframe. Website 1: http://website.website.com (Remote Website, can only add javascript & html to ...
Ryflex's user avatar
  • 5,671
11 votes
4 answers
12k views

SendMessage vs PostMessage + WaitForSingleObject

I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject. Thoughts?
Filip Frącz's user avatar
  • 5,909
11 votes
1 answer
6k views

Why is using '*' as the targetOrigin for postMessage a security risk?

I'm having a hard time understanding the security issues when using a wildcard for the targetOrigin of the postMessage() method. Doesn't the window you call postMessage() on already have an origin ...
endorphins's user avatar
11 votes
2 answers
23k views

window.postMessage between iframe and its parent with Angular: does anyone have a working example?

Does anyone have a working example of how to send and receive window.postMessage() calls in angular? I found the ng-post-message module on github and ngmodules, but I look at that code and it doesn't ...
K. Alan Bates's user avatar
11 votes
1 answer
18k views

How can i get postmessage data from react?

I'm trying to load a react url as an iframe in my jsp project. Here my sender side code block: <iframe id="eda" style="display: none;" src="http://myhost:3000/" ...
lesstalkmorecode's user avatar
10 votes
3 answers
27k views

Issue communication with postMessage from parent to child iFrame

I'm having an issue communicating from my parent window to the child iFrame. But in the other side, everything works perfectly. Here is how I get the chil iFrame object in order to fire the ...
Hubert Solecki's user avatar
10 votes
3 answers
8k views

Send string data from Thread to main form

In Dephi, I create a thread, like this, which will send message to main form from time to time Procedure TMyThread.SendLog(I: Integer); Var Log: array[0..255] of Char; Begin strcopy(@Log,PChar('...
alancc's user avatar
  • 489
10 votes
2 answers
33k views

Cross-site iframe postMessage from child to parent

I found this sample from SO while browsing for my problem, but I want to know exactly how to use it in my scenario. I have an iframe which is from another domain, and I want to detect when the iframe ...
Laziale's user avatar
  • 8,105
10 votes
2 answers
12k views

Can I do synchronous cross-domain communicating with window.postMessage?

I'm thinking of using window.postMessage directly for cross-domain communication. If I do: postMessage() from the parent frame Load an iframe window.addEventListener("message", callback, false); ...
ripper234's user avatar
  • 226k
10 votes
3 answers
24k views

iframe cross domain messaging with jQuery postMessage plugin

I am trying to communicate between a child iframe and its parent using the following plugin: http://benalman.com/projects/jquery-postmessage-plugin/ I can follow the example and post a message from ...
RyanP13's user avatar
  • 7,533
10 votes
1 answer
5k views

Javascript Errors: "No relay set", only in IE 7, 8

My javascript won't load because of errors it receives, only in IE. I used debugger to get the following errors. This page renders the javascript correctly in Safari, FF and chrome but not in IE and ...
ToddN's user avatar
  • 2,951
10 votes
1 answer
444 views

Use common JS libs inside sandboxed iframes

I plan to build a module system for my webapp that uses sandboxed iframes and the postMessage API to securely run custom user modules. The iframe blocks all DOM access and should only communicate ...
Stefan Blamberg's user avatar
9 votes
2 answers
8k views

javascript - window.postmessage - event.data is always null

I have an iframe and want to send data from the iframe to the parent window. Inside the js code of the iframe, I have the following statement window.parent.postMessage('hello', '*'); The ...
Hashken's user avatar
  • 4,506

1
2 3 4 5
18