【问题标题】: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) 将为您提供浏览器拥有的信息

    【讨论】:

    • 问题是如何记录 %OS% 变量及其存储位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 2012-04-20
    • 2017-09-13
    • 1970-01-01
    相关资源
    最近更新 更多