python-3.x - Firefox Selenium (python) 不会打开 WebRTC 流

标签 python-3.x selenium-webdriver webrtc selenium-firefoxdriver

因此,我正在尝试使用 Firefox webdriver 打开 WebRTC 流。 它在 Chrome 上运行良好,但流不会在 Firefox 上开始播放。页面加载,但没有音频/视频。

Firefox 可以在我的普通用户配置文件中正常播放流,但无法在 Selenium 中播放。

这是代码中唯一的区别:

def newFirefoxWindow(self):
        print("Opening a firefox window")
        profile = webdriver.FirefoxProfile()
        profile.set_preference("media.navigator.permission.disabled", 1)
        profile.set_preference("permissions.default.microphone", 1)
        profile.set_preference("permissions.default.camera", 1)
        profile.set_preference("media.block-autoplay-until-in-foreground", False)
        profile.set_preference("media.autoplay.default", 1)
        profile.set_preference("media.autoplay.allow-muted", False)
        profile.set_preference("plugin.state.flash", 1)
        profile.set_preference("webdriver_accept_untrusted_certs", True)
        driver = webdriver.Firefox(firefox_profile=profile)

        return driver

这适用于 Chrome:

def newChromeWindow(self):
        options = webdriver.ChromeOptions()
        options.add_argument('--ignore-certificate-errors')
        options.add_argument("--test-type")
        options.add_experimental_option("prefs", { \
            "profile.default_content_setting_values.media_stream_mic": 1,
            "profile.default_content_setting_values.media_stream_camera": 1,
            "profile.default_content_setting_values.geolocation": 1,
            "profile.default_content_setting_values.notifications": 1
            }
        driver = webdriver.Chrome(options=options)
        return driver

有什么建议吗?是否缺少我缺少的 Firefox 设置?

最佳答案

您需要通过将 media.autoplay.default 设置为 0 来允许 Firefox 中的媒体自动播放。以下是我在 WebdriverIO 中的 Firefox 功能:

'firefox': {
    browserName: 'firefox',
    'moz:firefoxOptions': {
        prefs: {
            "media.navigator.streams.fake": true,
            "media.navigator.permission.disabled": true,
            "media.autoplay.default": 0,
            "media.volume_scale": "0.0"
        }
    }
}

关于python-3.x - Firefox Selenium (python) 不会打开 WebRTC 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55697221/

相关文章:

python - 如何在 Python 中反转大型数据集的列

python - 使用python进行Nmap扫描并存储在mysql中

c# - Selenium C# : How to pull value from input element

python - Django查询集如何排除没有组或标签的产品?

python - 如何替换Python字典中的二维列表值?

javascript - Promise 在 selenium-webdriver 中返回未定义

java.io.IOException : Connection was aborted by the software in your host machine with Sendkey() in selenium java 异常

javascript - 结束两个对等点之间的 WebRTC 视频通话

java - 当我尝试结束通话(关闭连接)时,WebRTC 崩溃

android - 无法设置远程报价 sdp : Called with SDP without SDES crypto