<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>187822</bug_id>
          
          <creation_ts>2018-07-19 14:50:38 -0700</creation_ts>
          <short_desc>unhandledrejection event doesn&apos;t fire across realms</short_desc>
          <delta_ts>2018-07-20 19:31:10 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Timothy Gu">timothygu99</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>d</cc>
    
    <cc>ggaren</cc>
    
    <cc>joepeck</cc>
    
    <cc>timothygu99</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1443516</commentid>
    <comment_count>0</comment_count>
    <who name="Timothy Gu">timothygu99</who>
    <bug_when>2018-07-19 14:50:38 -0700</bug_when>
    <thetext>With this HTML:

&lt;iframe&gt;&lt;/iframe&gt;
&lt;script&gt;
const frame = frames[0];
frame.onunhandledrejection = () =&gt; { alert(&quot;Rejected!&quot;); };
frame.Promise.reject();
&lt;/script&gt;

The &quot;Rejected!&quot; 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:

&lt;iframe&gt;&lt;/iframe&gt;
&lt;script&gt;
const frame = frames[0];
frame.setTimeout(() =&gt; {
  frame.onunhandledrejection = () =&gt; { alert(&quot;Rejected!&quot;); };
  frame.Promise.reject();
});
&lt;/script&gt;

[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:

&lt;iframe&gt;&lt;/iframe&gt;
&lt;script&gt;
const frame = frames[0];
setTimeout(() =&gt; {
  frame.onunhandledrejection = () =&gt; { alert(&quot;Rejected!&quot;); };
  frame.Promise.reject();
});
&lt;/script&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1443536</commentid>
    <comment_count>1</comment_count>
    <who name="Timothy Gu">timothygu99</who>
    <bug_when>2018-07-19 15:19:08 -0700</bug_when>
    <thetext>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:

&lt;iframe&gt;&lt;/iframe&gt;
&lt;script&gt;
const frame = frames[0];
window.onunhandledrejection = () =&gt; { alert(&quot;Rejected!&quot;); };
frame.onunhandledrejection = () =&gt; { alert(&quot;Rejected!&quot;); };
frame.Promise.reject();
&lt;/script&gt;

Yet, even in this case, the message is not shown.

As an additional data point, with this HTML sample, the &quot;Rejected!&quot; message is shown as soon as I try to launch Web Inspector.

[1]: https://github.com/whatwg/html/issues/958</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>