-
Notifications
You must be signed in to change notification settings - Fork 281
Update client layout instrumentation #1128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shawj0
wants to merge
5
commits into
microsoft:master
Choose a base branch
from
shawj0:shawjames/client-signal-0870
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,6 @@ | |
| "packages": [ | ||
| "packages/*" | ||
| ], | ||
| "version": "0.8.69", | ||
| "version": "0.8.70", | ||
| "npmClient": "yarn" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| let version = "0.8.69"; | ||
| let version = "0.8.70"; | ||
| export default version; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { AgenticBrowserSignal, Constant as DataConstant } from "@clarity-types/data"; | ||
| import { Constant } from "@clarity-types/layout"; | ||
| import { set } from "@src/data/variable"; | ||
|
|
||
| let seen: boolean[] = []; | ||
|
|
||
| export function start(): void { | ||
| seen = []; | ||
| } | ||
|
|
||
| export function detect(attributes: { [key: string]: string }): void { | ||
| let signal = identify(attributes[Constant.Id]); | ||
| if (signal && !seen[signal]) { | ||
| seen[signal] = true; | ||
| set(DataConstant.AgenticBrowserSignal, signal.toString()); | ||
| } | ||
| } | ||
|
|
||
| function identify(id: string): AgenticBrowserSignal { | ||
| switch (id) { | ||
| case "claude-agent-glow-border": | ||
| return AgenticBrowserSignal.ClaudeAgentGlowBorder; | ||
| case "claude-agent-glow-border-inner": | ||
| return AgenticBrowserSignal.ClaudeAgentGlowBorderInner; | ||
| case "claude-agent-stop-container": | ||
| return AgenticBrowserSignal.ClaudeAgentStopContainer; | ||
| case "claude-agent-stop-button": | ||
| return AgenticBrowserSignal.ClaudeAgentStopButton; | ||
| case "claude-phantom-cursor": | ||
| return AgenticBrowserSignal.ClaudePhantomCursor; | ||
| default: | ||
| return AgenticBrowserSignal.None; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
| import { decode } from "clarity-decode"; | ||
| import { readFileSync } from "fs"; | ||
| import { resolve } from "path"; | ||
| import { pathToFileURL } from "url"; | ||
| import type { Page } from "@playwright/test"; | ||
| import type { Data } from "clarity-decode"; | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| clarity: (method: string, ...args: any[]) => void; | ||
| payloads: string[]; | ||
| } | ||
| } | ||
|
|
||
| const Variable = "<!>ABS"; | ||
| const Signals = { | ||
| ClaudeAgentGlowBorder: "1", | ||
| ClaudeAgentGlowBorderInner: "2", | ||
| ClaudeAgentStopContainer: "3", | ||
| ClaudeAgentStopButton: "4", | ||
| ClaudePhantomCursor: "5", | ||
| } as const; | ||
|
|
||
| async function start(page: Page, markup: string = ""): Promise<void> { | ||
| const htmlPath = resolve(__dirname, "./html/core.html"); | ||
| const htmlFileUrl = pathToFileURL(htmlPath).toString(); | ||
| const html = readFileSync(htmlPath, "utf8"); | ||
| const clarity = readFileSync(resolve(__dirname, "../packages/clarity-js/build/clarity.min.js"), "utf8"); | ||
| await page.goto(htmlFileUrl); | ||
| await page.setContent(html.replace("</body>", `${markup} | ||
| <script> | ||
| window.payloads = []; | ||
| ${clarity}; | ||
| clarity("start", { | ||
| delay: 50, | ||
| projectId: "test", | ||
| upload: (payload) => { window.payloads.push(payload); } | ||
| }); | ||
| </script> | ||
| </body> | ||
| `)); | ||
| } | ||
|
|
||
| async function collect(page: Page): Promise<string[]> { | ||
| await page.waitForTimeout(300); | ||
| await page.evaluate((): void => window.clarity("stop")); | ||
| await page.waitForFunction("window.payloads.length > 0"); | ||
| const payloads = await page.evaluate((): string[] => window.payloads); | ||
| const signals: string[] = []; | ||
| for (const payload of payloads.map((value: string): Data.DecodedPayload => decode(value))) { | ||
| for (const event of payload.variable || []) { | ||
| if (event.data && event.data[Variable]) { | ||
| signals.push(...event.data[Variable]); | ||
| } | ||
| } | ||
| } | ||
| return signals; | ||
| } | ||
|
|
||
| test.describe("Agentic browser markers", (): void => { | ||
| test("captures the Claude marker family", async ({ page }): Promise<void> => { | ||
| await start(page, ` | ||
| <div id="claude-agent-glow-border"></div> | ||
| <div id="claude-agent-glow-border-inner"></div> | ||
| <div id="claude-agent-stop-container"></div> | ||
| <button id="claude-agent-stop-button"></button> | ||
| <div id="claude-phantom-cursor"></div> | ||
| `); | ||
|
|
||
| expect((await collect(page)).sort()).toEqual(Object.values(Signals).sort()); | ||
| }); | ||
|
|
||
| test("captures a marker inserted after load", async ({ page }): Promise<void> => { | ||
| await start(page); | ||
| await page.evaluate((): void => { | ||
| const marker = document.createElement("div"); | ||
| marker.id = "claude-agent-glow-border"; | ||
| document.body.appendChild(marker); | ||
| }); | ||
|
|
||
| expect(await collect(page)).toEqual([Signals.ClaudeAgentGlowBorder]); | ||
| }); | ||
|
|
||
| test("captures an id assigned after insertion", async ({ page }): Promise<void> => { | ||
| await start(page); | ||
| await page.evaluate((): void => { | ||
| const marker = document.createElement("div"); | ||
| marker.id = "pending-marker"; | ||
| document.body.appendChild(marker); | ||
| }); | ||
| await page.waitForTimeout(150); | ||
| await page.evaluate((): void => { | ||
| document.getElementById("pending-marker").id = "claude-agent-stop-container"; | ||
| }); | ||
|
|
||
| expect(await collect(page)).toEqual([Signals.ClaudeAgentStopContainer]); | ||
| }); | ||
|
|
||
| test("retains a transient marker removed before upload", async ({ page }): Promise<void> => { | ||
| await start(page); | ||
| await page.evaluate((): void => { | ||
| const marker = document.createElement("button"); | ||
| marker.id = "claude-agent-stop-button"; | ||
| document.body.appendChild(marker); | ||
| marker.remove(); | ||
| }); | ||
|
|
||
| expect(await collect(page)).toEqual([Signals.ClaudeAgentStopButton]); | ||
| }); | ||
|
|
||
| test("emits each marker once per page", async ({ page }): Promise<void> => { | ||
| await start(page); | ||
| await page.evaluate((): void => { | ||
| for (let i = 0; i < 2; i++) { | ||
| const marker = document.createElement("div"); | ||
| marker.id = "claude-phantom-cursor"; | ||
| document.body.appendChild(marker); | ||
| } | ||
| }); | ||
|
|
||
| expect(await collect(page)).toEqual([Signals.ClaudePhantomCursor]); | ||
| }); | ||
|
|
||
| test("captures a marker in an open shadow root", async ({ page }): Promise<void> => { | ||
| await start(page); | ||
| await page.evaluate((): void => { | ||
| const host = document.createElement("div"); | ||
| document.body.appendChild(host); | ||
| const marker = document.createElement("div"); | ||
| marker.id = "claude-phantom-cursor"; | ||
| host.attachShadow({ mode: "open" }).appendChild(marker); | ||
| }); | ||
|
|
||
| expect(await collect(page)).toEqual([Signals.ClaudePhantomCursor]); | ||
| }); | ||
|
|
||
| test("captures a marker in a same-origin iframe", async ({ page }): Promise<void> => { | ||
| await start(page); | ||
| await page.evaluate((): void => { | ||
| const frame = document.createElement("iframe"); | ||
| frame.srcdoc = "<div id='claude-agent-stop-button'></div>"; | ||
| document.body.appendChild(frame); | ||
| }); | ||
|
|
||
| expect(await collect(page)).toEqual([Signals.ClaudeAgentStopButton]); | ||
| }); | ||
|
|
||
| test("does not emit a variable for similar ids", async ({ page }): Promise<void> => { | ||
| await start(page, `<div id="claude-agent-stop-container-copy"></div>`); | ||
|
|
||
| expect(await collect(page)).toEqual([]); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This callback runs inside an injected HTML
<script>as plain JavaScript, so a TypeScript annotation would be invalid here. This matches existing test patterns; no change needed.