undoclosetab icon indicating copy to clipboard operation
undoclosetab copied to clipboard

Firefox policies support

Open anatoli26 opened this issue 2 years ago • 12 comments

Not sure if it's implemented, but I can't find documentation about Firefox policies support, i.e. https://extensionworkshop.com/documentation/enterprise/adding-policy-support-to-your-extension/.

Is it possible to implement policies support for this extension so it would be possible to configure it via policies.json, like e.g. uBlock Origin: https://github.com/mozilla/policy-templates#3rdparty?

anatoli26 avatar May 24 '22 06:05 anatoli26

Wow. Well, that's one piece of shitty interface design :rofl:

I already hate how storage is implemented but I guess it is just as bad in Chrome and every Add-on developer has to come up with his own implementation for stuff like "default values".

But here the implementation is actually even worse than what Google did:

https://extensionworkshop.com/documentation/enterprise/adding-policy-support-to-your-extension/ Unlike Chrome, Firefox does not require a managed_schema that describes your data.

Let's translate that: Mozilla was too lazy to create built in managed storage verification so every Add-on developer has to come up with his own implementation for that.

So what am I supposed to do here? Just ignore verification altogether and don't care about unexpected errors if administrators set invalid values using policies?

M-Reimer avatar May 24 '22 14:05 M-Reimer

So what am I supposed to do here? Just ignore verification altogether and don't care about unexpected errors if administrators set invalid values using policies?

For that I suppose a message error in the console and simply considering it as no configuration at all would be enough. But for those who do provide a correct configuration that would be a huge plus to be able to configure the extension from a centralized place.

anatoli26 avatar May 24 '22 23:05 anatoli26

At this time, how the administrators would provide a default configuration for your extension? You can configure FF with the policies almost completely, but the configuration for the extensions is unavailable if they don't support policies (like uBlock Origin), so one can't deploy FF with your preconfigured extension in a organization.

anatoli26 avatar May 24 '22 23:05 anatoli26

After some serious trouble with "git subtrees" (which I hope to have resolved now) I probably finally have something that could ship with the next release:

https://github.com/M-Reimer/undoclosetab/blob/master/utils/storage.js#L61-L69

Having it in the "utils" subtree means that I can now move this change to all my Add-ons, so if you need it for any other Add-on, feel free to create an Issue so I can update it with priority.

My change allows you to override the default values. Keep in mind that it allows you to set unsupported out of range values without any validation happening!

M-Reimer avatar May 27 '22 17:05 M-Reimer

After some serious trouble with "git subtrees" (which I hope to have resolved now) I probably finally have something that could ship with the next release...

Don't you love it when tools save you time and energy?! ;)

Gitoffthelawn avatar May 28 '22 05:05 Gitoffthelawn

@M-Reimer, thanks for this implementation, but I couldn't find a definition of the variables in the manifest.json. AFAIK, for the options to be definable via policies, they should be defined in the manifest file like this:

{
  "name": "[email protected]",
  "description": "ignored",
  "type": "storage",
  "data":
  {
    "color": "management thinks it should be blue!"
  }
}

(taken from here: https://extensionworkshop.com/documentation/enterprise/adding-policy-support-to-your-extension/)

And once they are defined, they could be accessed with the code in the utils/storage.js that you pointed to. Though maybe I didn't understand something.

anatoli26 avatar May 29 '22 03:05 anatoli26

@Gitoffthelawn there is a good chance that I ran in an edge case here. The "subtree repo" was actually created from this repo here and it may be possible that merging back this now finds some common references between the repo I have the subtree in and the subtree repo itself. Just to be sure I recreated the subtree repo from scratch now.

@anatoli26 where do you have that from? It should not be needed. I successfully tried without that.

M-Reimer avatar May 29 '22 05:05 M-Reimer

@M-Reimer, the link I put in the last comment was from the official Mozilla add-ons documentation site.

Do you have an example of how you define the values in policies?

On the other hand, when do you plan to release in the Mozilla add-ons store the version with support of policies?

anatoli26 avatar May 30 '22 00:05 anatoli26

@anatoli26 I was asking about the JSON snippet you added. I can't find this on the add-ons documentation site.

I've tested using the "Place policies.json to installation directory" method. Works similar as for uBlock Origin but you have to leave out the "userSettings" level. There is no need for this level as the only thing, you can change, are user settings defaults. Where "defaults" means, that users can change to whatever they prefer and their settings always overwrite your "admin set" defaults.

M-Reimer avatar May 30 '22 11:05 M-Reimer

So, something like this?

{
  "policies": {
    "3rdparty": {
      "Extensions": {
        "{4853d046-c5a3-436b-bc36-220fd935ee1d}": {
          "numberShowNumber": 25,
          "checkPage": true,
          "checkTab": true
        }
      }
    }
  }
}

When do you plan to submit the new version of the extension to the Mozilla add-ons store?

anatoli26 avatar May 30 '22 19:05 anatoli26

You are close. The preference names are wrong but you are on the right way. If you really have issues after I've published the next version I may give you a hint, but actually I would prefer to not document this at all. People who find it in the source code probably know what they are doing there but I would prefer if only a few people used this as, as mentioned several times, this allows to set out of range values which could cause issues and useless Issue reports here on GitHub.

I've reported the "missing validation" thing to Mozilla but I don't expect fast decision: https://bugzil.la/1771731

If they finally decide against validation, I would probably create my own minimalist JSON schema validator only for my use. Everything that already exists is huge and way oversized for being shipped with every single Add-on.

About the next release: Probably in a few days but depends on other projects I'm working on. After all I'm doing all this in my spare time.

M-Reimer avatar May 31 '22 14:05 M-Reimer

Then I guess the vars with their default values are:

  "showNumber": 25,
  "showTabMenu": false,
  "showPageMenu": false,
  "showPageMenuitem": false,
  "onlyCurrent": true,
  "showClearList": false,
  "restoreGroup": false,
  "groupTime": 200

I have created an issue about the JSON validation pointing to your bugreport with Michael Kaply who is the lead dev responsible for the policies: https://github.com/mozilla/policy-templates/issues/904. Let's see what's his opinion.

anatoli26 avatar Jun 01 '22 05:06 anatoli26

Fixed in the upcoming release.

M-Reimer avatar May 07 '23 18:05 M-Reimer