如何自动设置chrome标志以启用几个模块?
我有应用程序设计,这需要在打开chrome://标志几个模块启用,否则整个应用程序不工作,对于正常用户它的噩梦做这样的小变化。
有没有什么javascript或者google app引擎或者其他方法可以从服务器端脚本或者一些插件中使用,我可以说点击一下,它就会自动启用chrome://flag中的模块。
发布于 2013-06-16 18:54:05
几乎所有的Chrome标志都可以通过命令行来设置。这里有一个quite exhaustive list of command line parameters,但也请记住,在新版本中会有更多!
编辑:这是Comprehensive, up-to-date list of Chrome command line switches
所以基本上你会在这些命令行标志已经设置的情况下启动chrome。这是最好的方法。
您不能使用Javascript或其他行为手动设置此设置。你可以通过编程的方式设置这个(除了命令行标志)的唯一方法是使用Capybara (一个可以打开和控制浏览器的工具,通常用于运行自动化测试),打开Chrome,然后手动导航到“chrome://标志”并点击必要的组合框。
编辑: Watir也和Capybara一样好
Watir是另一个浏览器自动化框架(类似于Capybara),但更易于设置和入门。关于如何打开网页和选择组合框的Here are examples,下面是关于using it with Chrome的说明。您可以编写一个单独的ruby文件,如下所示:
require 'watir-webdriver'
browser = Watir::Browser.new :chrome
browser.goto "chrome://flags"
browser.select_list(:id => <combo box id>).select("Enabled")
...在使用WebDriver时保留标志
Chrome有--user-data-dir开关,所有的配置文件设置都保存在这个开关中。Chrome使用的默认目录(在Windows/Mac/Linux上)是documented here。通常,WebDriver使用临时--user-data-dir启动,然后在使用后删除临时文件夹。所以,当你再次运行Chrome时,你设置的任何标志都将丢失!因此,将--user-data-dir设置为用户的默认配置文件目录,然后您设置的任何标志都将持久化。
编辑2:添加了chrome命令行标志的全面列表
WebEdit3WebDriver:添加了在驱动程序中保持标志的说明
发布于 2013-06-17 02:58:27
在chrome://标志屏幕中查找,我在一个包含的JS文件中发现了一些有趣的东西:
/**
* Invoked when the selection of a multi-value choice is changed to the
* specified index.
* @param {HTMLElement} node The node for the experiment being changed.
* @param {number} index The index of the option that was selected.
*/
function handleSelectChoiceExperiment(node, index) {
// Tell the C++ FlagsDOMHandler to enable the selected choice.
chrome.send('enableFlagsExperiment',
[String(node.internal_name) + '@' + index, 'true']);
requestFlagsExperimentsData();
}chrome.send确实是一种有效的方法,
下面是来自同一个文件的另一个代码片段(chrome://flag/flag s.js)
/**
* Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
*/
function restartBrowser() {
chrome.send('restartBrowser');
}手动调用chrome.send ('restartBroswer')确实会重新启动浏览器。
我认为这为您提供了自动设置标志所需的所有工具,您将需要在chrome://flags源代码中查找所需的标志,然后设置适当的chrome.send调用。
https://stackoverflow.com/questions/17060363
复制相似问题