From 4bb8fcdd5fc54488901ed2e98580e5e0ef00dfea Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Mon, 13 May 2024 20:34:22 +0300 Subject: [PATCH 1/2] fix(clerk-js): Improve logging for CAPTCHA script loading errors (#3374) * fix(clerk-js): Improve logging for CAPTCHA script loading errors * fix(clerk-js): Remove the generic CAPTCHA console error (cherry picked from commit 34befeebc49d95b5492a2e665ad3b31919f2c1e3) --- .changeset/fast-timers-matter.md | 5 +++++ packages/clerk-js/src/utils/captcha.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .changeset/fast-timers-matter.md 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/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)[] = []; From ea1bea39a4d9b0ff07aabc7bd8109b6aa2ff7706 Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Fri, 10 May 2024 00:12:24 +0300 Subject: [PATCH 2/2] fix(clerk-js): Use first-party cookies when running on Cypress (#3245) * fix(clerk-js): Use first-party cookies when running on Cypress * fix(clerk-js): Create isCypress util (cherry picked from commit 7b213d5a426de16e854f5d3316a24579f698ba38) --- .changeset/rotten-rats-carry.md | 5 +++++ packages/clerk-js/src/utils/runtime.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/rotten-rats-carry.md 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/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() {