Sunday, August 21, 2022

[FIXED] how to access browser %variables% (enclosed in percent % signs)

Issue

In various browsers you can find these type of variables %VAR%

In firefox about:config you can find:

%LOCALE%
%VERSION%
%OS%
%GOOGLE_LOCATION_SERVICE_API_KEY%

etc..

Where are those variables stored or set, and how to console log their value?


Solution

in firefox source code file named URLFormatter.jsm, you can see how those variables are declared.

For example, %OS% return a value from Services.appinfo.OS

%LOCALE% returns Services.locale.appLocaleAsBCP47

%CHANNEL% returns UpdateUtils.UpdateChannel

%GOOGLE_LOCATION_SERVICE_API_KEY% returns AppConstants.MOZ_GOOGLE_LOCATION_SERVICE_API_KEY

Those functions are defined within the prototype nsURLFormatterService but to access AppConstants for example, you need to use a custom firefox build,; like Firefox Nightly or enable experimental mode.

Those variables can be imported within a custom addon, and importing them using ChromeUtils.

const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);

Here is the more advanced documentation



Answered By - assayag.org
Answer Checked By - Candace Johnson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.