Skip to content

feat(tech-detect): detect Microsoft Clarity from its loader in a first-party bundle #1488 - #1489

Closed
nc9 wants to merge 1 commit into
mainfrom
feat/clarity-inbundle-1488
Closed

nc9 wants to merge 1 commit into
mainfrom
feat/clarity-inbundle-1488

Conversation

@nc9

@nc9 nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1488.

Microsoft Clarity had no bundle detector. The standard loader, t.src="https://www.clarity.ms/tag/"+i, bundled into a first-party script was found before v0.0.150 only by accident (a whole-text read of the page), and a few real installs lost Clarity when #1430 removed that read.

  • A new inBundle detector on the clarity fingerprint: .src = or setAttribute("src", ...) followed by a string, template literal or quote of https://[www.]clarity.ms/tag/. The assignment is code and the URL after it is a string, so the match starts in code (the inCode rule) while a docs string, a comment or prose that only names the URL does not match. The hint clarity.ms/tag/ is declared, so a capped scan sends the window around it.
  • Tests (clarity-inbundle-1488.test.ts, 5; 4 fail without the detector): the standard snippet inside a bundled module, the setAttribute and template-literal forms with and without www and with http:, deep in a 30,000-line bundle; negatives: the URL in a docs string, a comment, a help string, an object value, another host's .src, a look-alike host (clarity.ms.evil.invalid) and the library URL clarity.js; and 8 MB of near-miss assignments, with and without the real one at the end, under the time budget. bundle-content-1254, fingerprints, pattern-bounds, extras-budget and script-url-inline-1430 pass; tsgo is clean.
  • Docs sentence in docs/cloud/technologies.mdx, CHANGELOG under Unreleased / Added. Synthetic text only.

Review round 1: a sampler test (a bundle over 400 KB with the loader mid-file: the hint clarity.ms/tag/ is declared, sampleBundleExtras sends the window, the head plus windows detect it and the head alone does not; removing the hint fails it); negatives that put the whole assignment inside a string (var d='t.src="https://www.clarity.ms/tag/"+i';) so the in-code rejection is pinned, not only the \" case; protocol-relative //www.clarity.ms/tag/ is accepted (same host and path, anchored by the .src = code) and setAttribute ( with a space; the Firebase comma in the docs. Known limits, pinned as negative tests and listed in the docs: the URL split by concatenation or held in a variable, { src: ... } or JSX, s["src"] = ..., and loader code inside ${}. Rebased onto main.

The double-escaped flight chunk (#1487) is a separate shape, not touched here.

Skill: no change needed.

nik

…t in a first-party bundle #1488

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the feat/clarity-inbundle-1488 branch from baf3815 to 777d916 Compare November 1, 2026 09:36
@nc9 nc9 mentioned this pull request Nov 1, 2026
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.156 as 8e5ef92f via #1506.

nik

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.

tech-detect: add a Clarity bundle detector for clarity.ms/tag/ in first-party bundles

1 participant