Skip to content

Commit 5662a55

Browse files
committed
puppeteer does not have document defined
Might need to await some page load or detect in puppeteer
1 parent 633118e commit 5662a55

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

site/src/api/api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ export const hardCodedCSRFCookie = (): string => {
1616
return csrfToken
1717
}
1818

19-
// Always attach CSRF token to all requests
20-
const token = document.head.querySelector('meta[property="csrf-token"]')
19+
// Always attach CSRF token to all requests.
20+
// In puppeteer the document is undefined. In those cases, just
21+
// do nothing.
22+
const token = typeof document !== 'undefined' ?
23+
document.head.querySelector('meta[property="csrf-token"]') :
24+
null
25+
2126
if (token !== null && token.getAttribute("content") !== null) {
2227
if (process.env.NODE_ENV === "development") {
2328
// Development mode uses a hard-coded CSRF token

0 commit comments

Comments
 (0)