diff --git a/.changeset/fast-timers-matter.md b/.changeset/fast-timers-matter.md new file mode 100644 index 00000000000..df1125bc1a9 --- /dev/null +++ b/.changeset/fast-timers-matter.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Improve logging for CAPTCHA script loading errors diff --git a/.changeset/rotten-rats-carry.md b/.changeset/rotten-rats-carry.md new file mode 100644 index 00000000000..3e15355ba88 --- /dev/null +++ b/.changeset/rotten-rats-carry.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-js': patch +--- + +Fix Cypress setting cookies as third-party diff --git a/packages/clerk-js/src/utils/captcha.ts b/packages/clerk-js/src/utils/captcha.ts index 370c2308754..252baf0c255 100644 --- a/packages/clerk-js/src/utils/captcha.ts +++ b/packages/clerk-js/src/utils/captcha.ts @@ -1,8 +1,6 @@ import { loadScript } from '@clerk/shared/loadScript'; import type { CaptchaWidgetType } from '@clerk/types'; -import { clerkFailedToLoadThirdPartyScript } from '../core/errors'; - interface RenderOptions { /** * Every widget has a sitekey. This sitekey is associated with the corresponding widget configuration and is created upon the widget creation. @@ -76,9 +74,12 @@ export async function loadCaptcha(url: string) { if (!window.turnstile) { try { await loadScript(url, { defer: true }); - } catch (_) { + } catch { // Rethrow with specific message - clerkFailedToLoadThirdPartyScript('Cloudflare Turnstile'); + console.error('Clerk: Failed to load the CAPTCHA script from the URL: ', url); + throw { + captchaError: 'captcha_script_failed_to_load', + }; } } return window.turnstile; @@ -112,7 +113,7 @@ export const getCaptchaToken = async (captchaOptions: { return div; }; - const captcha = await loadCaptcha(scriptUrl); + const captcha: Turnstile = await loadCaptcha(scriptUrl); let retries = 0; const errorCodes: (string | number)[] = []; diff --git a/packages/clerk-js/src/utils/runtime.ts b/packages/clerk-js/src/utils/runtime.ts index fbd7d7a8d5d..06a40433579 100644 --- a/packages/clerk-js/src/utils/runtime.ts +++ b/packages/clerk-js/src/utils/runtime.ts @@ -10,8 +10,14 @@ export function usesHttps() { return inBrowser() && window.location.protocol === 'https:'; } +function isCypress() { + return typeof window !== 'undefined' && typeof (window as any).Cypress !== 'undefined'; +} + export function inIframe() { - return inBrowser() && window.self !== window.top; + // checks if the current window is an iframe + // excludes the case where the current window runs in a Cypress test + return inBrowser() && window.self !== window.top && !isCypress(); } export function inCrossOriginIframe() {