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
10 changes: 9 additions & 1 deletion packages/core/src/browser/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
generateUUID,
} from '../tools/utils/stringUtils'
import { buildUrl } from '../tools/utils/urlPolyfill'
import { globalObject } from '../tools/globalObject'

export interface CookieOptions {
secure?: boolean
Expand Down Expand Up @@ -75,7 +76,14 @@ export function deleteCookie(name: string, options?: CookieOptions) {
* https://web.dev/same-site-same-origin/#site
*/
let getCurrentSiteCache: string | undefined
export function getCurrentSite(hostname = location.hostname, referrer = document.referrer): string | undefined {
export function getCurrentSite(
hostname = globalObject.location?.hostname ?? '',
Comment thread
mormubis marked this conversation as resolved.
referrer = typeof document !== 'undefined' ? document.referrer : ''
): string | undefined {
// Cookie probing requires document.cookie, which is not available in Web Workers or Node.js
if (typeof document === 'undefined') {
return undefined
}
Comment on lines +84 to +86

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to add this bit to actually fix the codex p2.

if (getCurrentSiteCache === undefined) {
const defaultHostName = getCookieDefaultHostName(hostname, referrer)
if (defaultHostName) {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/domain/context/storeContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export function storeContextManager(
productKey: string,
customerDataType: CustomerDataType
) {
// window and localStorage are not available in Web Workers or Node.js environments
if (typeof window === 'undefined' || typeof localStorage === 'undefined') {
return
}

const storageKey = buildStorageKey(productKey, customerDataType)

storageListeners.push(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tools/utils/urlPolyfill.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { globalObject } from '../globalObject'

export function normalizeUrl(url: string) {
return buildUrl(url, location.href).href
return buildUrl(url, globalObject.location?.href).href
}

export function isValidUrl(url: string) {
Expand Down
Loading