<?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>235893</bug_id>
          
          <creation_ts>2022-01-31 08:37:06 -0800</creation_ts>
          <short_desc>Accessing `window.frameElement` should not report error if parent is cross-origin</short_desc>
          <delta_ts>2022-02-07 08:38:19 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Frames</component>
          <version>Safari 15</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>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Robert Knight">robertknight</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1835543</commentid>
    <comment_count>0</comment_count>
    <who name="Robert Knight">robertknight</who>
    <bug_when>2022-01-31 08:37:06 -0800</bug_when>
    <thetext>Calling `window.frameElement` from an iframe with a cross-origin parent returns `null` in Chrome, Firefox and Safari. In Safari it additionally results in a console error with the text &quot;Blocked a frame with origin $IFRAME_ORIGIN from accessing a frame with origin $PARENT_ORIGIN. Protocols, domains and ports must match.&quot; In Chrome/Firefox no such error is reported.

The specification [1] just says that the access should return null in this situation, it doesn&apos;t mention this access being an error. It looks like this may relate to a standards change described in https://github.com/whatwg/html/pull/266.

We came across this as our application had code that checked for null-ness of `window.frameElement` and then executed different code depending on whether the child frame can reach into the parent or not. Both cases are regarded as non-error scenarios in our context.

[1] https://html.spec.whatwg.org/multipage/browsers.html#dom-frameelement</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835570</commentid>
    <comment_count>1</comment_count>
    <who name="Sam Sneddon [:gsnedders]">gsnedders</who>
    <bug_when>2022-01-31 09:53:41 -0800</bug_when>
    <thetext>Note this is only a message in the console; window.frameElement does return null in the cross-origin case as far as I can tell.

There&apos;s nothing standardised about what does and doesn&apos;t get put in the console (as errors, warnings, or in any other form). I _believe_ (but I&apos;m not totally sure!) that the current WebKit behaviour is to log in the console for any blocked cross-origin access. Do you think that logging when no exception is thrown is confusing, or that logging an error when no exception is thrown is confusing?

(http://wpt.live/html/browsers/windows/nested-browsing-contexts/frameElement.sub.html covers this case, and we indeed pass all the tests.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1835840</commentid>
    <comment_count>2</comment_count>
    <who name="Robert Knight">robertknight</who>
    <bug_when>2022-01-31 23:16:01 -0800</bug_when>
    <thetext>I acknowledge the standard doesn&apos;t say anything about what gets logged in the browser console. I found it confusing though that a console error was logged even though no exception occurred and the code triggering the error was not doing something that the specs/MDN docs indicated as being deprecated or bad practice.

The code in question looks something like:

```
if (window.frameElement) {
  // Execute some logic that makes use of information about the iframe
  // containing this document.
} else {
  // Fallback for cross-origin case.
}
```

While looking at this I found we also have some code that triggers the same error but from the other side, using the `iframe.contentDocument` property to test whether an iframe is same-origin.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838179</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-02-07 08:38:19 -0800</bug_when>
    <thetext>&lt;rdar://problem/88573609&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>