Can the source of a MessageEvent ever be undefined?

377 views
Skip to first unread message

Erik Kuefler

unread,
Oct 30, 2012, 3:38:48 PM10/30/12
to chromium...@chromium.org
Hi,

I'm using window.postMessage in my application and am getting reports of an exception that I can only explain if the source of the MessageEvent passed to the event listener is undefined. I haven't found a way to reproduce this locally yet, and  don't understand how this can be possible. The only reference I can find to source being undefined has to do with content scripts, which shouldn't apply here. This appears to happen only in Chrome, and has been observed on versions 21, 22, and 23. Is anyone aware of any boundary conditions that could lead to an undefined message source?

Thanks.

PhistucK

unread,
Oct 31, 2012, 2:53:24 AM10/31/12
to ekue...@google.com, chromium...@chromium.org
Perhaps a content script (by some extension the user has installed) is creating a MessageEvent itself?
Does it happen to a lot of users?

PhistucK



--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

Erik Kuefler

unread,
Oct 31, 2012, 4:22:19 AM10/31/12
to PhistucK, chromium...@chromium.org
Yes, it's happening more frequently than I would expect if the source were just random content scripts. I'm pretty sure it's failing on my own messages that I expect to be sending it. I was wondering if it would be undefined in some situation like if the window had been closed, but that doesn't seem to repro it. Guess it's time to add some more logging...

Erik Kuefler

unread,
Nov 1, 2012, 1:52:37 PM11/1/12
to chromium...@chromium.org
Just in case anyone else comes across this thread, I think I found the problem:
  1. I have an iframe that sends two post messages to its parent page in the same event loop
  2. In response to the first message, the parent removes the iframe from the DOM
  3. When the parent receives the second message (which it will since it was queued before the frame was removed), it will see it as having an undefined parent.
I'm unsure whether this is a bug in Chrome or working as intended; the specs don't seem to define what should happen to a WindowProxy object after the window has been closed. But I should be able to fix it on my end.

Reply all
Reply to author
Forward
0 new messages