From f53bd67d300c637497d95dbe8c13c74e1af2b1e4 Mon Sep 17 00:00:00 2001 From: martbost Date: Fri, 9 Oct 2026 08:44:27 -0500 Subject: [PATCH] Dwell timers no longer stall on phones: a focused ad frame or a touch device counts as an active tab (Brian Holland 2026-10-09: no timer, no close on the welcome tour and verified ads on mobile) Co-Authored-By: Claude Fable 5.1 --- public/assets/my.js | 6 ++++-- public/assets/view.js | 4 +++- public/my.html | 2 +- public/view.html | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/public/assets/my.js b/public/assets/my.js index fb96554..72b556d 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -3,6 +3,8 @@ (async function () { // back-office shell: no marketing nav here; rehearsal notice lives in the top bar const $ = IAP.$; + // dwell timers pause when the tab is away; a focused ad frame or a touch device counts as active (phones never report hasFocus reliably) + const tabActive = () => document.visibilityState === 'visible' && (document.hasFocus() || !!(document.activeElement && document.activeElement.tagName === 'IFRAME') || (window.matchMedia && window.matchMedia('(pointer: coarse)').matches)); try { const c = await IAP.getConfig(); if (c.rehearsal && $('boRehearsal')) { @@ -2281,7 +2283,7 @@ refresh(); // countdown pauses off-tab; the server separately enforces the dwell on its own clock ibTimer = setInterval(() => { - if (document.visibilityState !== 'visible' || !document.hasFocus()) return; + if (!tabActive()) return; left -= 1; if (left > 0) { refresh(); return; } clearInterval(ibTimer); @@ -2849,7 +2851,7 @@ $('ggTimer').textContent = left + 's'; await new Promise(done => { const t = setInterval(() => { - if (document.visibilityState !== 'visible' || !document.hasFocus()) return; + if (!tabActive()) return; left -= 1; $('ggTimer').textContent = Math.max(0, left) + 's'; if (left <= 0) { clearInterval(t); done(); } diff --git a/public/assets/view.js b/public/assets/view.js index a348861..f184140 100644 --- a/public/assets/view.js +++ b/public/assets/view.js @@ -7,6 +7,8 @@ const token = location.pathname.split('/').pop(); const framed = window.self !== window.top; // shown inside the dashboard's in-page ad overlay let left = 5, timer = null, credited = false, asking = false; + // 'active' = visible and (focused, or the ad frame itself holds focus, or a touch device where hasFocus() is unreliable) + const tabActive = () => document.visibilityState === 'visible' && (document.hasFocus() || !!(document.activeElement && document.activeElement.tagName === 'IFRAME') || (window.matchMedia && window.matchMedia('(pointer: coarse)').matches)); const setMsg = t => { $('vMsg').textContent = t; }; async function j(url, body) { const r = await fetch(url, body @@ -18,7 +20,7 @@ if (credited || asking) return; // In the in-page overlay the iframe often doesn't hold focus even though it's // fully on screen, so gate on tab visibility only when framed. - if (document.visibilityState !== 'visible' || (!framed && !document.hasFocus())) { + if (document.visibilityState !== 'visible' || (!framed && !tabActive())) { $('vTimer').classList.add('paused'); $('vTimer').textContent = 'paused'; setMsg(framed ? 'Keep this ad on screen to finish the countdown.' : 'Come back to this tab to keep the countdown moving.'); diff --git a/public/my.html b/public/my.html index e5cdc5d..8267bc5 100644 --- a/public/my.html +++ b/public/my.html @@ -1149,7 +1149,7 @@ - + diff --git a/public/view.html b/public/view.html index e1b0375..9af6543 100644 --- a/public/view.html +++ b/public/view.html @@ -46,6 +46,6 @@ - +