@@ -48,6 +48,38 @@ function sanitizeInput(input) {
4848 return input . trim ( ) . replace ( / [ < > ] / g, '' ) ;
4949}
5050
51+ // Detect ad blockers (AdGuard, uBlock, etc.)
52+ function detectAdBlocker ( ) {
53+ // Check for common ad blocker indicators
54+ if ( typeof window . adguard !== 'undefined' ) {
55+ return true ;
56+ }
57+
58+ // Check if AdGuard is blocking
59+ if ( document . querySelector ( '[data-adguard]' ) ) {
60+ return true ;
61+ }
62+
63+ // Check for generic ad blocker detection
64+ try {
65+ const testAd = document . createElement ( 'div' ) ;
66+ testAd . innerHTML = ' ' ;
67+ testAd . className = 'adsbox ad-placement ad-placeholder adbadge BannerAd' ;
68+ testAd . style . position = 'absolute' ;
69+ testAd . style . left = '-999px' ;
70+ document . body . appendChild ( testAd ) ;
71+
72+ const isBlocked = testAd . offsetHeight === 0 ||
73+ window . getComputedStyle ( testAd ) . display === 'none' ||
74+ window . getComputedStyle ( testAd ) . visibility === 'hidden' ;
75+
76+ document . body . removeChild ( testAd ) ;
77+ return isBlocked ;
78+ } catch ( e ) {
79+ return false ;
80+ }
81+ }
82+
5183// Main Initialization
5284async function initializeApp ( ) {
5385 try {
@@ -179,8 +211,22 @@ async function initializePuter() {
179211 updatePuterUI ( true ) ;
180212 showToast ( 'Sesión iniciada en Puter exitosamente' , 'success' ) ;
181213 } catch ( error ) {
182- console . error ( '❌ Puter login error:' , error ) ;
183- showToast ( 'Error al iniciar sesión en Puter' , 'error' ) ;
214+ // Handle specific error cases
215+ if ( error ?. error === 'auth_window_closed' ) {
216+ console . log ( 'ℹ️ Puter auth window closed by user' ) ;
217+ // Always warn about ad blockers when login is cancelled
218+ showToast ( 'Inicio de sesión cancelado. Verifica que no tengas bloqueadores como AdGuard activos' , 'warning' , 10000 ) ;
219+ } else {
220+ console . error ( '❌ Puter login error:' , error ) ;
221+
222+ // Check for ad blockers on other errors
223+ const hasAdBlocker = detectAdBlocker ( ) ;
224+ if ( hasAdBlocker ) {
225+ showToast ( 'Error al iniciar sesión. Intenta desactivar AdGuard o bloqueadores de anuncios' , 'error' , 6000 ) ;
226+ } else {
227+ showToast ( 'Error al iniciar sesión en Puter' , 'error' ) ;
228+ }
229+ }
184230 }
185231 } ) ;
186232
0 commit comments