From f312a568a23e3ce685c6a354236eec2ac4c6bf2e Mon Sep 17 00:00:00 2001 From: jamz-uk <222520099+jamz-uk@users.noreply.github.com> Date: Thu, 21 Aug 2025 02:01:52 +0100 Subject: [PATCH] fixing captcha on certain browsers fuck you firefox and brave --- Auto-Image.js | 59 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/Auto-Image.js b/Auto-Image.js index ccadc95..9196147 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -1009,32 +1009,45 @@ async executeTurnstile(sitekey, action = 'paint') { await this.loadTurnstile(); - - if (typeof window.turnstile?.execute === 'function') { - try { - const token = await window.turnstile.execute(sitekey, { action }); - if (token && token.length > 20) { - return token; - } - } catch (error) { - console.warn('Turnstile execute failed:', error); + try { + if (this._turnstileWidgetId && typeof window.turnstile?.execute === 'function') { + const token = await window.turnstile.execute(this._turnstileWidgetId, { action }); + if (token && token.length > 20) return token; } + } catch (err) { + console.warn('Turnstile execute re-use failed, will re-render widget:', err); } - // Fallback to DOM rendering - return await new Promise(resolve => { - const container = document.createElement('div'); - container.style.position = 'fixed'; - container.style.left = '-9999px'; - document.body.appendChild(container); - - window.turnstile.render(container, { - sitekey, - callback: token => { - document.body.removeChild(container); - resolve(token); - } - }); + return await new Promise((resolve, reject) => { + try { + const container = document.createElement('div'); + container.style.position = 'fixed'; + container.style.left = '-9999px'; + container.style.top = '0'; + container.setAttribute('aria-hidden', 'true'); + document.body.appendChild(container); + + const widgetId = window.turnstile.render(container, { + sitekey, + size: 'invisible', + action, + retry: 'auto', + callback: (token) => { + resolve(token); + }, + 'error-callback': (e) => { + console.warn('Turnstile error-callback:', e); + resolve(null); + }, + 'timeout-callback': () => { + console.warn('Turnstile timeout-callback'); + resolve(null); + } + }); + this._turnstileWidgetId = widgetId; + } catch (e) { + reject(e); + } }); },