Skip to content

fix(plugin-autocapture-browser): fix nearest label CSS coping - #1964

Open
daniel-graham-amplitude wants to merge 1 commit into
mainfrom
SDK-229-fix-nearest-label
Open

fix(plugin-autocapture-browser): fix nearest label CSS coping#1964
daniel-graham-amplitude wants to merge 1 commit into
mainfrom
SDK-229-fix-nearest-label

Conversation

@daniel-graham-amplitude

@daniel-graham-amplitude daniel-graham-amplitude commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Note

Low Risk
Small DOM-query change in autocapture label enrichment only; improves event property accuracy with no auth or data-pipeline impact.

Overview
getNearestLabel in the autocapture browser plugin now applies :scope> to each heading selector (h1h6), not only to span. Previously, headings in the compound selector could match any descendant of the current parent, so nested headings could be picked as [Amplitude] Element Parent Label when walking up the DOM.

A regression test covers a form input under a layout where a page-level h1 is not a direct child label of the input’s immediate ancestors, expecting an empty parent label.

Reviewed by Cursor Bugbot for commit fbff3f3. Bugbot is set up for automated code reviews on this repo. Configure here.

@daniel-graham-amplitude
daniel-graham-amplitude requested a review from a team as a code owner August 31, 2026 17:03
@linear-code

linear-code Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

SDK-229

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Regression test expects wrong label
    • Nested the page-title h1 under a header so the fixture exercises unscoped descendant matching instead of a sibling :scope>h1 hit.

Create PR

Or push these changes by commenting:

@cursor push a728934667
Preview (a728934667)
diff --git a/packages/plugin-autocapture-browser/test/data-extractor.test.ts b/packages/plugin-autocapture-browser/test/data-extractor.test.ts
--- a/packages/plugin-autocapture-browser/test/data-extractor.test.ts
+++ b/packages/plugin-autocapture-browser/test/data-extractor.test.ts
@@ -472,11 +472,13 @@
       // the parent. Walking up then picks the first ancestor that contains any
       // heading — e.g. a page title — instead of a sibling label.
       const container = document.createElement('div');
+      const header = document.createElement('header');
       const heading = document.createElement('h1');
       heading.innerText = 'My App';
       const form = document.createElement('form');
       const input = document.createElement('input');
-      container.appendChild(heading);
+      header.appendChild(heading);
+      container.appendChild(header);
       form.appendChild(input);
       container.appendChild(form);

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 7a19102. Configure here.

Comment thread packages/plugin-autocapture-browser/test/data-extractor.test.ts
@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 64.33 KB (+0.01% 🔺)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 135.32 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 218.75 KB (+0.01% 🔺)
@amplitude/element-selector (gzipped esm) 3.4 KB (0%)

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.

2 participants