Skip to content

Commit

Permalink
rage
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 14, 2023
1 parent f723d39 commit 6ba226d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
21 changes: 16 additions & 5 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,26 @@ export function seekFirstNonPublicSubDomain(hostname: string, cookieJar = docume
}
return ''
}
// TRICKY: this is important enough functionality that we need to test it
// but, it relies on browser behavior, so we set it on window here
// so that we can access it in browser-based tests
;(window as any).POSTHOG_INTERNAL_seekFirstNonPublicSubDomain = seekFirstNonPublicSubDomain

const DOMAIN_MATCH_REGEX = /[a-z0-9][a-z0-9-]+\.[a-z]{2,}$/i
const originalCookieDomainFn = (hostname: string): string => {
const matches = hostname.match(DOMAIN_MATCH_REGEX)
return matches ? matches[0] : ''
}

export function chooseCookieDomain(hostname: string, cross_subdomain: boolean | undefined): string {
if (cross_subdomain) {
// NOTE: Could we use this for cross domain tracking?
const matchedSubDomain = seekFirstNonPublicSubDomain(hostname)
let matchedSubDomain = seekFirstNonPublicSubDomain(hostname)

if (!matchedSubDomain) {
const originalMatch = originalCookieDomainFn(hostname)
if (originalMatch !== matchedSubDomain) {
logger.info('Warning: cookie subdomain discovery mismatch', originalMatch, matchedSubDomain)
}
matchedSubDomain = originalMatch
}

return matchedSubDomain ? '; domain=.' + matchedSubDomain : ''
}
return ''
Expand Down
46 changes: 0 additions & 46 deletions testcafe/subdomain.detection.spec.js

This file was deleted.

0 comments on commit 6ba226d

Please sign in to comment.