【问题标题】:how to access browser %variables% (enclosed in percent % signs)如何访问浏览器 %variables%(包含在百分号中)
【发布时间】:2022-01-16 08:05:22
【问题描述】:
在各种浏览器中你可以找到这些类型的变量%VAR%
在火狐about:config你可以找到:
%LOCALE%
%VERSION%
%OS%
%GOOGLE_LOCATION_SERVICE_API_KEY%
等等。
这些变量存储或设置在哪里,以及如何通过控制台记录它们的值?
【问题讨论】:
标签:
firefox
browser
environment-variables
urlencode
console.log
【解决方案1】:
在名为 URLFormatter.jsm 的 firefox source code 文件中,您可以看到这些变量是如何声明的。
例如,%OS% 从Services.appinfo.OS 返回一个值
%LOCALE% 返回Services.locale.appLocaleAsBCP47
%CHANNEL% 返回UpdateUtils.UpdateChannel
%GOOGLE_LOCATION_SERVICE_API_KEY% 返回AppConstants.MOZ_GOOGLE_LOCATION_SERVICE_API_KEY
这些函数是在原型nsURLFormatterService 中定义的,但是例如要访问 AppConstants,您需要使用自定义的 firefox 构建;喜欢 Firefox Nightly 或启用实验模式。
这些变量可以在自定义插件中导入,并使用 ChromeUtils 导入。
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
这里是更高级的documentation
【解决方案2】:
console.log(navigator) 将为您提供浏览器拥有的信息