File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
packages/chrome/src/proxy Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff 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
163168export 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 ;
You can’t perform that action at this time.
0 commit comments