@dongdev/fca-unofficial 3.0.17 → 3.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/module/loginHelper.js +88 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/module/loginHelper.js
CHANGED
|
@@ -289,26 +289,101 @@ async function setJarCookies(j, appstate) {
|
|
|
289
289
|
const cookiePath = c.path || "/";
|
|
290
290
|
const dom = cookieDomain.replace(/^\./, "");
|
|
291
291
|
|
|
292
|
-
//
|
|
292
|
+
// Handle expirationDate (can be in seconds or milliseconds)
|
|
293
293
|
let expiresStr = "";
|
|
294
|
-
if (c.
|
|
294
|
+
if (c.expirationDate !== undefined) {
|
|
295
|
+
let expiresDate;
|
|
296
|
+
if (typeof c.expirationDate === "number") {
|
|
297
|
+
// If expirationDate is less than a year from now in seconds, treat as seconds
|
|
298
|
+
// Otherwise treat as milliseconds
|
|
299
|
+
const now = Date.now();
|
|
300
|
+
const oneYearInMs = 365 * 24 * 60 * 60 * 1000;
|
|
301
|
+
if (c.expirationDate < (now + oneYearInMs) / 1000) {
|
|
302
|
+
expiresDate = new Date(c.expirationDate * 1000);
|
|
303
|
+
} else {
|
|
304
|
+
expiresDate = new Date(c.expirationDate);
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
expiresDate = new Date(c.expirationDate);
|
|
308
|
+
}
|
|
309
|
+
expiresStr = `; expires=${expiresDate.toUTCString()}`;
|
|
310
|
+
} else if (c.expires) {
|
|
295
311
|
const expiresDate = typeof c.expires === "number" ? new Date(c.expires) : new Date(c.expires);
|
|
296
312
|
expiresStr = `; expires=${expiresDate.toUTCString()}`;
|
|
297
313
|
}
|
|
298
314
|
|
|
299
|
-
//
|
|
300
|
-
const
|
|
315
|
+
// Helper function to build cookie string
|
|
316
|
+
const buildCookieString = (domainOverride = null) => {
|
|
317
|
+
const domain = domainOverride || cookieDomain;
|
|
318
|
+
let cookieParts = [`${cookieName}=${cookieValue}${expiresStr}`];
|
|
319
|
+
cookieParts.push(`Domain=${domain}`);
|
|
320
|
+
cookieParts.push(`Path=${cookiePath}`);
|
|
321
|
+
|
|
322
|
+
// Add Secure flag if secure is true
|
|
323
|
+
if (c.secure === true) {
|
|
324
|
+
cookieParts.push("Secure");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Add HttpOnly flag if httpOnly is true
|
|
328
|
+
if (c.httpOnly === true) {
|
|
329
|
+
cookieParts.push("HttpOnly");
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Add SameSite attribute if provided
|
|
333
|
+
if (c.sameSite) {
|
|
334
|
+
const sameSiteValue = String(c.sameSite).toLowerCase();
|
|
335
|
+
if (["strict", "lax", "none"].includes(sameSiteValue)) {
|
|
336
|
+
cookieParts.push(`SameSite=${sameSiteValue.charAt(0).toUpperCase() + sameSiteValue.slice(1)}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return cookieParts.join("; ");
|
|
341
|
+
};
|
|
301
342
|
|
|
302
|
-
//
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
343
|
+
// Determine target URLs and cookie strings based on domain
|
|
344
|
+
const cookieConfigs = [];
|
|
345
|
+
|
|
346
|
+
// For .facebook.com domain, set for both facebook.com and messenger.com
|
|
347
|
+
if (cookieDomain === ".facebook.com" || cookieDomain === "facebook.com") {
|
|
348
|
+
// Set for facebook.com with .facebook.com domain
|
|
349
|
+
cookieConfigs.push({ url: `http://${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
350
|
+
cookieConfigs.push({ url: `https://${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
351
|
+
cookieConfigs.push({ url: `http://www.${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
352
|
+
cookieConfigs.push({ url: `https://www.${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
353
|
+
|
|
354
|
+
// Set for messenger.com with .messenger.com domain (or without domain for host-only)
|
|
355
|
+
// Use .messenger.com domain to allow cross-subdomain sharing
|
|
356
|
+
cookieConfigs.push({ url: `http://messenger.com${cookiePath}`, cookieStr: buildCookieString(".messenger.com") });
|
|
357
|
+
cookieConfigs.push({ url: `https://messenger.com${cookiePath}`, cookieStr: buildCookieString(".messenger.com") });
|
|
358
|
+
cookieConfigs.push({ url: `http://www.messenger.com${cookiePath}`, cookieStr: buildCookieString(".messenger.com") });
|
|
359
|
+
cookieConfigs.push({ url: `https://www.messenger.com${cookiePath}`, cookieStr: buildCookieString(".messenger.com") });
|
|
360
|
+
} else if (cookieDomain === ".messenger.com" || cookieDomain === "messenger.com") {
|
|
361
|
+
// Set for messenger.com only
|
|
362
|
+
const messengerDom = cookieDomain.replace(/^\./, "");
|
|
363
|
+
cookieConfigs.push({ url: `http://${messengerDom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
364
|
+
cookieConfigs.push({ url: `https://${messengerDom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
365
|
+
cookieConfigs.push({ url: `http://www.${messengerDom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
366
|
+
cookieConfigs.push({ url: `https://www.${messengerDom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
367
|
+
} else {
|
|
368
|
+
// For other domains, set normally
|
|
369
|
+
cookieConfigs.push({ url: `http://${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
370
|
+
cookieConfigs.push({ url: `https://${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
371
|
+
cookieConfigs.push({ url: `http://www.${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
372
|
+
cookieConfigs.push({ url: `https://www.${dom}${cookiePath}`, cookieStr: buildCookieString() });
|
|
373
|
+
}
|
|
307
374
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
375
|
+
// Set cookie for all target URLs, silently catch domain errors
|
|
376
|
+
for (const config of cookieConfigs) {
|
|
377
|
+
tasks.push(j.setCookie(config.cookieStr, config.url).catch((err) => {
|
|
378
|
+
// Silently ignore domain mismatch errors for cross-domain cookies
|
|
379
|
+
// These are expected when setting cookies across domains
|
|
380
|
+
if (err && err.message && err.message.includes("Cookie not in this host's domain")) {
|
|
381
|
+
return; // Expected error, ignore
|
|
382
|
+
}
|
|
383
|
+
// Log other errors but don't throw
|
|
384
|
+
return;
|
|
385
|
+
}));
|
|
386
|
+
}
|
|
312
387
|
}
|
|
313
388
|
await Promise.all(tasks);
|
|
314
389
|
}
|
package/package.json
CHANGED