Skip to content

Commit 794c655

Browse files
committed
[chrome] implement sendSetCookie
1 parent 8ed25c8 commit 794c655

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/chrome/src/proxy/scramjet.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ class ProxyFrameContext {
158158
this.rpc.recieve(event.data);
159159
});
160160
}
161+
162+
alive(): boolean {
163+
// the windowproxy *object* will still exist, so we need to check if there's still a path to it
164+
return findSelfSequence(this.windowproxy!) !== null;
165+
}
161166
}
162167

163168
export let contexts: ProxyFrameContext[] = [];
@@ -262,7 +267,30 @@ export function createFetchHandler(controller: Controller) {
262267
headers,
263268
}) as BareResponseFetch;
264269
},
265-
async sendSetCookie(url: URL, cookie: string) {},
270+
async sendSetCookie(url: URL, cookie: string) {
271+
let promises: Promise<any>[] = [];
272+
for (const context of contexts) {
273+
if (context.alive()) {
274+
promises.push(
275+
context.rpc.call("setCookie", {
276+
url: url.href,
277+
cookie,
278+
})
279+
);
280+
}
281+
}
282+
283+
// a context could be deadlocked, so add a safety
284+
await Promise.race([
285+
new Promise((res) =>
286+
setTimeout(() => {
287+
console.error("a context deadlocked! hit timeout");
288+
res(null);
289+
}, 1000)
290+
),
291+
Promise.all(promises),
292+
]);
293+
},
266294
});
267295

268296
return fetchHandler;

0 commit comments

Comments
 (0)