Skip to content

Commit eea4224

Browse files
fix(desktop): discover Firefox Snap profiles for browser import
1 parent 0cf1076 commit eea4224

3 files changed

Lines changed: 125 additions & 1 deletion

File tree

‎apps/desktop/src/preview/BrowserImport/Sources.test.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,85 @@ describe("cookieDatabaseCandidatePaths", () => {
398398

399399
const firefox = BROWSER_IMPORT_SOURCES.find((source) => source.id === "firefox")!;
400400

401+
describe("Firefox Snap profiles", () => {
402+
it.effect("finds Snap profiles with or without profiles.ini and checks their locks", () =>
403+
run(
404+
Effect.gen(function* () {
405+
const fileSystem = yield* FileSystem.FileSystem;
406+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-firefox-snap-" });
407+
const context = yield* sourcePathContext.pipe(
408+
Effect.provideService(HostProcessEnvironment, { HOME: home }),
409+
Effect.provideService(HostProcessPlatform, "linux"),
410+
);
411+
const root = `${home}/snap/firefox/common/.mozilla/firefox`;
412+
const directory = `${root}/abcd.default`;
413+
yield* fileSystem.makeDirectory(directory, { recursive: true });
414+
yield* writeFirefoxCookieDatabase(`${directory}/cookies.sqlite`, 2, 1);
415+
yield* fileSystem.writeFileString(
416+
`${root}/profiles.ini`,
417+
"[Profile0]\nName=Personal\nIsRelative=1\nPath=abcd.default\n",
418+
);
419+
420+
assert.isTrue(yield* isSourceInstalled(firefox, context));
421+
assert.deepEqual(yield* listSourceProfiles(firefox, context), [
422+
{ directory, name: "Personal", cookieCount: 2 },
423+
]);
424+
assert.equal(
425+
yield* resolveCookieDatabase(firefox, context, directory),
426+
`${directory}/cookies.sqlite`,
427+
);
428+
assert.isFalse(yield* isSourceRunning(firefox, context));
429+
yield* fileSystem.symlink("foreign-host:+4242", `${directory}/lock`);
430+
assert.isTrue(yield* isSourceRunning(firefox, context));
431+
yield* fileSystem.remove(`${directory}/lock`);
432+
assert.isFalse(yield* isSourceRunning(firefox, context));
433+
434+
yield* fileSystem.remove(`${root}/profiles.ini`);
435+
assert.deepEqual(yield* listSourceProfiles(firefox, context), [
436+
{ directory, name: "abcd.default", cookieCount: 2 },
437+
]);
438+
}),
439+
),
440+
);
441+
442+
it.effect("keeps matching profile names in native and Snap installs distinct", () =>
443+
run(
444+
Effect.gen(function* () {
445+
const fileSystem = yield* FileSystem.FileSystem;
446+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-firefox-snap-" });
447+
const context = yield* sourcePathContext.pipe(
448+
Effect.provideService(HostProcessEnvironment, { HOME: home }),
449+
Effect.provideService(HostProcessPlatform, "linux"),
450+
);
451+
const native = `${home}/.mozilla/firefox`;
452+
const snap = `${home}/snap/firefox/common/.mozilla/firefox`;
453+
for (const root of [native, snap]) {
454+
yield* fileSystem.makeDirectory(`${root}/abcd.default`, { recursive: true });
455+
yield* writeFirefoxCookieDatabase(`${root}/abcd.default/cookies.sqlite`, 1, 0);
456+
yield* fileSystem.writeFileString(
457+
`${root}/profiles.ini`,
458+
"[Profile0]\nName=Personal\nIsRelative=1\nPath=abcd.default\n" +
459+
`[Profile1]\nName=Shared\nIsRelative=0\nPath=${snap}/abcd.default\n`,
460+
);
461+
}
462+
463+
const profiles = yield* listSourceProfiles(firefox, context);
464+
assert.deepEqual(
465+
profiles.map((profile) => profile.directory),
466+
["abcd.default", `${snap}/abcd.default`],
467+
);
468+
const databases = yield* Effect.forEach(profiles, (profile) =>
469+
resolveCookieDatabase(firefox, context, profile.directory),
470+
);
471+
assert.deepEqual(databases, [
472+
`${native}/abcd.default/cookies.sqlite`,
473+
`${snap}/abcd.default/cookies.sqlite`,
474+
]);
475+
}),
476+
),
477+
);
478+
});
479+
401480
describe("listSourceProfiles Firefox fallback", () => {
402481
const cases = [
403482
{ platform: "linux" as const, profileDirectory: "linux.default" },

‎apps/desktop/src/preview/BrowserImport/Sources.ts‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ const withCookieCounts = (
359359
* `Default` would report a browser whose cookies live in `Profile 1` as having
360360
* nothing to import — and it is then left out of the menu entirely.
361361
*/
362-
export const listSourceProfiles = Effect.fn("BrowserImportSources.listSourceProfiles")(function* (
362+
const listSourceProfilesInDirectory = Effect.fnUntraced(function* (
363363
definition: BrowserImportSourceDefinition,
364364
context: BrowserImportPathContext,
365365
): Effect.fn.Return<ReadonlyArray<BrowserImportSourceProfile>, never, FileSystem.FileSystem> {
@@ -429,6 +429,41 @@ export const listSourceProfiles = Effect.fn("BrowserImportSources.listSourceProf
429429
);
430430
});
431431

432+
/**
433+
* Include Firefox's Snap home alongside its native home. Snap profiles use
434+
* absolute directories so cookie reads and lock checks keep pointing at the
435+
* installation they came from, even when both installs use the same name.
436+
*/
437+
export const listSourceProfiles = Effect.fn("BrowserImportSources.listSourceProfiles")(function* (
438+
definition: BrowserImportSourceDefinition,
439+
context: BrowserImportPathContext,
440+
): Effect.fn.Return<ReadonlyArray<BrowserImportSourceProfile>, never, FileSystem.FileSystem> {
441+
if (definition.engine !== "firefox" || context.platform !== "linux") {
442+
return yield* listSourceProfilesInDirectory(definition, context);
443+
}
444+
445+
const root = definition.userDataDirectory(context);
446+
if (root === undefined) return [];
447+
const roots = [
448+
root,
449+
context.path.join(context.home, "snap", "firefox", "common", ".mozilla", "firefox"),
450+
];
451+
const profiles = new Map<string, BrowserImportSourceProfile>();
452+
for (const directory of roots) {
453+
const found = yield* listSourceProfilesInDirectory(
454+
{ ...definition, userDataDirectory: () => directory },
455+
context,
456+
);
457+
for (const profile of found) {
458+
const absolute = context.path.resolve(directory, profile.directory);
459+
if (!profiles.has(absolute)) {
460+
profiles.set(absolute, directory === root ? profile : { ...profile, directory: absolute });
461+
}
462+
}
463+
}
464+
return [...profiles.values()];
465+
});
466+
432467
/**
433468
* Whether a cookie database candidate is a regular file. Presence alone is
434469
* not enough: a directory at the path would list as an importable profile and

‎docs/user/browser-import.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Import browser logins
2+
3+
In the desktop app, open **Settings → Integrations → Browser profiles → Add profile**
4+
and choose a browser under **Import from**. The import copies cookies into a T3 Code browser
5+
profile so you can use existing logins in the preview browser. Changes made afterward stay
6+
separate from the source browser.
7+
8+
On Linux, Firefox profiles are discovered from both native and Snap installations. A browser
9+
appears once it has a profile with a cookie database. Close the source browser before importing;
10+
the import wizard will prompt you if it is still running.

0 commit comments

Comments
 (0)