feat: allow disabling cookie sources and default to firefox/graphql

This commit is contained in:
Peter Steinberger
2025-12-03 16:31:55 +00:00
parent 33ef131b94
commit 6ecfe57018
3 changed files with 20 additions and 3 deletions
+3 -1
View File
@@ -60,7 +60,9 @@ Example `~/.config/bird/config.json5` (Firefox + GraphQL defaults):
// Prefer Firefox cookies by default // Prefer Firefox cookies by default
firefoxProfile: "default-release", firefoxProfile: "default-release",
// Optional: Sweetistics defaults if you want fallback/overrides // Optional: Sweetistics defaults if you want fallback/overrides
sweetisticsApiKey: "sweet-..." sweetisticsApiKey: "sweet-...",
// Disable Chrome cookies entirely (optional)
allowChrome: false
} }
``` ```
+10
View File
@@ -44,6 +44,8 @@ type BirdConfig = {
firefoxProfile?: string; firefoxProfile?: string;
sweetisticsApiKey?: string; sweetisticsApiKey?: string;
sweetisticsBaseUrl?: string; sweetisticsBaseUrl?: string;
allowChrome?: boolean;
allowFirefox?: boolean;
}; };
function readConfigFile(path: string): Partial<BirdConfig> { function readConfigFile(path: string): Partial<BirdConfig> {
@@ -210,6 +212,8 @@ program
ct0: opts.ct0, ct0: opts.ct0,
chromeProfile: opts.chromeProfile || config.chromeProfile, chromeProfile: opts.chromeProfile || config.chromeProfile,
firefoxProfile: opts.firefoxProfile || config.firefoxProfile, firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
allowChrome: config.allowChrome ?? true,
allowFirefox: config.allowFirefox ?? true,
}); });
for (const warning of warnings) { for (const warning of warnings) {
@@ -299,6 +303,8 @@ program
ct0: opts.ct0, ct0: opts.ct0,
chromeProfile: opts.chromeProfile || config.chromeProfile, chromeProfile: opts.chromeProfile || config.chromeProfile,
firefoxProfile: opts.firefoxProfile || config.firefoxProfile, firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
allowChrome: config.allowChrome ?? true,
allowFirefox: config.allowFirefox ?? true,
}); });
for (const warning of warnings) { for (const warning of warnings) {
@@ -390,6 +396,8 @@ program
ct0: opts.ct0, ct0: opts.ct0,
chromeProfile: opts.chromeProfile || config.chromeProfile, chromeProfile: opts.chromeProfile || config.chromeProfile,
firefoxProfile: opts.firefoxProfile || config.firefoxProfile, firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
allowChrome: config.allowChrome ?? true,
allowFirefox: config.allowFirefox ?? true,
}); });
for (const warning of warnings) { for (const warning of warnings) {
@@ -778,6 +786,8 @@ program
ct0: opts.ct0, ct0: opts.ct0,
chromeProfile: opts.chromeProfile || config.chromeProfile, chromeProfile: opts.chromeProfile || config.chromeProfile,
firefoxProfile: opts.firefoxProfile || config.firefoxProfile, firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
allowChrome: config.allowChrome ?? true,
allowFirefox: config.allowFirefox ?? true,
}); });
for (const warning of warnings) { for (const warning of warnings) {
+7 -2
View File
@@ -294,6 +294,8 @@ export async function resolveCredentials(options: {
ct0?: string; ct0?: string;
chromeProfile?: string; chromeProfile?: string;
firefoxProfile?: string; firefoxProfile?: string;
allowChrome?: boolean;
allowFirefox?: boolean;
}): Promise<CookieExtractionResult> { }): Promise<CookieExtractionResult> {
const warnings: string[] = []; const warnings: string[] = [];
const cookies: TwitterCookies = { const cookies: TwitterCookies = {
@@ -338,8 +340,11 @@ export async function resolveCredentials(options: {
} }
} }
const allowFirefox = options.allowFirefox ?? true;
const allowChrome = options.allowChrome ?? true;
// 3. Firefox cookies (preferred browser fallback) // 3. Firefox cookies (preferred browser fallback)
if (!cookies.authToken || !cookies.ct0) { if (allowFirefox && (!cookies.authToken || !cookies.ct0)) {
const firefoxResult = await extractCookiesFromFirefox(options.firefoxProfile); const firefoxResult = await extractCookiesFromFirefox(options.firefoxProfile);
warnings.push(...firefoxResult.warnings); warnings.push(...firefoxResult.warnings);
@@ -354,7 +359,7 @@ export async function resolveCredentials(options: {
} }
// 4. Chrome cookies (secondary browser fallback) // 4. Chrome cookies (secondary browser fallback)
if (!cookies.authToken || !cookies.ct0) { if (allowChrome && (!cookies.authToken || !cookies.ct0)) {
const chromeResult = await extractCookiesFromChrome(options.chromeProfile); const chromeResult = await extractCookiesFromChrome(options.chromeProfile);
warnings.push(...chromeResult.warnings); warnings.push(...chromeResult.warnings);