Skip to content

Commit

Permalink
feat: support hasCrossSiteAncestor
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Dec 18, 2024
1 parent 4476dc0 commit 732f916
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/bidiMapper/modules/network/NetworkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ export function bidiToCdpCookie(
httpOnly: params.cookie.httpOnly ?? false,
...(partitionKey.sourceOrigin !== undefined && {
partitionKey: {
hasCrossSiteAncestor: false,
hasCrossSiteAncestor: Boolean(
partitionKey['goog:hasCrossSiteAncestor'],
),
// CDP's `partitionKey.topLevelSite` is the BiDi's `partition.sourceOrigin`.
topLevelSite: partitionKey.sourceOrigin,
},
Expand Down
16 changes: 14 additions & 2 deletions src/bidiMapper/modules/storage/StorageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export class StorageProcessor {
// are returned.
(c) =>
partitionKey.sourceOrigin === undefined ||
c.partitionKey?.topLevelSite === partitionKey.sourceOrigin,
(c.partitionKey?.topLevelSite === partitionKey.sourceOrigin &&
c.partitionKey?.hasCrossSiteAncestor ===
partitionKey['goog:hasCrossSiteAncestor']),
)
.filter((cdpCookie) => {
const bidiCookie = cdpToBiDiCookie(cdpCookie);
Expand Down Expand Up @@ -212,7 +214,12 @@ export class StorageProcessor {
if (
key !== undefined &&
value !== undefined &&
!['type', 'sourceOrigin', 'userContext'].includes(key)
![
'type',
'sourceOrigin',
'userContext',
'goog:hasCrossSiteAncestor',
].includes(key)
) {
unsupportedPartitionKeys.set(key, value);
}
Expand All @@ -229,10 +236,15 @@ export class StorageProcessor {

// Set `userContext` to `default` if not provided, as it's required in Chromium.
const userContext = descriptor.userContext ?? 'default';
const hasCrossSiteAncestor =
descriptor['goog:hasCrossSiteAncestor'] ?? false;

return {
userContext,
...(sourceOrigin === undefined ? {} : {sourceOrigin}),
...(sourceOrigin === undefined
? {}
: {'goog:hasCrossSiteAncestor': hasCrossSiteAncestor}),
};
}

Expand Down

0 comments on commit 732f916

Please sign in to comment.