[Feature] Support preconfiguration via Policy by nenikitov · Pull Request #12920 · darkreader/darkreader · GitHub
Skip to content

[Feature] Support preconfiguration via Policy#12920

Open
nenikitov wants to merge 12 commits into
darkreader:mainfrom
nenikitov:main
Open

[Feature] Support preconfiguration via Policy#12920
nenikitov wants to merge 12 commits into
darkreader:mainfrom
nenikitov:main

Conversation

@nenikitov

Copy link
Copy Markdown

Solves #12619 .

This PR adds configuration via policy for Chrome and Firefox browsers.
I'd be glad if someone could confirm if it works on Safari, Edge, and Thunderbird, I can't test them.

@alexanderby

Copy link
Copy Markdown
Member

@voronind-com

voronind-com commented Oct 31, 2024

Copy link
Copy Markdown

@alexanderby We'd really appreciate if this got merged. Thanks! <3

Tested on Firefox 128.3.0esr

@voronind-com

Copy link
Copy Markdown

It'd be nice to document the settings somewhere tho.

@voronind-com

voronind-com commented Nov 1, 2024

Copy link
Copy Markdown

Also I can't quite catch the issue, but sometimes theme settings no longer fetch from the policy. In such cases I have to remove the storage-sync-v2.sqlite file so that Dark Reader picks up new policy values.

Do I assume correctly that the extension should load new settings from the policy, i.e. just like uBlock?

Right now I have to run with this ugly lazy patch ddd532c, but surely it can be done much better.

@nenikitov

Copy link
Copy Markdown
Author

It'd be nice to document the settings somewhere tho.

Yeah, but I'm not sure where to do it.

Also I can't quite catch the issue, but sometimes theme settings no longer fetch from the policy. In such cases I have to remove the storage-sync-v2.sqlite file so that Dark Reader picks up new policy values.

I tried changing the settings on my end and couldn't replicate the issue, at least for the 10ish times I changed the policy everything worked.
Here is the Nix config I used. Lmk if something isn't right.

{pkgs, ...}: {
  programs.firefox = {
    enable = true;
    package = pkgs.firefox-esr; # As of writing, version 128.5.1. I think is needed to install extensions from file without signature?
    profiles.default = {
      isDefault = true;
      settings."xpinstall.signatures.required" = false;
    };
    policies = {
      ExtensionSettings."addon@darkreader.org" = {
        install_url = "file:///path/to/darkreader/build/release/darkreader-firefox.xpi";
        installation_mode = "force_installed";
      };
      "3rdparty".Extensions."addon@darkreader.org" = {
        theme = { # The settings I tried changing back and forth to see if it fails to read
          grayscale = 70;
          sepia = true;
          constrast = 50;
        };
      };
    };
  };
}

Do I assume correctly that the extension should load new settings from the policy, i.e. just like uBlock?

Yep.

@voronind-com

Copy link
Copy Markdown

Lmk if something isn't right.

Well I had to patch it like that: https://git.voronind.com/voronind/nix/src/branch/main/patch/darkreader/Policy.patch
That's quite radical, but that's the only way it loads settings consistently. Maybe it's on my end, but whenever I change the color settings like darkSchemeBackgroundColor they are going to be ignored as I stated above unless I nuke the sqlite db with settings, extension storage and the extension itself. I may try to dig deeper into it, but IIRC based on your sources it prefers loading stored settings and only loading "managed" as a fallback when there are no old settings in the storage.

My policy configuration: https://git.voronind.com/voronind/nix/src/commit/b979aec1921017e9a003f02ede58a8c168dfa45c/home/program/firefox/default.nix#L303

@nenikitov

nenikitov commented Dec 21, 2024

Copy link
Copy Markdown
Author

it prefers loading stored settings and only loading "managed" as a fallback when there are no old settings in the storage.

Nice catch! I think then the priority should be changed so managed settings always overwrite local settings.


Before I can do that, I'm not sure if I stumbled on an edge case. The function loadSettingsFromStorage resolves in 3 places here, here, and here. The cases 1 and 3 follow this template:

UserStorage.migrateAutomationSettings(SETTINGS);
UserStorage.fillDefaults(SETTINGS);
UserStorage.loadBarrier.resolve(SETTINGS);
return SETTINGS;

but the 2nd cases misses the first 2 lines, meaning if we have some local settings that are set to be synced, but sync storage could not be read, we return those local settings without migrations and defaults.
Is this intended behavior?

@nenikitov

Copy link
Copy Markdown
Author

I think that should have fixed the issue, now managed settings always take priority. It would be amazing if you could double check it @voronind-com.

If that 2nd case described here should not call migrateAutomationSettings and fillDefaults, I can fix it.

@voronind-com

voronind-com commented Dec 22, 2024

Copy link
Copy Markdown

I think that should have fixed the issue, now managed settings always take priority. It would be amazing if you could double check it @voronind-com.

If that 2nd case described here should not call migrateAutomationSettings and fillDefaults, I can fix it.

I'll check it today and report. Thank you very much for looking into this issue.

Edit: I've fixed all my issues, testing.

@voronind-com

Copy link
Copy Markdown

@nenikitov I've tested it multiple times, seems to be working just fine. Thank you <3

@nenikitov

Copy link
Copy Markdown
Author

I think that makes this PR feature complete.
Let me know if there is anything else needed to be done.

@voronind-com

Copy link
Copy Markdown

I think that makes this PR feature complete. Let me know if there is anything else needed to be done.

Documentation?

@nenikitov

Copy link
Copy Markdown
Author

Should it look similar to uBlock's one?
Also, would it go to the docs/ directory?

