This commit is contained in:
Hailey
2024-07-11 19:47:54 -07:00
parent eb53b61136
commit 1c1d45ba5a
@@ -7,30 +7,27 @@ export function getGooglePlayReferrerInfoAsync(): Promise<GooglePlayReferrerInfo
throw new NotImplementedError() throw new NotImplementedError()
} }
export function getReferrerInfoAsync(): Promise<ReferrerInfo | null> { export async function getReferrerInfoAsync(): Promise<ReferrerInfo | null> {
// Returning a promise to match the functionality on native if (
return new Promise(resolve => { Platform.OS === 'web' &&
if ( // for ssr
Platform.OS === 'web' && typeof document !== 'undefined' &&
// for ssr document != null &&
typeof document !== 'undefined' && document.referrer
document != null && ) {
document.referrer try {
) { const url = new URL(document.referrer)
try { if (url.hostname !== 'bsky.app') {
const url = new URL(document.referrer) return {
if (url.hostname !== 'bsky.app') { referrer: url.href,
resolve({ hostname: url.hostname,
referrer: url.href,
hostname: url.hostname,
})
} }
} catch {
// If something happens to the URL parsing, we don't want to actually cause any problems for the user. Just
// log the error so we might catch it
console.error('Failed to parse referrer URL')
} }
} catch {
// If something happens to the URL parsing, we don't want to actually cause any problems for the user. Just
// log the error so we might catch it
console.error('Failed to parse referrer URL')
} }
resolve(null) }
}) return null
} }