Skip to content

Zone.js doesn't monkey patch MessagePort#onmessage #34581

@wwwillchen

Description

@wwwillchen

🐞 bug report

Affected Package

The issue is caused by package @angular/zone.js

Is this a regression?

No, I don't think so.

Description

MessagePort is a native browser API used to asynchronously pass messages between different JS execution contexts, which my team uses for communicating across frames.

We discovered today that MessagePort is only partially monkey patched. Because MessagePort extends from EventTarget, zone.js does correctly monkeypatch MessagePort.prototype.addEventListener, however it doesn't monkeypatch the onmessage property.

My team is using an internal package within google3 for iframe communication which uses onmessage instead of addEventListener. We could use addEventListener instead of onmessage however it's slightly cumbersome because then we need to call MessagePort#start. onmessage implicitly calls MessagePort#start and I would guess most people using MessagePort would prefer to use onmessage because of this reason.

Given that onmessage can be monkey-patchable, it would be nice to fill in this hole in zone.js so other folks won't get confused. It took a while to debug this issue and at the very least, it would be good to document this limitation in zone.js (e.g. it only monkey-patches certain asynchronous APIs in MessagePort).

Thanks for your time.

🌍 Your Environment

Angular Version:
google3 cl/286903174

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions