From c64c61ce9203915a1f7901347943de0c3f9ea118 Mon Sep 17 00:00:00 2001 From: Swair Shah Date: Tue, 3 Feb 2026 14:04:49 -0800 Subject: [PATCH] fix: cast expires_utc to TEXT for Node < 24.4 sqlite compatibility On Node 22.x, the node:sqlite module throws an error when encountering integers larger than Number.MAX_SAFE_INTEGER. Chrome stores cookie expiration timestamps (expires_utc) as large integers that exceed this limit. The readBigInts option that would handle this was only added in Node 24.4. This patch casts expires_utc to TEXT in the SQL query when running on Node < 24.4, which avoids the overflow error. The existing code already handles parsing string values via tryParseInt(). Fixes #82 Related: https://github.com/steipete/sweet-cookie/issues/16 Co-Authored-By: Claude Opus 4.5 --- patches/@steipete__sweet-cookie.patch | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/patches/@steipete__sweet-cookie.patch b/patches/@steipete__sweet-cookie.patch index 12ab8a5..bf1710d 100644 --- a/patches/@steipete__sweet-cookie.patch +++ b/patches/@steipete__sweet-cookie.patch @@ -74,3 +74,20 @@ index 71c815f77378d03e07061976ac372b3a55a61ac4..b21c15640955a8e7faa8f1d6ea6fed7c args.profile = profile; return resolveCookiesDbFromProfileOrRoots(args); } +diff --git a/dist/providers/chromeSqlite/shared.js b/dist/providers/chromeSqlite/shared.js +index 1234567890abcdef..fedcba0987654321 100644 +--- a/dist/providers/chromeSqlite/shared.js ++++ b/dist/providers/chromeSqlite/shared.js +@@ -185,9 +185,13 @@ async function readChromeRows(dbPath, where) { + const sqliteKind = isBunRuntime() ? 'bun' : 'node'; + const sqliteLabel = sqliteKind === 'bun' ? 'bun:sqlite' : 'node:sqlite'; +- const sql = `SELECT name, value, host_key, path, expires_utc, samesite, encrypted_value, ` + ++ // Cast expires_utc to TEXT to avoid integer overflow errors on Node < 24.4 ++ // where readBigInts option is not available. The code already handles string parsing. ++ const expiresCol = (sqliteKind === 'node' && !supportsReadBigInts()) ++ ? 'CAST(expires_utc AS TEXT) AS expires_utc' ++ : 'expires_utc'; ++ const sql = `SELECT name, value, host_key, path, ${expiresCol}, samesite, encrypted_value, ` + + `is_secure AS is_secure, is_httponly AS is_httponly ` + + `FROM cookies WHERE (${where}) ORDER BY expires_utc DESC;`; + const result = await queryNodeOrBun({ kind: sqliteKind, dbPath, sql });