【问题标题】:play DRM content in chrome driver在 chrome 驱动程序中播放 DRM 内容
【发布时间】:2015-06-11 08:37:17
【问题描述】:

我正在为播放 DRM 内容的 HTML5 播放器编写一些 selenium 测试,当我手动测试它时,播放器在 Chrome 中运行良好,但如果我运行我的测试用例,则在最新的 chrome 驱动程序中没有加载或播放任何内容。

是因为drm内容没有被授权在chrome驱动中播放还是其他什么?

我对用 selenium 编写的其他函数运行测试没有问题。 有什么想法吗?

【问题讨论】:

  • 测试后关闭浏览器前请检查控制台(F12)是否有错误,如果有,请复制到这里。
  • @peetya 我没有任何错误,只是内容没有显示

标签: html google-chrome selenium


【解决方案1】:

Chromedriver 默认使用 --disable-component-update 开关启动 Chrome,这会禁用 NaCl(本机客户端)支持,而这反过来又需要加载 DRM 模块(例如 Widevine Modular DRM)。

要解决这个问题,您需要告诉驱动程序不要使用此开关启动 Chrome,方法是使用 excludeSwitches 选项构建驱动程序,指定 disable-component-update 参数。例如(JS):

var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");
var capabilities = new webdriver.Capabilities.chrome();

var chromeOptions = {
     'args': ['--user-data-dir=C:/ChromeProfile'], // start with pre-configured Chrome profile
     'excludeSwitches': ['disable-component-update'] // stop breaking Native Client support
};

capabilities.set('chromeOptions', chromeOptions);

var driver = new webdriver.Builder().
    withCapabilities(capabilities).
    build();

driver.get('http://...');

或者使用 Python 绑定:

from selenium import webdriver

def buildDriver():
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['disable-component-update'])
    options.add_argument('--user-data-dir=C:/Temp/ChromeProfile')            
    return webdriver.Chrome(chrome_options=options)

希望对您有所帮助..

--ab1

Issue 886: Enabled PNaCl Components in ChromeDriver - Enhancement

【讨论】:

  • 抱歉回复晚了,我终于有机会再做这个了。我确实喜欢你发布的内容,但内容仍然无法播放。
【解决方案2】:

我发布了Chainik 答案的Java 版本,作为Java 用户的参考,如果有任何问题,请告诉我。

            ChromeOptions options = new ChromeOptions();
            List<String> list = new ArrayList<String>();
            list.add("disable-component-update");
            options.setExperimentalOption("excludeSwitches", list);
            options.addArguments("user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/Default");

            java.lang.System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");
            Webdriver driver = new ChromeDriver(options);

这是关于 chromedriver 功能和选项的article

【讨论】:

    【解决方案3】:

    如果您无法获得@Chainik 的答案,请尝试一下。它对我有用。

    根据https://bugs.chromium.org/p/chromedriver/issues/detail?id=1140,您可以通过做一些事情来解决这个问题。

    使用这些命令行参数-- google-chrome --user-data-dir=/path/to/any/custom/directory/home/user/Desktop/Chromedir --profile-directory="Profile 1" --remote-debugging-port=7878从终端/命令提示符手动启动 chrome

    1. 确保“配置文件 1”已存在于同一个 --user-data-dir 中(使配置文件 1 具有必要的 chrome://components/ 以在手动启动时运行 Netflix)
    2. 您可以使用任何空闲端口代替 7878 验证http://localhost:7878 是否正在运行并返回值。 现在使用下面的代码通过 chromedriver 连接到 remote-debugging-port=7878 验证 chrome://components/

    我把我的放到一个 .bat 文件中,但你可以对 bash 脚本或其他任何东西做同样的事情:

    C:/Program Files (x86)/Google/Chrome/Application/chrome.exe --user-data=c:/temp/chromeprofile --profile-directory="Profile 1" --remote-debugging-port=7878
    

    然后在你的代码中设置调试器地址以使用浏览器:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    cr_options = Options()
    
    # This line is where the "magic" happens.
    cr_options.add_experimental_option('debuggerAddress','127.0.0.1:7878')
    
    browser = webdriver.Chrome(chrome_options=cr_options)
    browser.get('https://www.google.com')
    browser.get('chrome://components/')
    

    【讨论】:

      【解决方案4】:

      这已经晚了,但可能会帮助其他人。我能够通过不使用无头浏览器来解决这个问题并播放视频。

      在 Python 中,

             options = Options()
             options.headless = False
             webdriver.Chrome(executable_path='path/to/chromedriver', options=options)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-17
        • 2020-10-05
        • 1970-01-01
        • 2017-12-23
        • 2019-04-06
        • 2019-01-28
        • 2014-10-21
        • 2017-12-05
        相关资源
        最近更新 更多