Skip to content

prefs option is incorrectly treated as a flat Record<string,JSONLike>, nested objects are not merged but overwritten #335

Description

@Rob--W

The chrome-launcher implementation assumes that prefs are a flat dictionary-like object.

This assumption is incorrect. Preferences are stored/read as nested properties: https://source.chromium.org/chromium/chromium/src/+/main:components/prefs/json_pref_store.cc;l=215-267;drc=34ad7f3844f882baf3d31a6bc6e300acaa0e3fc8

Here is an example:

{"download": { "open_pdf_in_system_reader": false } }
+
{"download": { "default_directory": "/tmp/" } }

Given the above example, I would expect the following:

{
  "download": {
    "open_pdf_in_system_reader": false,
    "default_directory": "/tmp/"
  }
}

The actual result, however, is as follows (because the top-level "download" key is overwritten):

{"download": { "default_directory": "/tmp/" } }

To fix this, one could replace the top-level merge with a deepmerge, at
https://github.com/GoogleChrome/chrome-launcher/blame/v1.1.1/src/chrome-launcher.ts#L247-L250 . One potential downside to this is that it becomes impossible to clear an existing value, but I don't think that this is a big deal: Because the set of meaningful pref is fixed (or at least known), anyone who cares about clearing could explicitly list all relevant prefs with the default value instead of specifying something like {"download":{}}.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions