@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @poncho-ai/browser@0.6.3 build /home/runner/work/poncho-ai/poncho-ai/packages/browser
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
  CLI Building entry: src/index.ts
@@ -7,8 +7,8 @@
7
7
  CLI tsup v8.5.1
8
8
  CLI Target: es2022
9
9
  ESM Build start
10
- ESM dist/index.js 44.07 KB
11
- ESM ⚡️ Build success in 79ms
10
+ ESM dist/index.js 45.65 KB
11
+ ESM ⚡️ Build success in 112ms
12
12
  DTS Build start
13
- DTS ⚡️ Build success in 4573ms
13
+ DTS ⚡️ Build success in 1828ms
14
14
  DTS dist/index.d.ts 13.72 KB
@@ -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
+  RUN  v1.6.1 /Users/cesar/Dev/latitude/poncho-ai/packages/browser
7
+
8
+ No test files found, exiting with code 0
9
+ include: **/*.{test,spec}.?(c|m)[jt]s?(x)
10
+
11
+ exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*
12
+ watch exclude: **/node_modules/**, **/dist/**
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
- await cdp.send("Network.setCookies", { cookies: state.cookies });
945
- console.log(`[poncho][browser] Restored ${state.cookies.length} cookies`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poncho-ai/browser",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Browser automation for Poncho agents, powered by agent-browser",
5
5
  "repository": {
6
6
  "type": "git",
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 () => { tab!.frameListeners.delete(listener); };
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
- await cdp.send("Network.setCookies", { cookies: state.cookies });
900
- console.log(`[poncho][browser] Restored ${state.cookies.length} cookies`);
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 }>> = {};