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
5 changes: 5 additions & 0 deletions .changeset/fast-timers-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Improve logging for CAPTCHA script loading errors
5 changes: 5 additions & 0 deletions .changeset/rotten-rats-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fix Cypress setting cookies as third-party
11 changes: 6 additions & 5 deletions packages/clerk-js/src/utils/captcha.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)[] = [];

Expand Down
8 changes: 7 additions & 1 deletion packages/clerk-js/src/utils/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down