Bug 187822

Summary: unhandledrejection event doesn't fire across realms
Product: WebKit Reporter: Timothy Gu <timothygu99>
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: d, ggaren, joepeck, timothygu99
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Timothy Gu
Reported 2018-07-19 14:50:38 PDT
With this HTML: <iframe></iframe> <script> const frame = frames[0]; frame.onunhandledrejection = () => { alert("Rejected!"); }; frame.Promise.reject(); </script> The "Rejected!" message is not shown, but it is on Chrome. ---- There is an interesting twist to this, as executing the script inside a frame.setTimeout() (which makes the entry realm [1] to Promise.reject be that of the iframe) would allow the alert to execute. The following code works: <iframe></iframe> <script> const frame = frames[0]; frame.setTimeout(() => { frame.onunhandledrejection = () => { alert("Rejected!"); }; frame.Promise.reject(); }); </script> [1]: https://html.spec.whatwg.org/multipage/webappapis.html#concept-entry-realm ---- Merely a setTimeout does not fix the problem. The following does not alert the message either: <iframe></iframe> <script> const frame = frames[0]; setTimeout(() => { frame.onunhandledrejection = () => { alert("Rejected!"); }; frame.Promise.reject(); }); </script>
Attachments
Timothy Gu
Comment 1 2018-07-19 15:19:08 PDT
There is certainly some ambiguity in the HTML spec about what the right global object the event is fired on should be (should it be on frame? or window?) [1]. An enhanced version of reproduction case tries to handle this uncertainty by permitting both possibilities: <iframe></iframe> <script> const frame = frames[0]; window.onunhandledrejection = () => { alert("Rejected!"); }; frame.onunhandledrejection = () => { alert("Rejected!"); }; frame.Promise.reject(); </script> Yet, even in this case, the message is not shown. As an additional data point, with this HTML sample, the "Rejected!" message is shown as soon as I try to launch Web Inspector. [1]: https://github.com/whatwg/html/issues/958
Note You need to log in before you can comment on or make changes to this bug.