Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/events/components/dotcom-cookies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isHeadless } from './is-headless'

// We cannot use Cookies.get() on the frontend for httpOnly cookies
// so we need to make a request to the server to get the cookies

type DotcomCookies = {
dotcomUsername?: string
isStaff?: boolean
}

Expand All @@ -19,6 +20,8 @@ const LOCAL_STORAGE_KEY = 'dotcomCookies'
// If a user is staff and they didn't happen to be logged in when these cookies were saved,
// we can instruct them as needed to update the cookies and correctly set the isStaff flag.
async function fetchCookies(): Promise<DotcomCookies> {
if (isHeadless()) return { isStaff: false }

// Return the cached object if we have it in memory.
if (cachedCookies) {
return cachedCookies
Expand Down Expand Up @@ -63,7 +66,6 @@ async function fetchCookies(): Promise<DotcomCookies> {
console.error('Error fetching cookies:', err)
// On failure, return default values.
const defaultCookies: DotcomCookies = {
dotcomUsername: '',
isStaff: false,
}
cachedCookies = defaultCookies
Expand All @@ -81,8 +83,3 @@ export async function getIsStaff(): Promise<boolean> {
const cookies = await fetchCookies()
return cookies.isStaff || false
}

export async function getDotcomUsername(): Promise<string> {
const cookies = await fetchCookies()
return cookies.dotcomUsername || ''
}
3 changes: 3 additions & 0 deletions src/events/components/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Router } from 'next/router'
import { isLoggedIn } from 'src/frame/components/hooks/useHasAccount'
import { getExperimentVariationForContext } from './experiments/experiment'
import { EventType, EventPropsByType } from '../types'
import { isHeadless } from './is-headless'

const COOKIE_NAME = '_docs-events'

Expand Down Expand Up @@ -73,6 +74,8 @@ export function sendEvent<T extends EventType>({
eventGroupKey?: string
eventGroupId?: string
} & EventPropsByType[T]) {
if (isHeadless()) return

const body = {
type,

Expand Down
18 changes: 18 additions & 0 deletions src/events/components/is-headless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Basic checks for if the browser is actually a headless browser robot

declare global {
interface Window {
GHDOCSPLAYWRIGHT: any
}
}

export function isHeadless(): boolean {
if (window.GHDOCSPLAYWRIGHT) return false
if (navigator.webdriver) return true
if (/headless/i.test(navigator.userAgent)) return true
if (/headless/i.test(navigator.appVersion)) return true
if (!window.outerHeight || !window.innerHeight) return true
if (navigator.languages?.length === 0) return true
if (navigator.mimeTypes?.length === 0) return true
return false
}
8 changes: 8 additions & 0 deletions src/fixtures/tests/playwright-rendering.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ test.describe('survey', () => {
// See https://github.com/microsoft/playwright/issues/12231
})

await page.addInitScript(() => {
window.GHDOCSPLAYWRIGHT = 1
})

await page.goto('/get-started/foo/for-playwright')

// The label is visually an SVG. Finding it by its `for` value feels easier.
Expand Down Expand Up @@ -709,6 +713,10 @@ test.describe('survey', () => {
// See https://github.com/microsoft/playwright/issues/12231
})

await page.addInitScript(() => {
window.GHDOCSPLAYWRIGHT = 1
})

await page.goto('/get-started/foo/for-playwright')

await page.locator('[for=survey-yes]').click()
Expand Down
1 change: 0 additions & 1 deletion src/frame/middleware/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ router.get('/cookies', (req, res) => {
noCacheControl(res)
const cookies = {
isStaff: Boolean(req.cookies?.staffonly?.startsWith('yes')) || false,
dotcomUsername: req.cookies?.dotcom_user || '',
}
return res.json(cookies)
})
Expand Down
16 changes: 14 additions & 2 deletions src/ghes-releases/lib/enterprise-dates.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,22 @@
},
"3.19": {
"releaseDate": "2025-11-11",
"deprecationDate": "2026-12-02"
"deprecationDate": "2026-12-09"
},
"3.20": {
"releaseDate": "2026-02-17",
"deprecationDate": "2027-03-10"
"deprecationDate": "2027-03-17"
},
"3.21": {
"releaseDate": "2026-05-12",
"deprecationDate": "2027-06-02"
},
"3.22": {
"releaseDate": "2026-08-04",
"deprecationDate": "2027-08-25"
},
"3.23": {
"releaseDate": "2026-11-10",
"deprecationDate": "2027-12-08"
}
}