Skip to content

Commit ba64f4a

Browse files
committed
fix: auto-lift toggle button above reCAPTCHA badge
The floating star and reCAPTCHA v3 badge both default to the bottom-right corner. Pages that embed reCAPTCHA (Greenhouse, Workday, .gov forms, many ATS templates) end up with the two gadgets overlapping — visible but click-fighting each other. After createToggleButton, poll every 200 ms for up to 6 s looking for .grecaptcha-badge. If found, bump our button's bottom from 24 px to 90 px so it sits cleanly above the badge. Only applies when the user hasn't dragged the button yet (drag-saved positions in localStorage are honored verbatim). Also cleaned up the temporary diagnostic logs now that the host-hiding issue from #1 is confirmed fixed — kept the error-only path so init exceptions still surface, and kept the silent self-healing MutationObserver that re-appends the host if a SPA removes it.
1 parent 8c92db0 commit ba64f4a

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

content.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,6 @@
4040
if (window.__jobmatchAILoaded) return;
4141
window.__jobmatchAILoaded = true;
4242

43-
// Boot diagnostic — temporary, helps debug "no floating button" reports on
44-
// sites with strict CSP or aggressive layouts (e.g. some Greenhouse pages).
45-
// Remove once the root cause is identified.
46-
try {
47-
console.log('[JobMatch AI] boot:', {
48-
url: location.href.slice(0, 200),
49-
topFrame: window === window.top,
50-
bodyExists: !!document.body,
51-
readyState: document.readyState,
52-
});
53-
} catch (_) {}
5443

5544
// URL normalizer is loaded as a content script before us (see manifest.json).
5645
// Strips UTM/click-id noise so the analysis cache + applied-job dedupe work.
@@ -2002,6 +1991,25 @@
20021991
btn.style.top = 'auto';
20031992
}
20041993

1994+
// Auto-avoid reCAPTCHA badge. Both gadgets default to bottom-right;
1995+
// when a page (Greenhouse, Workday, government forms, etc.) embeds
1996+
// reCAPTCHA the badge overlaps our button. Watch for .grecaptcha-badge
1997+
// for ~5 s after init and lift our button above it. Only kicks in
1998+
// when the user has NOT dragged it themselves yet — drag-saved
1999+
// positions are honored verbatim.
2000+
if (!saved) {
2001+
let attempts = 0;
2002+
const RECAPTCHA_OFFSET_BOTTOM = 90; // reCAPTCHA badge is ~60 px tall + breathing room
2003+
const tick = setInterval(() => {
2004+
if (++attempts >= 30) { clearInterval(tick); return; } // give up after ~6 s
2005+
const badge = document.querySelector('.grecaptcha-badge');
2006+
if (badge) {
2007+
btn.style.bottom = RECAPTCHA_OFFSET_BOTTOM + 'px';
2008+
clearInterval(tick);
2009+
}
2010+
}, 200);
2011+
}
2012+
20052013
// ── Drag logic ──
20062014
let didDrag = false, startX, startY, startRight, startBottom;
20072015
const MIN_MARGIN = 8;
@@ -4731,23 +4739,20 @@
47314739
if (window === window.top) {
47324740
try {
47334741
createPanel();
4734-
console.log('[JobMatch AI] createPanel ok');
47354742
createToggleButton();
4736-
console.log('[JobMatch AI] createToggleButton ok; host in DOM=',
4737-
!!document.getElementById('jobmatch-ai-toggle-host'));
47384743
} catch (e) {
4744+
// Only surface errors — successful init stays silent. The thrown
4745+
// error gives us a console breadcrumb if the panel ever fails to
4746+
// appear on a page in the wild.
47394747
console.error('[JobMatch AI] init error:', e && (e.stack || e.message || e));
47404748
}
4741-
// Watch for the page removing our toggle host (some SPAs replace body)
4742-
// — common cause of "button vanishes after a moment" reports.
4749+
// Self-healing: if the page later removes our toggle host (some SPAs
4750+
// replace body during hydration / SPA route changes), re-append it.
47434751
try {
47444752
const host = document.getElementById('jobmatch-ai-toggle-host');
47454753
if (host && typeof MutationObserver === 'function') {
47464754
const obs = new MutationObserver(() => {
4747-
if (!host.isConnected) {
4748-
console.warn('[JobMatch AI] toggle host removed by page — re-appending');
4749-
document.body.appendChild(host);
4750-
}
4755+
if (!host.isConnected) document.body.appendChild(host);
47514756
});
47524757
obs.observe(document.body, { childList: true });
47534758
}

0 commit comments

Comments
 (0)