Fix Firefox cookie expiry conversion for Playwright
Some Firefox cookies store expiry in milliseconds instead of seconds. Detect values beyond year 2100 and convert to seconds. Also map zero/negative expiry to -1 for Playwright session cookies. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vendored
+1
-1
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"firefox.d.ts","sourceRoot":"","sources":["../src/firefox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;CACrC;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACpB;AAuFD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,EAAE,CAItD;AAsFD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,aAAa,EAAE,CAmClB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACrC,CAWA"}
|
{"version":3,"file":"firefox.d.ts","sourceRoot":"","sources":["../src/firefox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;CACrC;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACpB;AAuFD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,cAAc,EAAE,CAItD;AAsFD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,aAAa,EAAE,CAmClB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACrC,CAsBA"}
|
||||||
Vendored
+11
-1
@@ -215,12 +215,22 @@ export function importFirefoxCookies(options) {
|
|||||||
* Convert FirefoxCookie to Playwright cookie format
|
* Convert FirefoxCookie to Playwright cookie format
|
||||||
*/
|
*/
|
||||||
export function toPlaywrightCookie(cookie) {
|
export function toPlaywrightCookie(cookie) {
|
||||||
|
// Firefox uses 0 for session cookies; Playwright requires -1 or positive unix timestamp (seconds).
|
||||||
|
// Some Firefox cookies store expiry in milliseconds instead of seconds — detect and convert.
|
||||||
|
// Any expiry > year 2100 in seconds (4102444800) is likely milliseconds.
|
||||||
|
let expires = cookie.expires;
|
||||||
|
if (expires > 4102444800) {
|
||||||
|
expires = Math.floor(expires / 1000);
|
||||||
|
}
|
||||||
|
if (expires <= 0) {
|
||||||
|
expires = -1;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
name: cookie.name,
|
name: cookie.name,
|
||||||
value: cookie.value,
|
value: cookie.value,
|
||||||
domain: cookie.domain,
|
domain: cookie.domain,
|
||||||
path: cookie.path,
|
path: cookie.path,
|
||||||
expires: cookie.expires,
|
expires,
|
||||||
secure: cookie.secure,
|
secure: cookie.secure,
|
||||||
httpOnly: cookie.httpOnly,
|
httpOnly: cookie.httpOnly,
|
||||||
sameSite: cookie.sameSite,
|
sameSite: cookie.sameSite,
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+12
-1
@@ -272,12 +272,23 @@ export function toPlaywrightCookie(cookie: FirefoxCookie): {
|
|||||||
httpOnly: boolean;
|
httpOnly: boolean;
|
||||||
sameSite: 'Strict' | 'Lax' | 'None';
|
sameSite: 'Strict' | 'Lax' | 'None';
|
||||||
} {
|
} {
|
||||||
|
// Firefox uses 0 for session cookies; Playwright requires -1 or positive unix timestamp (seconds).
|
||||||
|
// Some Firefox cookies store expiry in milliseconds instead of seconds — detect and convert.
|
||||||
|
// Any expiry > year 2100 in seconds (4102444800) is likely milliseconds.
|
||||||
|
let expires = cookie.expires;
|
||||||
|
if (expires > 4102444800) {
|
||||||
|
expires = Math.floor(expires / 1000);
|
||||||
|
}
|
||||||
|
if (expires <= 0) {
|
||||||
|
expires = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: cookie.name,
|
name: cookie.name,
|
||||||
value: cookie.value,
|
value: cookie.value,
|
||||||
domain: cookie.domain,
|
domain: cookie.domain,
|
||||||
path: cookie.path,
|
path: cookie.path,
|
||||||
expires: cookie.expires,
|
expires,
|
||||||
secure: cookie.secure,
|
secure: cookie.secure,
|
||||||
httpOnly: cookie.httpOnly,
|
httpOnly: cookie.httpOnly,
|
||||||
sameSite: cookie.sameSite,
|
sameSite: cookie.sameSite,
|
||||||
|
|||||||
Reference in New Issue
Block a user