javascript Google Chrome - 我如何以编程方式启用 chrome://flags 某些模块从禁用模式到启用模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17060363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Chrome - how can i programmatically enable chrome://flags some of the modules from disable mode to enabled mode?
提问by
How can I automate the setting of chrome flags to enable few modules?
如何自动设置 chrome 标志以启用几个模块?
I have application designed which requires on open the chrome://flags few modules enabled, otherwise the whole application does not work, for normal user its nightmare to do such small changes.
我设计的应用程序需要在打开 chrome://flags 时启用几个模块,否则整个应用程序将无法工作,对于普通用户来说,做这样小的更改是噩梦。
Is there any javascript or google app engine or other method to use from server side scripting or some plugin where i can say click this and it will automatically enable the modules inside chrome://flags?
是否有任何 javascript 或谷歌应用程序引擎或其他方法可以从服务器端脚本或一些插件中使用,我可以说点击它,它会自动启用 chrome://flags 中的模块?
回答by Subhas
Almost every Chrome flag can be set via the command line. Here is a quite exhaustive list of command line parameters, but also keep in mind that there would be even more in newer versions!
几乎每个 Chrome 标志都可以通过命令行设置。这是一个非常详尽的命令行参数列表,但请记住,在较新的版本中还会有更多!
EDIT: Here is the Comprehensive, up-to-date list of Chrome command line switches
编辑:这是Chrome 命令行开关的最新综合列表
So basically you would launch chrome with these command line flags already set. That's the best way to go about it.
所以基本上你会在已经设置了这些命令行标志的情况下启动 chrome。这是最好的方法。
You cannot manually set this using Javascript or other behavior. The only way you can set this programmatically (other than command line flags) is to use Capybara(a tool that can open and control browsers, generally used for running automated tests), open Chrome and then manually navigate to "chrome://flags" and click the necessary combo boxes.
您不能使用 Javascript 或其他行为手动设置它。以编程方式(除了命令行标志)进行设置的唯一方法是使用Capybara(一种可以打开和控制浏览器的工具,通常用于运行自动化测试),打开 Chrome,然后手动导航到“chrome://flags” "并单击必要的组合框。
EDIT: Watir is also as good as Capybara
编辑:Watir 也和 Capybara 一样好
Watiris another browser automation framework (similar to Capybara) but is much easier to setup and start with. Here are exampleson how you would open a web page and select a combo box, and here are instructions on using it with Chrome. You can write a single ruby file which looks like:
Watir是另一个浏览器自动化框架(类似于 Capybara),但更容易设置和启动。以下是有关如何打开网页和选择组合框的示例,以及如何在Chrome 中使用它的说明。您可以编写一个如下所示的 ruby 文件:
require 'watir-webdriver'
browser = Watir::Browser.new :chrome
browser.goto "chrome://flags"
browser.select_list(:id => <combo box id>).select("Enabled")
...
Persisting the Flags when using WebDriver
使用 WebDriver 时保留标志
Chrome has the --user-data-dir
switch which is where all the profile settings are saved. The default directories that Chrome uses (on Windows/Mac/Linux) [is documented here. Generally, WebDriver launches with a temporary --user-data-dir
, and later deletes the temporary folder after use. So whatever flags you set will be lost when you run Chrome again! So set --user-data-dir
to your user's default profile directory, and then whatever flags you set will be persisted.
Chrome 具有--user-data-dir
保存所有配置文件设置的开关。Chrome 使用的默认目录(在 Windows/Mac/Linux 上)[记录在此处。通常,WebDriver 启动时带有一个临时的--user-data-dir
,然后在使用后删除临时文件夹。因此,当您再次运行 Chrome 时,您设置的任何标志都将丢失!所以设置--user-data-dir
为您用户的默认配置文件目录,然后您设置的任何标志都将被持久化。
Edit 2: Added comprehensive list of chrome command line flags
编辑 2:添加了 chrome 命令行标志的综合列表
Edit 3: Added instructions for persisting the flags in Webdriver
编辑 3:添加了在 Webdriver 中保留标志的说明
回答by HBP
Rooting about in the chrome://flags screen I found something interesting in an included JS file :
在 chrome://flags 屏幕中扎根,我在包含的 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
is indeed a valid method,
chrome.send
确实是一个有效的方法,
Here is another snippet form the same file (chrome://flags/flags.js)
这是同一文件的另一个片段(chrome://flags/flags.js)
/**
* Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
*/
function restartBrowser() {
chrome.send('restartBrowser');
}
Manually calling chrome.send ('restartBroswer')
did indeed restart the browser.
手动调用chrome.send ('restartBroswer')
确实重新启动了浏览器。
I think this provides all the facilities you need to automate the setting of the flags, you will need to trawl through the chrome://flags
source to find the flags you need and then
set up the appropriate chrome.send
calls.
我认为这提供了自动设置标志所需的所有设施,您需要遍历chrome://flags
源以找到所需的标志,然后设置适当的chrome.send
调用。