Skip to content

fix(extension): speed up floating button placement - #36

Merged
kunchenguid merged 4 commits into
mainfrom
fix/extension-button-hit-testing
Jun 1, 2026
Merged

kunchenguid merged 4 commits into
mainfrom
fix/extension-button-hit-testing

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

The developer wanted to fix severe lag in the Chrome extension on heavy sites like x.com by removing complex hitbox/collision logic they suspected was too expensive. They specifically asked to replace the sophisticated hitbox behavior with something dumb and simple, accepting a less precise overlap-avoidance tradeoff. The goal was to keep button placement lightweight, avoid expensive repeated hit-testing on hot events like typing and selection changes, and verify the change with tests.

What Changed

  • Replaced exhaustive overlap scanning for the injected button with a lightweight center-point hit test that checks candidate placements in order.
  • Skips injected Simple Words UI during hit-testing so refreshes can still detect page controls underneath the currently visible button.
  • Updated content-script coverage and placement documentation to match the simpler collision-avoidance behavior.

Risk Assessment

✅ Low: The change is narrowly scoped to replacing expensive button overlap scans with a center-point hit test and includes focused test coverage for the new behavior, with no material regressions found in the reviewed diff.

Testing

Focused content-script tests, rebuilt extension bundles, and the browser e2e fixture all passed; the Playwright run exercised the actual Chrome extension UI and captured screenshots plus placement measurements showing the Simple Words button avoids a real page button while accepting overlap with a broad tabindex container as the intended simpler tradeoff.

  • Evidence: Button avoids page button screenshot (local file: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KT29ZCR1PNQAN2D8EWS67H52/button-control-avoided.png)
  • Evidence: Tabindex container not avoided screenshot (local file: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KT29ZCR1PNQAN2D8EWS67H52/tabindex-container-not-avoided.png)
Evidence: Placement measurement evidence

buttonControlEvidence.overlapsAvoidTarget=false; tabindexEvidence.overlapsAvoidTarget=true

{
  "buttonControlEvidence": {
    "editor": {
      "top": 161,
      "left": 80,
      "right": 280,
      "bottom": 261,
      "width": 200,
      "height": 100
    },
    "avoidTarget": {
      "top": 221,
      "left": 240,
      "right": 290,
      "bottom": 271,
      "width": 50,
      "height": 50
    },
    "simpleWordsButton": {
      "top": 169,
      "left": 248,
      "right": 272,
      "bottom": 193,
      "width": 24,
      "height": 24
    },
    "overlapsAvoidTarget": false
  },
  "tabindexEvidence": {
    "editor": {
      "top": 161,
      "left": 80,
      "right": 280,
      "bottom": 261,
      "width": 200,
      "height": 100
    },
    "avoidTarget": {
      "top": 221,
      "left": 240,
      "right": 290,
      "bottom": 271,
      "width": 50,
      "height": 50
    },
    "simpleWordsButton": {
      "top": 229,
      "left": 248,
      "right": 272,
      "bottom": 253,
      "width": 24,
      "height": 24
    },
    "overlapsAvoidTarget": true
  }
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 src/content.ts:601 - elementFromPoint only sees the topmost element, and the Simple Words button is made visible before positionButton runs. On later input/scroll/selection refreshes, a candidate that overlaps the current button will hit-test the injected button itself, return false via isInjectedUITarget, and never inspect the page control underneath. This lets newly appeared or shifted page buttons remain covered; use a single-point elementsFromPoint scan that skips injected UI, or temporarily disable/hide the injected button while hit-testing.

🔧 Fix: Skip injected UI in hit-testing
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • npx vitest run test/content.test.ts
  • npm run build:background && npm run build:pages
  • npx playwright test e2e/button-overlap.spec.ts
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid
kunchenguid merged commit 909ebdd into main Jun 1, 2026
1 check passed
@kunchenguid
kunchenguid deleted the fix/extension-button-hit-testing branch June 1, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant