Skip to content
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

prefs option doesn't work #323

Closed
aklinker1 opened this issue Sep 30, 2023 · 3 comments · Fixed by #322
Closed

prefs option doesn't work #323

aklinker1 opened this issue Sep 30, 2023 · 3 comments · Fixed by #322

Comments

@aklinker1
Copy link

It doesn't seem like the prefs option does anything. At least the example in the README doesn't work.

// (optional) Additional preferences to be set in Chrome, for example: {'download.default_directory': __dirname}
// See: https://chromium.googlesource.com/chromium/src/+/main/chrome/common/pref_names.cc
// Do note, if you set preferences when using your default profile it will overwrite these
prefs: {[key: string]: Object};

import { launch } from 'chrome-launcher';

launch({
  chromePath: '/Applications/Chrome.app/Contents/MacOS/Google Chrome',
  prefs: {
    // Subdirectory of my downloads directory just for testing
    'download.default_directory': '/Users/aklinker1/Downloads/test',
  },
});

But when I go to chrome://downloads/ and open the downloads folder, it opens /Users/aklinker1/Downloads instead of /Users/aklinker1/Downloads/test, and chrome://settings/downloads also lists /Users/aklinker1/Downloads as my download location.

Looking at the code, it seems like I shouldn't pass in a dot separated string, but in the same format as the preferences file. That doesn't work either.

if (this.fs.existsSync(preferenceFile)) {
// overwrite existing file
const file = this.fs.readFileSync(preferenceFile, 'utf-8');
const content = JSON.parse(file);
this.fs.writeFileSync(preferenceFile, JSON.stringify({...content, ...this.prefs}), 'utf-8');
} else {
// create new Preference file
this.fs.writeFileSync(preferenceFile, JSON.stringify({...this.prefs}), 'utf-8');
}

import { launch } from 'chrome-launcher';

launch({
  chromePath: '/Applications/Chrome.app/Contents/MacOS/Google Chrome',
  prefs: {
    download: {
      default_directory: '/Users/aklinker1/Downloads/test',
    },
  },
});

But I probably just don't know how the preferences file works. I would think line 247 should be a deep merge, not a simple spread, but maybe chrome expands the dot notation strings automatically and performs the deep merge?

I originally came across this trying to set extensions.ui.developer_mode to true, but couldn't get that working either. I figured that might be a special setting, so I tried it with download.default_directory then created this issue.

$ npx envinfo --system --browsers --binaries --npmPackages chrome-launcher

  System:
    OS: macOS 13.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 2.01 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.asdf/installs/nodejs/18.16.1/bin/node
    npm: 9.5.1 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 8.6.3 - ~/.asdf/installs/nodejs/18.16.1/bin/pnpm
  Browsers:
    Chrome: 117.0.5938.92
    Safari: 16.5.2
  npmPackages:
    chrome-launcher: ^1.0.0 => 1.0.0
@paulirish
Copy link
Member

This was probably fixed with #308 which hasn't shipped in a release yet.

The 1.1.0 we're about to ship will have it.

@paulirish paulirish mentioned this issue Sep 30, 2023
@aklinker1
Copy link
Author

Ahh, ok. I saw that PR, and couldn't figure out if it was released or not yet 👍 Thanks!

@aklinker1
Copy link
Author

Nice, seems to be working. Thanks for the quick release!

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 a pull request may close this issue.

2 participants