Skip to content

Commit

Permalink
fix: set browser preferences correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Junyan committed Jul 18, 2023
1 parent dacd357 commit cdc8cb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ class Launcher {
return;
}

const preferenceFile = `${this.userDataDir}/Preferences`;
const profileDir = `${this.userDataDir}/Default`;
if (!this.fs.existsSync(profileDir)) {
this.fs.mkdirSync(profileDir, {recursive: true});
}

const preferenceFile = `${profileDir}/Preferences`;
try {
if (this.fs.existsSync(preferenceFile)) {
// overwrite existing file
Expand Down
6 changes: 4 additions & 2 deletions test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe('Launcher', () => {
const existStub = stub().returns(true)
const readFileStub = stub().returns(JSON.stringify({ some: 'prefs' }))
const writeFileStub = stub()
const fs = {...fsMock, rmdirSync: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub };
const mkdirStub = stub()
const fs = {...fsMock, rmdir: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub, mkdirSync: mkdirStub };
const chromeInstance =
new Launcher({prefs: {'download.default_directory': '/some/dir'}}, {fs: fs as any});

Expand All @@ -89,7 +90,8 @@ describe('Launcher', () => {
const existStub = stub().returns(false)
const readFileStub = stub().returns(Buffer.from(JSON.stringify({ some: 'prefs' })))
const writeFileStub = stub()
const fs = {...fsMock, rmdirSync: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub };
const mkdirStub = stub()
const fs = {...fsMock, rmdir: spy(), readFileSync: readFileStub, writeFileSync: writeFileStub, existsSync: existStub, mkdirSync: mkdirStub };
const chromeInstance =
new Launcher({prefs: {'download.default_directory': '/some/dir'}}, {fs: fs as any});

Expand Down

0 comments on commit cdc8cb9

Please sign in to comment.