Skip to content

[Feature] Support preconfiguration via Policy #12920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

nenikitov
Copy link

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
Member

Thank you for your Pull Request. It looks interesting. I have to do some research before merging it. I'm currently busy with other high priority issues. Sorry if it will take too long before I get back to this PR.

@voronind-com
Copy link

voronind-com commented Oct 31, 2024

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

Tested on Firefox 128.3.0esr

@voronind-com
Copy link

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

@voronind-com
Copy link

voronind-com commented Nov 1, 2024

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
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."[email protected]" = {
        install_url = "file:///path/to/darkreader/build/release/darkreader-firefox.xpi";
        installation_mode = "force_installed";
      };
      "3rdparty".Extensions."[email protected]" = {
        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

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
Copy link
Author

nenikitov commented Dec 21, 2024

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
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
Copy link

voronind-com commented Dec 22, 2024

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

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

@nenikitov
Copy link
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

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

Documentation?

@nenikitov
Copy link
Author

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

@voronind-com
Copy link

Thanks for the docs, lgtm.

@voronind-com
Copy link

@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
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
Copy link

voronind-com commented Feb 11, 2025

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
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

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.

@awwpotato
Copy link

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

@subham8907
Copy link

I donot know why this pr is not closed or merged

@subham8907
Copy link

@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

I donot know why this pr is not closed or merged

@alexanderby

@voronind-com
Copy link

@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
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

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
Author

It's up to date now

@voronind-com
Copy link

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

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.

7 participants