[whatwg] Sending messages to just-created windows/workers

Drew Wilson atwilson at google.com
Thu Mar 19 11:10:09 PDT 2009


The WebWorkers spec states:
"DedicatedWorkerGlobalScope objects act as if they had an implicit
MessagePort associated with them"

MessagePorts will queue up events until the owner either explicitly invokes
start() on them, or sets the onmessage attribute. Is the intent that
dedicated workers also implement this same functionality for their implicit
port (i.e. if I create a dedicated worker, and immediately post a message to
it, but the worker doesn't actually set an onmessage handler, should that
event be queued until such a time as the worker does set an onmessage
handler)?

There's a similar issue with cross-window postMessage(). I've been playing
around with the current implementation in Chrome/WebKit, and code like this:

function newWindow() {
  var childWin = window.open();
  childWin.document.location = "http://example.com/child.html";

  childWin.postMessage("hi new window", "*");

}

...does not result in the message handler in the new window being
called, because the window isn't loaded at the time the message is
posted (it works just fine after the new window has loaded/executed
its script). I'm curious whether this is just a bug in the early
implementation, or if this is indeed the expected behavior -- if so,
then it makes it difficult to do cross-domain messaging as you have
this race condition on startup.

The spec is fairly clear about how this should work when explicitly
working with MessagePorts, but the behavior for these other related
use cases seems ambiguous (maybe intentionally so?)

-atw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090319/2b96403e/attachment.htm>


More information about the whatwg mailing list