获取 SecurityError:在 Firefox 97、98 版本中,截屏时拒绝访问跨源对象上的属性“pageXOffset”

Rak*_*han 5 selenium selenium-firefoxdriver selenium-webdriver geckodriver

在 Firefox 版本 97 和 98 中,当我在 iframe 内切换并截取屏幕截图时,出现异常: org.openqa.selenium.WebDriverException: SecurityError: Permission returned to access property pageXOffset" on cross-origin object。

方法中出现异常: org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs

我能够在 iFrame 内执行单击、getText 和所有其他操作。唯一的例外是在截图时出现

Chrome 99 中不会出现此类问题。

我尝试设置首选项:

profile.setPreference("browser.tabs.remote.useCrossOriginEmbedderPolicy", false);
            profile.setPreference("security.csp.enable", false);
            profile.setPreference("security.external_protocol_requires_permission", false);
            profile.setPreference("security.fileuri.strict_origin_policy", false);
            profile.setPreference("browser.tabs.remote.useCrossOriginOpenerPolicy", false);
            profile.setPreference("network.http.referer.disallowCrossSiteRelaxingDefault.pbmode", false);
            profile.setPreference("dom.block_external_protocol_in_iframes", false);
            profile.setPreference("dom.block_download_in_sandboxed_iframes", false);
            profile.setPreference("dom.delay.block_external_protocol_in_iframes.enabled", false);
            profile.setPreference("dom.block_download_in_sandboxed_iframes", false);
Run Code Online (Sandbox Code Playgroud)

它不起作用。

但是,当我切换到主要内容并截取屏幕截图时,没有例外,但我的整个网页都在 iFrame 内,因此我必须在 iFrame 内切换并截取整个页面的多个屏幕截图。最近有人在 Firefox 中遇到过这个问题吗?请帮忙。

我正在使用 Selenium 版本:3.14.0 并使用 WebdriverManager 进行自动驱动程序下载。

如果我可以添加更多信息,请告诉我。

小智 -1

我在截图时遇到了同样的问题。我设法通过禁用跟踪保护来修复它。我将首选项添加到选项中,屏幕截图现在可以正常工作。

profile.setPreference("privacy.trackingprotection.enabled", false)
Run Code Online (Sandbox Code Playgroud)