#2692·brython

Brython crashes on reference to a cross-origin window

Author: cjlee112Created May 24, 2026Updated May 24, 2026

Brython crashes on running the following in the current online console:

>>> from browser import document
>>> body = document.select_one('body')
>>> body
<HTMLBodyElement>
>>> from browser import html
>>> ifr = html.IFRAME(sandbox="")
>>> body <= ifr
<HTMLBodyElement>
>>> ifr.contentWindow
Traceback (most recent call last):
  File "<python-input-17>", line 1, in <module>
    ifr.contentWindow
JavascriptError: Failed to read a named property '[PYOBJ]' from 'Window': Blocked a frame with origin "https://brython.info" from accessing a cross-origin frame.
>>> ifr.contentWindow.postMessage('boo', '*')
Traceback (most recent call last):
  File "<python-input-18>", line 1, in <module>
    ifr.contentWindow.postMessage('boo', '*')
    ^^^^^^^^^^^^^^^^^
JavascriptError: Failed to read a named property '[PYOBJ]' from 'Window': Blocked a frame with origin "https://brython.info" from accessing a cross-origin frame.

Brython is trying to access attributes of the Window object that are illegal under cross-origin policy as described here: https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Same-origin_policy#cross-origin_script_api_access