@voronind-com

Copy link
Copy Markdown

Thanks for the docs, lgtm.

@voronind-com

Copy link
Copy Markdown

@alexanderby This is quite the feature right here! Gently poking for the first and only time to take a peek at this PR.
I've personally been using it for 2+ months with no issues whatsoever.

Thanks for your time! <3

@alexanderby

Copy link
Copy Markdown
Member

Could you please tell why do you need this feature? Do you want to install the extension to users in a corporate network and force certain settings?

@voronind-com

voronind-com commented Feb 11, 2025

Copy link
Copy Markdown

Could you please tell why do you need this feature? Do you want to install the extension to users in a corporate network and force certain settings?

Personally I use this to manage my configuration with NixOS in my home infrastructure. Having about a dozen active devices, being able to configure it all only once is very important. If I ever get a new device, when I install OS there, the Dark Reader will be already preconfigured how I need it. Currently DR is the only extension I use that doesn't have this feature (others that I use are UBO, FoxyProxy, Vimium and Bitwarden). Mostly I want to set color theming for web sites, DR is great at this.

tl;dr This feature is not that uncommon among browser extensions, and it allows for proper configuration via config files for many-many different use cases. Thanks again!

@nenikitov

Copy link
Copy Markdown
Author

Could you please tell why do you need this feature? Do you want to install the extension to users in a corporate network and force certain settings?

Same use case as @voronind-com - sharing browser config between computers.

@Anomalocaridid

Copy link
Copy Markdown

Could you please tell why do you need this feature? Do you want to install the extension to users in a corporate network and force certain settings?

I currently only have one device with NixOS and even then, it would still be useful for coordinating a system-wide color scheme.

@0xda157

0xda157 commented Apr 29, 2025

Copy link
Copy Markdown

Heyo, would it be possible to get some movement on this pr?

@subham8907

Copy link
Copy Markdown

I donot know why this pr is not closed or merged

@subham8907

Copy link
Copy Markdown

@nenikitov can you contribute on my repository to implement pre confrigation via policy iwant to implement same feature on my extension https://github.com/Linkumori/Linkumori-Extension/tree/main

@Eveeifyeve

Copy link
Copy Markdown

I donot know why this pr is not closed or merged

@alexanderby

@voronind-com

Copy link
Copy Markdown

@nenikitov Could you be so kind to update this PR to the latest version?
Then we could ping darkreaderdev and alexanderby again.

I'm honestly considering alternatives to Dark Reader for this very reason. Please tell me if you switched to something else that has policy configurations.

@nenikitov

Copy link
Copy Markdown
Author

Could you be so kind to update this PR to the latest version?

I'll get to it in a couple of days

Please tell me if you switched to something else that has policy configurations.

No, I'm still using Dark Reader

@Eveeifyeve

Copy link
Copy Markdown

if this pr becomes a abandonment I might look into creating a pr basing of this one with Co Author and update it.

@nenikitov

Copy link
Copy Markdown
Author

It's up to date now

@voronind-com

Copy link
Copy Markdown

@darkreaderdev and @alexanderby could you be so kind to look at this PR, please? It's been a while. Thanks!

@ahan98

ahan98 commented Jun 27, 2025

Copy link
Copy Markdown

My policy configuration: https://git.voronind.com/voronind/nix/src/commit/b979aec1921017e9a003f02ede58a8c168dfa45c/home/program/firefox/default.nix#L303

@voronind-com Can confirm this works for me on Firefox v128.12.0esr. Your config was easy-to-follow and even taught me a couple Nix tricks. Thanks for sharing your patch!

@voronind-com

voronind-com commented Jun 27, 2025

Copy link
Copy Markdown

@ahan98 I'm glad it worked out for you! Sorry for the broken links. I'll write an updated guide for NixOS below.

  1. Grab a patch from this PR.
  2. Grab my dark reader derivation. Just in case, here's a working patch for that version. Also, you probably want to remove the __findFile input and also use relative path to a .patch file instead of <...> in my example. Please ask if you have any issues here.
  3. Next you need to allow installation of unsigned extensions.
programs.firefox.policies.Preferences = {
  "xpinstall.signatures.required" = {
    Value = false;
    Status = "locked";
  };
};
  1. Then you need to add that extension to firefox. Use the derivation from step 2.
programs.firefox.policies.ExtensionSettings = {
  "addon@darkreader.org" = {
    install_url = "file://${pkgs.callPackage ./darkreader { }}/latest.xpi";
    installation_mode = "force_installed";
  };
};
  1. Configure DarkReader extension via policy. For that use the programs.firefox.policies."3rdparty".Extensions."addon@darkreader.org" = { ... };. Here is my configuration for that.

@Eveeifyeve

Eveeifyeve commented Jun 27, 2025

Copy link
Copy Markdown

I am looking into recreating this pr, just because this hasn't been worked on or at least seen to push this pr out.

Because this is needed for stylix styling for darkreader and plus I think darkreader having custom styling would be cool since catppucin could make styling for this.

@voronind-com

Copy link
Copy Markdown

I am looking into recreating this pr, just because this hasn't been worked on or at least seen to push this pr out.

Because this is needed for stylix styling for darkreader.

I has been seen, yet there's no activity, yes.

@Eveeifyeve

Copy link
Copy Markdown

I am looking into recreating this pr, just because this hasn't been worked on or at least seen to push this pr out.
Because this is needed for stylix styling for darkreader.

I has been seen, yet there's no activity, yes.

In progress need to pull changes from this pr then add coauthor.

@Eveeifyeve

Eveeifyeve commented Jun 27, 2025

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants