Google chrome 无法使用selenium和chrome headless模式访问chrome运行时

Google chrome 无法使用selenium和chrome headless模式访问chrome运行时,google-chrome,selenium,f#,google-chrome-headless,Google Chrome,Selenium,F#,Google Chrome Headless,我有一个简单的F#项目,使用硒和铬。我注意到当Chrome以无头模式启动时,Chrome对象没有定义 另一方面,如果我“正常”运行它,chrome对象将被正确引用 示例代码: let chromeOptions = new ChromeOptions(BinaryLocation = _chrome) chromeOptions.AddArguments ( "--headless", "--disable-gpu"

我有一个简单的F#项目,使用硒和铬。我注意到当Chrome以无头模式启动时,Chrome对象没有定义

另一方面,如果我“正常”运行它,chrome对象将被正确引用

示例代码:

let chromeOptions = new ChromeOptions(BinaryLocation = _chrome)
chromeOptions.AddArguments
    (
        "--headless", 
        "--disable-gpu"                    
    )
let chrome = new ChromeDriver(chromeOptions, Url = "http://www.example.com")

try                
    Console.WriteLine(chrome.Capabilities.Platform)
    Console.WriteLine(chrome.Capabilities.BrowserName)
    Console.WriteLine(chrome.Capabilities.Version)
    let res = chrome.ExecuteScript("return chrome;")
    Console.WriteLine(res)
with e -> 
    Console.WriteLine(e.Message)

chrome.Quit()
如果我运行上面的代码,我会得到以下输出:

Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 61158
Only local connections are allowed.
Any
chrome
62.0.3188.0
unknown error: chrome is not defined
  (Session info: headless chrome=62.0.3188.0)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)
Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 60248
Only local connections are allowed.
Any
chrome
62.0.3188.0
System.Collections.Generic.Dictionary`2[System.String,System.Object]
如果省略headless选项,则得到以下输出:

Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 61158
Only local connections are allowed.
Any
chrome
62.0.3188.0
unknown error: chrome is not defined
  (Session info: headless chrome=62.0.3188.0)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)
Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 60248
Only local connections are allowed.
Any
chrome
62.0.3188.0
System.Collections.Generic.Dictionary`2[System.String,System.Object]

这是一个bug还是我遗漏了什么?

headless
是chrome最近的一项功能,您会发现它与普通浏览器的不同之处,可能还没有记录在案。因此,很难说这是一个bug还是一个功能会丢失。您是否使用Chrome 62?,但chromedriver 2.31将按照其标准支持Chrome 60。不幸的是,通过使用Chrome 60.0.3112.101,我得到了相同的错误:\n我想我没有正确理解您的问题。你能帮我理解
res
的数据类型吗?你到底想通过控制台打印什么?当然,打印只是为了证明我的问题。我真正的目标是执行一个使用chrome运行时的脚本,以便将消息(通过chrome.runtime.sendMessage)发送到我以前加载的扩展。此扩展记录与服务器交换的所有请求和响应。Afaik这是使用Selenium获取此类信息的唯一方法。
headless
是chrome的一项最新功能,您会发现它与普通浏览器的不同之处,可能还没有记录在案。因此,很难说这是一个bug还是一个功能会丢失。您是否使用Chrome 62?,但chromedriver 2.31将按照其标准支持Chrome 60。不幸的是,通过使用Chrome 60.0.3112.101,我得到了相同的错误:\n我想我没有正确理解您的问题。你能帮我理解
res
的数据类型吗?你到底想通过控制台打印什么?当然,打印只是为了证明我的问题。我真正的目标是执行一个使用chrome运行时的脚本,以便将消息(通过chrome.runtime.sendMessage)发送到我以前加载的扩展。此扩展记录与服务器交换的所有请求和响应。Afaik这是使用Selenium获取此类信息的唯一方法。