Skip to content

Commit 51549f7

Browse files
committed
fix: append cookies instead
1 parent b45ca91 commit 51549f7

3 files changed

Lines changed: 16 additions & 26 deletions

File tree

src/components/dictionaries/network-compat.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async function installMv3HeaderRule(
155155
if (cookieHeader) {
156156
requestHeaders.push({
157157
header: 'cookie',
158-
operation: 'set',
158+
operation: 'append',
159159
value: cookieHeader
160160
})
161161
}
@@ -190,15 +190,13 @@ async function getCookieHeader(
190190
const partitionKey = {
191191
topLevelSite: options.topLevelSite
192192
}
193-
const unpartitionedCookies = await getCookiesForRequest(cookiesApi, options)
194193
const partitionedCookies = await getCookiesForRequest(
195194
cookiesApi,
196195
options,
197196
partitionKey
198197
)
199-
const cookies = collectCookies(unpartitionedCookies, partitionedCookies)
200-
if (cookies.length > 0) {
201-
return stringifyCookies(cookies)
198+
if (partitionedCookies.length > 0) {
199+
return stringifyCookies(partitionedCookies)
202200
}
203201

204202
return stringifyCookies(
@@ -302,20 +300,6 @@ function stringifyCookies(cookies: Cookie[]) {
302300
return cookiePairs.join('; ')
303301
}
304302

305-
function collectCookies(...cookieLists: Cookie[][]) {
306-
const result: Cookie[] = []
307-
308-
for (const cookies of cookieLists) {
309-
for (const cookie of cookies) {
310-
if (cookie.name && cookie.value) {
311-
result.push({ name: cookie.name, value: cookie.value })
312-
}
313-
}
314-
}
315-
316-
return result
317-
}
318-
319303
function setRequestHeader(
320304
requestHeaders: Array<{ name: string; value?: string }>,
321305
name: string,

test/specs/components/dictionaries/cambridge/network.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { browser } from '../../../../helper'
22

3+
const getCookieQueryArgs = () =>
4+
browser.cookies.getAll.getCalls().map(call => call.args[0])
5+
36
describe('Dict/Cambridge/network', () => {
47
let originalWebRequest: typeof browser.webRequest
58

@@ -116,7 +119,7 @@ describe('Dict/Cambridge/network', () => {
116119

117120
await ensureNetworkCompatibility()
118121

119-
expect(browser.cookies.getAll.thirdCall.args[0]).toEqual({
122+
expect(getCookieQueryArgs()).toContainEqual({
120123
url: 'https://dictionary.cambridge.org',
121124
partitionKey: {
122125
topLevelSite: 'https://cambridge.org'
@@ -142,7 +145,7 @@ describe('Dict/Cambridge/network', () => {
142145
})
143146
})
144147

145-
it('should preserve same-name cookies in MV2', async () => {
148+
it('should append partitioned cookies in MV2', async () => {
146149
browser.cookies.getAll.callsFake(options =>
147150
Promise.resolve(
148151
options.partitionKey
@@ -318,7 +321,7 @@ describe('Dict/Cambridge/network', () => {
318321
},
319322
{
320323
header: 'cookie',
321-
operation: 'set',
324+
operation: 'append',
322325
value: 'cf_clearance=next-clearance-token'
323326
}
324327
]
@@ -362,7 +365,7 @@ describe('Dict/Cambridge/network', () => {
362365

363366
await ensureNetworkCompatibility()
364367

365-
expect(browser.cookies.getAll.thirdCall.args[0]).toEqual({
368+
expect(getCookieQueryArgs()).toContainEqual({
366369
url: 'https://dictionary.cambridge.org',
367370
partitionKey: {
368371
topLevelSite: 'https://cambridge.org'
@@ -382,7 +385,7 @@ describe('Dict/Cambridge/network', () => {
382385
},
383386
{
384387
header: 'cookie',
385-
operation: 'set',
388+
operation: 'append',
386389
value:
387390
'cf_clearance=partitioned-clearance-token; cf_chl_rc_ni=1'
388391
}

test/specs/components/dictionaries/cobuild/network.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { browser } from '../../../../helper'
22

3+
const getCookieQueryArgs = () =>
4+
browser.cookies.getAll.getCalls().map(call => call.args[0])
5+
36
describe('Dict/COBUILD/network', () => {
47
let originalWebRequest: typeof browser.webRequest
58

@@ -43,7 +46,7 @@ describe('Dict/COBUILD/network', () => {
4346

4447
await ensureNetworkCompatibility()
4548

46-
expect(browser.cookies.getAll.thirdCall.args[0]).toEqual({
49+
expect(getCookieQueryArgs()).toContainEqual({
4750
url: 'https://www.collinsdictionary.com',
4851
partitionKey: {
4952
topLevelSite: 'https://collinsdictionary.com'
@@ -117,7 +120,7 @@ describe('Dict/COBUILD/network', () => {
117120
},
118121
{
119122
header: 'cookie',
120-
operation: 'set',
123+
operation: 'append',
121124
value: 'cf_clearance=partitioned-clearance-token'
122125
}
123126
]

0 commit comments

Comments
 (0)