有没有办法获取 Google Chrome 扩展中的命令行参数?
我需要使用自定义参数从命令行启动 Chrome,这 包含一些 js 文件的路径。此外,该路径将用于 扩大。
我仔细浏览了所有相关文档并单击了中的所有节点 Chrome 调试器,但没有发现任何与命令行类似的内容 参数。是否有可能获得这些参数或者需要 编写更复杂的 npapi 扩展? (理论上在这样的 npapi- 扩展我们可以通过win-api、命令行获取自我进程 自我过程等)。
I need to launch Chrome from command line with custom parameter, which
contains path to some js-file. Further this path will be used in
extension.
I browsed carefully all related documentation and clicked all nodes in
Chrome debugger, but found nothing which can resemble on command line
parameters. Is it possible anyway to get these parameters or it's need
to write more complex npapi-extension? (theoretically in such npapi-
extension we able to get self process through win-api, command line of
self process and so on).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
黑客警报:此帖子建议传递虚假信息要打开的 URL,其中包含所有命令行参数作为查询字符串参数,例如,
Hack alert: this post suggests passing a fake URL to open that has all the command-line parameters as query string parameters, e.g.,
也许通过命令行将路径传递到自定义用户代理字符串中的扩展程序。例如:
然后,在您的扩展中:
Perhaps pass the path to your extension in a custom user agent string set via the command line. For example:
Then, in your extension:
基本上我使用 @dfrankow 的回答中给出的技术,但我打开
127.0.0.1:0
而不是假网址。这种方法有两个优点:0
。 仅使用127.0.0.1
是不够的,因为 Web 服务器可能在客户端上运行机,并且我不希望扩展程序意外连接到它。所以我必须指定一个端口号,但是哪个呢?端口0
是完美的选择:根据 RFC 1700 ,这个端口号是“保留”的,即不允许服务器使用它。将参数
abc
和xyz
传递给您的扩展的示例命令行:您可以通过以下方式在 background.js 中读取这些参数:
控制台输出(在后台页面的控制台中)扩展名):
Basically I use the technique given in @dfrankow's answer, but I open
127.0.0.1:0
instead of a fake URL. This approach has two advantages:0
. Using simply127.0.0.1
is not enough, since it is possible that a web server runs on the client machine, and I don't want the extension to connect to it accidentally. So I have to specify a port number, but which one? Port0
is the perfect choice: according to RFC 1700, this port number is "reserved", that is, servers are not allowed to use it.Example command line to pass arguments
abc
andxyz
to your extension:You can read these arguments in background.js this way:
Console output (in the console of the background page of the extension):
你可以尝试:
这假设你在加载序列中使用 jQuery,你总是可以用任何其他 AJAX 方法替换
You could try:
This assumes you are using jQuery in your loading sequence, you could always substitute with any other AJAX method
除了上面关于使用 URL 传递参数的答案之外,请注意,只有扩展程序(而不是应用程序)可以执行此操作。我发布了一个 Chrome 扩展程序,它只拦截 URL 并使其可供其他应用程序使用。
https://chrome.google.com/webstore/detail/gafgnggdglmjplpklcfhcgfaeehecepg/
来源代码可在:
https://github.com/appazur/kiosk-launcher
Wi-Fi 公共显示屏
Further to the answers above about using the URL to pass parameters in, note that only Extensions, not Apps, can do this. I've published a Chrome Extension that just intercepts the URL and makes it available to another App.
https://chrome.google.com/webstore/detail/gafgnggdglmjplpklcfhcgfaeehecepg/
The source code is available at:
https://github.com/appazur/kiosk-launcher
for Wi-Fi Public Display Screens