@@ -381,19 +381,56 @@ export class CRBrowserContext extends BrowserContext {
381381  async  doGetCookies ( urls : string [ ] ) : Promise < channels . NetworkCookie [ ] >  { 
382382    const  {  cookies }  =  await  this . _browser . _session . send ( 'Storage.getCookies' ,  {  browserContextId : this . _browserContextId  } ) ; 
383383    return  network . filterCookies ( cookies . map ( c  =>  { 
384-       const  copy : any  =  {  sameSite : 'Lax' ,  ...c  } ; 
385-       delete  copy . size ; 
386-       delete  copy . priority ; 
387-       delete  copy . session ; 
388-       delete  copy . sameParty ; 
389-       delete  copy . sourceScheme ; 
390-       delete  copy . sourcePort ; 
391-       return  copy  as  channels . NetworkCookie ; 
384+       const  {  name,  value,  domain,  path,  expires,  httpOnly,  secure,  sameSite }  =  c ; 
385+       const  copy : channels . NetworkCookie  =  { 
386+         name, 
387+         value, 
388+         domain, 
389+         path, 
390+         expires, 
391+         httpOnly, 
392+         secure, 
393+         sameSite : sameSite  ??  'Lax' , 
394+       } ; 
395+       // If hasCrossSiteAncestor is false, the cookie is a partitioned first party cookie, 
396+       // this is Chromium specific, see https://chromestatus.com/feature/5144832583663616 
397+       // and https://github.com/explainers-by-googlers/CHIPS-spec. 
398+       if  ( c . partitionKey )  { 
399+         copy . _crHasCrossSiteAncestor  =  c . partitionKey . hasCrossSiteAncestor ; 
400+         copy . partitionKey  =  c . partitionKey . topLevelSite ; 
401+       } 
402+       return  copy ; 
392403    } ) ,  urls ) ; 
393404  } 
394405
395406  async  addCookies ( cookies : channels . SetNetworkCookie [ ] )  { 
396-     await  this . _browser . _session . send ( 'Storage.setCookies' ,  {  cookies : network . rewriteCookies ( cookies ) ,  browserContextId : this . _browserContextId  } ) ; 
407+     function  toChromiumCookie ( cookie : channels . SetNetworkCookie )  { 
408+       const  {  name,  value,  url,  domain,  path,  expires,  httpOnly,  secure,  sameSite,  partitionKey,  _crHasCrossSiteAncestor }  =  cookie ; 
409+       const  copy : Protocol . Network . CookieParam  =  { 
410+         name, 
411+         value, 
412+         url, 
413+         domain, 
414+         path, 
415+         expires, 
416+         httpOnly, 
417+         secure, 
418+         sameSite
419+       } ; 
420+       if  ( partitionKey )  { 
421+         copy . partitionKey  =  { 
422+           topLevelSite : partitionKey , 
423+           // _crHasCrossSiteAncestor is non-standard, set it true by default if the cookie is partitioned. 
424+           hasCrossSiteAncestor : _crHasCrossSiteAncestor  ??  true , 
425+         } ; 
426+       } 
427+       return  copy ; 
428+     } 
429+ 
430+     await  this . _browser . _session . send ( 'Storage.setCookies' ,  { 
431+       cookies : network . rewriteCookies ( cookies ) . map ( toChromiumCookie ) , 
432+       browserContextId : this . _browserContextId 
433+     } ) ; 
397434  } 
398435
399436  async  doClearCookies ( )  { 
0 commit comments