Files

23 lines
623 B
JavaScript

// Runtime detection for browser-extension contexts.
//
// On ordinary web pages `window.chrome` exists but does not expose the identity
// API, so we feature-check the function we actually need rather than trusting
// the presence of a `chrome`/`browser` global.
export function getIdentityApi(api = globalThis.browser ?? globalThis.chrome) {
const identity = api?.identity;
if (
typeof identity?.launchWebAuthFlow === 'function' &&
typeof identity?.getRedirectURL === 'function'
) {
return identity;
}
return null;
}
export function canUseExtensionAuth() {
return Boolean(getIdentityApi());
}