Skip to content

Commit a4539c4

Browse files
committed
fix(goto): skip cookies from headers
Cookies are parsed and set via `page.setCookie`, so they have to be excluded from being set via `page.setExtraHTTPHeaders`.
1 parent 2668c86 commit a4539c4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/goto/src/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
326326
const headersKeys = Object.keys(headers)
327327

328328
if (headersKeys.length > 0) {
329+
const { cookie, ...headersWithoutCookie } = headers
330+
329331
if (headers.cookie) {
330332
const cookies = parseCookies(url, headers.cookie)
331333
prePromises.push(
@@ -337,6 +339,9 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
337339
)
338340
}
339341

342+
const extraHTTPHeaders = headers.cookie ? headersWithoutCookie : headers
343+
const extraHTTPHeadersKeys = Object.keys(extraHTTPHeaders)
344+
340345
if (headers['user-agent']) {
341346
prePromises.push(
342347
run({
@@ -347,13 +352,15 @@ module.exports = ({ defaultDevice = 'Macbook Pro 13', timeout: globalTimeout, ..
347352
)
348353
}
349354

350-
prePromises.push(
351-
run({
352-
fn: page.setExtraHTTPHeaders(headers),
353-
timeout: actionTimeout,
354-
debug: { headers: headersKeys }
355-
})
356-
)
355+
if (extraHTTPHeadersKeys.length > 0) {
356+
prePromises.push(
357+
run({
358+
fn: page.setExtraHTTPHeaders(extraHTTPHeaders),
359+
timeout: actionTimeout,
360+
debug: { headers: extraHTTPHeadersKeys }
361+
})
362+
)
363+
}
357364
}
358365

359366
if (timezone) {

0 commit comments

Comments
 (0)