playwright: [BUG] Permission Denied Error when accessing cross-origin-isolated iframe in Firefox browser
Context
Playwright Version: 1.31.1 Operating System: Windows 10 Python version: 3.11.0 Browser: Firefox
Code Snippet
from playwright.sync_api import sync_playwright
with sync_playwright() as playwright:
browser = playwright.firefox.launch()
page = browser.new_page()
page.goto("https://forum.cfcybernews.eu/", wait_until="networkidle")
page.locator("#challenge-spinner").wait_for(state="hidden")
iframe_element = page.query_selector(
'iframe[allow="cross-origin-isolated; fullscreen; autoplay"]'
)
iframe_element.content_frame()
Describe the bug
When attempting to access the content frame of an iframe with the allow="cross-origin-isolated" attribute set, Playwright fails with the following error message:
playwright._impl._api_types.Error: Protocol error (Page.describeNode): error in channel "content::11/14/2": exception while running method "describeNode" in namespace "page": Permission denied to access property "docShell" on cross-origin object _describeNode@chrome://juggler/content/content/PageAgent.js:440:47
_onMessage@chrome://juggler/content/SimpleChannel.js:194:37
bindToActor/actor.receiveMessage@chrome://juggler/content/SimpleChannel.js:53:44
_onMessage@chrome://juggler/content/SimpleChannel.js:178:24
bindToActor/actor.receiveMessage@chrome://juggler/content/SimpleChannel.js:53:44
Additionally, the iframe element with the allow="cross-origin-isolated" attribute was not present in the page.frames list, even though it was present in the page. This behavior was observed only with the Firefox browser, while the same code worked as expected with the Chromium and WebKit browsers.
Expected behavior
The content frame of the iframe with the allow="cross-origin-isolated" attribute should be accessible using the content_frame() method of the ElementHandle object.
Steps to reproduce
Launch a Firefox browser instance using Playwright.
Navigate to a webpage that contains an iframe with the allow="cross-origin-isolated" attribute set.
Select the iframe using the query_selector() method of the Page object.
Attempt to access the content frame of the iframe using the content_frame() method of the ElementHandle object.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 20
- Comments: 20
Bumping this.
Same issue with python 3.11 and playwright 1.38 and Firefox browser. It is a major blocker for us. Do you have some estimation when are you going to fix this? or maybe you can provide some workarround? @mxschmitt
up this
This issue seems to affect Playwright 1.26.x+. As a hacky solution, I’ve found that if you provide an older binary manually, you can still interact with OOPIF in later versions of Playwright. However, as the docs mention, you cannot just give a public release version of Firefox as Playwright patches the browser for it to work.
Note the below explanation is relevant to
python-playwrightbut can probably be adapted (not that it should be).Say you install Playwright 1.26.0, the manifest notes the browser version is
104.0and revision is1350. So if you look in thems-playwrightcache, you’ll see afirefox-1350directory. Find the binary within and give it at initialization in newer Playwright (tested with 1.40.0 here):However, note that this alone will given an error:
It seems that the way user prefs were loaded or patched has changed. You can simply disable this by commenting this out in the server js. Open
site-packages/playwright/driver/package/lib/server/firefox/ffBrowser.jsand comment out the passing ofuserPrefsinFFBrowser.connectlike so:Edit: You can also enable passing of user preferences by copying the logic from
site-packages/playwright/driver/package/lib/server/firefox/firefox.js, too.After that, the browser launches and interactions within the iframe are successful!
Note that this is not well-tested, and absolutely not a long-term solution. It works for what I’m doing within an OOPIF but who knows what sort of undesirable behaviour this could lead to.
TL;DR: Can use the last OOPIF compatible Playwright-patched version of Firefox (v104 in python-playwright 1.26.0) with later versions of Playwright (tested with python-playwright 1.40.0)
, at the cost of losing Firefox preferences.Any news here ? It would be really helpful.
Same issue with java and headless=false here. Would this be solved soon?
Any news here ?