webextension_local_filesystem_links icon indicating copy to clipboard operation
webextension_local_filesystem_links copied to clipboard

change settings in about:config

Open WileC opened this issue 7 years ago • 3 comments

It would be nice to change the settings of the extension per about:config entries. Especially the visibility in the toolbar.

In a company deployment it could be setup and administrated via the about:config entries by server hosted settings.

Example: "extensions.localfilesystemlinks.showintoolbar" boolean "extensions.localfilesystemlinks.showinstatusbar" boolean

WileC avatar Mar 27 '17 11:03 WileC

Hello WileC, nice to hear that you think about or even already use the addon in a corporate environment. That was the original motivation when the addon was first created. This feature request is now open for patches.

feinstaub avatar Apr 18 '17 15:04 feinstaub

Closing this. It is not possible with a web extension as there is no API to access about:config.

If anyone knows a way, we can reopen this and add this feature. I'd love to add this but unfortunately, it's not supported.

about:config values can be set within perf.js with user_perf(key, value) but I couldn't find a way to access them from the extension.

Extensions developed by Mozilla can use the about:config settings e.g. Pocket has settings like extensions.pocket.api. But it seems that it's not possible for third-party extensions.

Stackoverflow answer to this topic https://stackoverflow.com/a/50024435/1483981

From ChatGPT (24.05.2023)

Within the scope of standard WebExtensions, there is no direct access to modify preferences in the about:config page or use user_pref to override extension preferences. The WebExtensions API provides its own mechanisms for storing and retrieving preferences using the browser.storage API [...].

AWolf81 avatar May 24 '23 08:05 AWolf81

about:config is not possible.

But I did some more research / tests and I think it should be possible with browser.managed.storage but I couldn't get this to work.

Not sure what is missing, I'm getting Error: An unexpected error occurred for browser.storage.managed.get(). Google did not help here.

The managed_settings.json is added to the registry in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\ManagedStorage\jid1-JAzC7z53jemo5Q@jetpack with a standard entry (REG_SZ) pointing to the abs. path of the managed_settings.json file - this removed the error Managed storage manifest not found. (How to handle this needs to be checked later? Is this left to the user?)

Some snippets to create a draft version with managed storage:

  • managed_settings.json in src folder (two new settings, allowEditingOfExtensionSettings will be true by default - just for testing false, not yet used):
{
    "name": "jid1-JAzC7z53jemo5Q@jetpack",
    "description": "Settings used after installation",
    "type": "storage",
    "data": {
        "whitelist": "*",
        "enableExecutables": false,
        "revealOpenOption": "O",
        "enableLinkIcons": true,
        "retriesOnFailure": 1,
        "allowEditingOfExtensionSettings": false,
        "enableFirstRunPage": true
    }
}
  • webpack.config.js add to CopyWebpackPlugin([ ..., { from: 'src/managed_settings.json', to: 'managed_settings.json' }, ...])
  • Add new settings (not changeable settings in UI) to src\extension\constants.js:
export const defaultSettings = {
    whitelist: '*',
    enableExecutables: false,
    revealOpenOption: 'O', // default = open link
    enableLinkIcons: true,
    retriesOnFailure: 1, // default = one retry, error indication delayed by one retry is OK
    allowEditingOfExtensionSettings: true, // --> (NEW) changeable by modifying the managed storage for installation for other users, not changeable in UI
    enableFirstRunPage: true //--> (NEW) managed_settings.json only.
};
  • Modify onSettingsLoaded in src\extension\background\EventHandlers.js (draft version, not tested):
// ...
onSettingsLoaded(settings, callback) {

        let managedSettings;

        const handleSettings = (manifestSettings) => {            
            const loadedSettings = Object.assign({}, defaultSettings, manifestSettings, settings);
            const whitelist = loadedSettings.whitelist.trim()
                ? prepareWhitelist(loadedSettings.whitelist.trim())
                : [];
            // const whitelist = ['*']; //['http://127.0.0.1:3000/*', '*://*.localhost/*', '*://*.google.de/*', '*://*.trello.com/*'];
    
            callback(loadedSettings, whitelist);
        }

        // load manifest.json settings saved in data 
        // --> requires a Windows key to be available (HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER)\SOFTWARE\Mozilla\ManagedStorage\webextension_local_filesystem_links with REG_SZ as abs. path to managed_settings.json
        browser.storage.managed.get().then(handleSettings).catch(e => {
            console.log(e)
            handleSettings()
        })
    }
  • Add enableFirstRunPage check to src\extension\background\index.js in addListeners by wrapping browser.runtime.onInstalled.addListener(checkInstallation) in an if-block:
// ...
// check if first installation or update
        browser.storage.local
            .get()
            .then(settings =>
                this.eventHandlers.onSettingsLoaded(
                    settings,
                    (loadedSettings) => {
                        console.log("check setting", loadedSettings);
                        if (loadedSettings.enableFirstRunPage) {
                            browser.runtime.onInstalled.addListener(checkInstallation);
                        }
                    }));

AWolf81 avatar May 25 '23 06:05 AWolf81