Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can messageerror fire on Worker? #10262

Open
foolip opened this issue Apr 8, 2024 · 4 comments
Open

Can messageerror fire on Worker? #10262

foolip opened this issue Apr 8, 2024 · 4 comments

Comments

@foolip
Copy link
Member

foolip commented Apr 8, 2024

What is the issue with the HTML Standard?

https://html.spec.whatwg.org/#dedicated-workers-and-the-worker-interface defines the onmessageerror event handler attribute for Worker, but can a "messageerror" event actually fire on a Worker object?

I have looked at all instances of "messageerror" and can't find any that seems to fire the event at an Worker instance, only other kinds of objects. Perhaps it happens implicitly through bubbling?

The only test I can find in WPT that listens for the event is https://wpt.fyi/results/webmessaging/broadcastchannel/workers.html, but only to fail the test if it is fired.

I'm trying to understand what behavior (if any) is required by the spec and how to test it, since it's not in Chrome but is in Firefox and Safari:
https://developer.mozilla.org/en-US/docs/Web/API/Worker#browser_compatibility

@Kaiido
Copy link
Member

Kaiido commented Apr 8, 2024

The Worker instance becomes a kind of proxy over the outside port MessagePort, so when that MessagePort would fire a messageerror event (i.e when the deserialization in the owner's side thrown), this event is expected to fire on the Worker instance.
However testing for this doesn't seem easy. The specs say that it may happen when a buffer can't be allocated, but I couldn't get one allocated in the worker thread that wouldn't be allocated in the owner's. It may also happen when posting an interface that doesn't exist on the receiving end, but once again I couldn't find a case where the serialization steps wouldn't throw before.

@foolip
Copy link
Member Author

foolip commented Apr 9, 2024

Thank you @Kaiido, it seems this even can be fired then, in principle. If an event propagates from a MessagePort to a Worker, where are the steps for this? In the message port post message steps only see MessagePort as the event target, so is there some general language about how events are propagated here?

@annevk
Copy link
Member

annevk commented Apr 9, 2024

It's hard to think of a case that would reliably fail as typically a dedicated worker is in the same agent cluster as its owner. And in the one case where that might not be the case (data: URLs and sandboxing) the dedicated worker is less privileged so you could not use SharedArrayBuffer as test. And beyond SharedArrayBuffer I'm not sure there's a good messageerror example, except for the theoretical one around OOO.

@foolip what you're looking for is described here: https://html.spec.whatwg.org/#dedicated-workers-and-the-worker-interface

All messages received by that port must immediately be retargeted at the Worker object.

@foolip
Copy link
Member Author

foolip commented Apr 19, 2024

I've filed https://crbug.com/335744333 about adding onmessageerror in Blink, if the event can fire at all, which I'm not sure about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants