@poncho-ai/browser 0.6.3 → 0.6.4
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/.turbo/turbo-build.log +4 -4
- package/.turbo/turbo-test.log +12 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.js +44 -2
- package/package.json +1 -1
- package/src/session.ts +60 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @poncho-ai/browser@0.6.
|
|
2
|
+
> @poncho-ai/browser@0.6.4 build /Users/cesar/Dev/latitude/poncho-ai/packages/browser
|
|
3
3
|
> tsup src/index.ts --format esm --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
[34mCLI[39m tsup v8.5.1
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
11
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mESM[39m [1mdist/index.js [22m[32m45.65 KB[39m
|
|
11
|
+
[32mESM[39m ⚡️ Build success in 112ms
|
|
12
12
|
[34mDTS[39m Build start
|
|
13
|
-
[32mDTS[39m ⚡️ Build success in
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 1828ms
|
|
14
14
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m13.72 KB[39m
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
> @poncho-ai/browser@0.6.2 test /Users/cesar/Dev/latitude/poncho-ai/packages/browser
|
|
3
|
+
> vitest --passWithNoTests
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[7m[1m[36m RUN [39m[22m[27m [36mv1.6.1[39m [90m/Users/cesar/Dev/latitude/poncho-ai/packages/browser[39m
|
|
7
|
+
|
|
8
|
+
No test files found, exiting with code 0
|
|
9
|
+
[2minclude: [22m[33m**/*.{test,spec}.?(c|m)[jt]s?(x)[39m
|
|
10
|
+
|
|
11
|
+
[2mexclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[2m, [22m**/cypress/**[2m, [22m**/.{idea,git,cache,output,temp}/**[2m, [22m**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*[39m
|
|
12
|
+
[2mwatch exclude: [22m[33m**/node_modules/**[2m, [22m**/dist/**[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @poncho-ai/browser
|
|
2
2
|
|
|
3
|
+
## 0.6.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b5af10a`](https://github.com/cesr/poncho-ai/commit/b5af10a2f7b0023c683f14cd465105f8ddfff0ee) Thanks [@cesr](https://github.com/cesr)! - Fix browser cookie restore failing with "Invalid parameters" by sanitizing Playwright-format cookies to CDP-compatible format before calling Network.setCookies. Falls back to per-cookie restore when batch call fails.
|
|
8
|
+
|
|
3
9
|
## 0.6.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -186,6 +186,24 @@ async function getBrowserManagerCtor() {
|
|
|
186
186
|
return BrowserManagerCtor;
|
|
187
187
|
}
|
|
188
188
|
var MAX_TABS = 8;
|
|
189
|
+
var VALID_SAME_SITE = ["Strict", "Lax", "None"];
|
|
190
|
+
function sanitizeCookieForCDP(c) {
|
|
191
|
+
const name = typeof c.name === "string" ? c.name : "";
|
|
192
|
+
const value = typeof c.value === "string" ? c.value : "";
|
|
193
|
+
if (!name) return null;
|
|
194
|
+
const out = { name, value };
|
|
195
|
+
if (typeof c.domain === "string" && c.domain) out.domain = c.domain;
|
|
196
|
+
if (typeof c.path === "string") out.path = c.path;
|
|
197
|
+
if (typeof c.secure === "boolean") out.secure = c.secure;
|
|
198
|
+
if (typeof c.httpOnly === "boolean") out.httpOnly = c.httpOnly;
|
|
199
|
+
if (typeof c.expires === "number" && c.expires > 0) {
|
|
200
|
+
out.expires = c.expires;
|
|
201
|
+
}
|
|
202
|
+
if (typeof c.sameSite === "string" && VALID_SAME_SITE.includes(c.sameSite)) {
|
|
203
|
+
out.sameSite = c.sameSite;
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
189
207
|
var SAME_TAB_INIT_SCRIPT = `
|
|
190
208
|
(() => {
|
|
191
209
|
// Override window.open to navigate in-place
|
|
@@ -836,6 +854,10 @@ var BrowserSession = class {
|
|
|
836
854
|
tab.frameListeners.add(listener);
|
|
837
855
|
return () => {
|
|
838
856
|
tab.frameListeners.delete(listener);
|
|
857
|
+
if (tab.frameListeners.size === 0 && this._screencastConversation === conversationId) {
|
|
858
|
+
this.stopScreencast().catch(() => {
|
|
859
|
+
});
|
|
860
|
+
}
|
|
839
861
|
};
|
|
840
862
|
}
|
|
841
863
|
onStatus(conversationId, listener) {
|
|
@@ -941,8 +963,28 @@ var BrowserSession = class {
|
|
|
941
963
|
if (!json) return;
|
|
942
964
|
const state = JSON.parse(json);
|
|
943
965
|
if (state.cookies?.length) {
|
|
944
|
-
|
|
945
|
-
|
|
966
|
+
const sanitized = state.cookies.map(sanitizeCookieForCDP).filter((c) => c !== null);
|
|
967
|
+
if (sanitized.length) {
|
|
968
|
+
try {
|
|
969
|
+
await cdp.send("Network.setCookies", { cookies: sanitized });
|
|
970
|
+
} catch {
|
|
971
|
+
let restored = 0;
|
|
972
|
+
for (const cookie of sanitized) {
|
|
973
|
+
try {
|
|
974
|
+
await cdp.send("Network.setCookies", { cookies: [cookie] });
|
|
975
|
+
restored++;
|
|
976
|
+
} catch {
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
if (restored > 0) {
|
|
980
|
+
console.log(`[poncho][browser] Restored ${restored}/${sanitized.length} cookies (batch failed, fell back to individual)`);
|
|
981
|
+
} else {
|
|
982
|
+
console.warn("[poncho][browser] Could not restore any cookies");
|
|
983
|
+
}
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
console.log(`[poncho][browser] Restored ${sanitized.length} cookies`);
|
|
987
|
+
}
|
|
946
988
|
}
|
|
947
989
|
if (state.origins?.length) {
|
|
948
990
|
const entries = {};
|
package/package.json
CHANGED
package/src/session.ts
CHANGED
|
@@ -62,6 +62,37 @@ async function getBrowserManagerCtor(): Promise<new () => BrowserManagerInstance
|
|
|
62
62
|
|
|
63
63
|
const MAX_TABS = 8;
|
|
64
64
|
|
|
65
|
+
const VALID_SAME_SITE = ["Strict", "Lax", "None"];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Map a Playwright-format cookie to a CDP-compatible CookieParam, stripping
|
|
69
|
+
* unknown fields and fixing values that newer Chrome versions reject.
|
|
70
|
+
*/
|
|
71
|
+
function sanitizeCookieForCDP(c: Record<string, unknown>): Record<string, unknown> | null {
|
|
72
|
+
const name = typeof c.name === "string" ? c.name : "";
|
|
73
|
+
const value = typeof c.value === "string" ? c.value : "";
|
|
74
|
+
if (!name) return null;
|
|
75
|
+
|
|
76
|
+
const out: Record<string, unknown> = { name, value };
|
|
77
|
+
|
|
78
|
+
if (typeof c.domain === "string" && c.domain) out.domain = c.domain;
|
|
79
|
+
if (typeof c.path === "string") out.path = c.path;
|
|
80
|
+
if (typeof c.secure === "boolean") out.secure = c.secure;
|
|
81
|
+
if (typeof c.httpOnly === "boolean") out.httpOnly = c.httpOnly;
|
|
82
|
+
|
|
83
|
+
// Playwright uses -1 for session cookies; CDP expects the field to be
|
|
84
|
+
// absent for session cookies.
|
|
85
|
+
if (typeof c.expires === "number" && c.expires > 0) {
|
|
86
|
+
out.expires = c.expires;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof c.sameSite === "string" && VALID_SAME_SITE.includes(c.sameSite)) {
|
|
90
|
+
out.sameSite = c.sameSite;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
65
96
|
/**
|
|
66
97
|
* Init script that forces new-tab navigations (window.open, target="_blank")
|
|
67
98
|
* to open in the current tab. Runs before page scripts on every navigation.
|
|
@@ -779,7 +810,12 @@ export class BrowserSession {
|
|
|
779
810
|
this.tabs.set(conversationId, tab);
|
|
780
811
|
}
|
|
781
812
|
tab.frameListeners.add(listener);
|
|
782
|
-
return () => {
|
|
813
|
+
return () => {
|
|
814
|
+
tab!.frameListeners.delete(listener);
|
|
815
|
+
if (tab!.frameListeners.size === 0 && this._screencastConversation === conversationId) {
|
|
816
|
+
this.stopScreencast().catch(() => {});
|
|
817
|
+
}
|
|
818
|
+
};
|
|
783
819
|
}
|
|
784
820
|
|
|
785
821
|
onStatus(conversationId: string, listener: StatusListener): () => void {
|
|
@@ -896,8 +932,29 @@ export class BrowserSession {
|
|
|
896
932
|
origins?: Array<{ origin: string; localStorage: Array<{ name: string; value: string }> }>;
|
|
897
933
|
};
|
|
898
934
|
if (state.cookies?.length) {
|
|
899
|
-
|
|
900
|
-
|
|
935
|
+
const sanitized = state.cookies
|
|
936
|
+
.map(sanitizeCookieForCDP)
|
|
937
|
+
.filter((c): c is Record<string, unknown> => c !== null);
|
|
938
|
+
if (sanitized.length) {
|
|
939
|
+
try {
|
|
940
|
+
await cdp.send("Network.setCookies", { cookies: sanitized });
|
|
941
|
+
} catch {
|
|
942
|
+
let restored = 0;
|
|
943
|
+
for (const cookie of sanitized) {
|
|
944
|
+
try {
|
|
945
|
+
await cdp.send("Network.setCookies", { cookies: [cookie] });
|
|
946
|
+
restored++;
|
|
947
|
+
} catch { /* skip this cookie */ }
|
|
948
|
+
}
|
|
949
|
+
if (restored > 0) {
|
|
950
|
+
console.log(`[poncho][browser] Restored ${restored}/${sanitized.length} cookies (batch failed, fell back to individual)`);
|
|
951
|
+
} else {
|
|
952
|
+
console.warn("[poncho][browser] Could not restore any cookies");
|
|
953
|
+
}
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
console.log(`[poncho][browser] Restored ${sanitized.length} cookies`);
|
|
957
|
+
}
|
|
901
958
|
}
|
|
902
959
|
if (state.origins?.length) {
|
|
903
960
|
const entries: Record<string, Array<{ name: string; value: string }>> = {};
|