blocks and
elements, which
+// `textContent` joins without a separator, so a recorded value would read
+// "AlphaBeta" for two lines. Read the value exactly the way `bsk fill` verifies
+// it (`FILL_VALUE_FUNCTION` in `tools/interaction.ts`): typed layouts are read
+// literally, other rich structures keep their rendered text.
+function editorValue(el: HTMLElement): string {
+ const collapses = ["normal", "nowrap"].includes(getComputedStyle(el).whiteSpace);
+ const isInline = (node: Node) => node.nodeType === Node.TEXT_NODE || node.nodeName === "BR";
+ const isLine = (node: Node) =>
+ node.nodeName === "DIV" &&
+ getComputedStyle(node as Element).display === "block" &&
+ [...node.childNodes].every(isInline);
+ const nodes = [...el.childNodes];
+ let value: string;
+ if (nodes.every((node) => isInline(node) || isLine(node))) {
+ const lines: Node[][] = [];
+ let open: Node[] | undefined;
+ for (const node of nodes) {
+ if (isLine(node)) {
+ lines.push([...node.childNodes]);
+ open = undefined;
+ } else {
+ if (!open) lines.push((open = []));
+ open.push(node);
+ }
+ }
+ value = lines
+ .flatMap((line) => {
+ let text = line
+ .map((node, index) => {
+ if (node.nodeName !== "BR") return (node as CharacterData).data;
+ return index < line.length - 1 ? "\n" : "";
+ })
+ .join("");
+ if (collapses) text = text.replace(/^[ \t\r\n]+|[ \t\r\n]+$/g, "");
+ // Without a
, an empty line has no height.
+ return text === "" && !line.some((node) => node.nodeName === "BR") ? [] : [text];
+ })
+ .join("\n");
+ } else {
+ // An editor holding only an empty line, such as
, is empty.
+ const rendered = el.innerText;
+ value = rendered === "\n" && el.textContent === "" ? "" : rendered;
+ }
+ return collapses ? value.replace(/\u00a0/g, " ") : value;
+}
+
function fillableValue(el: FillableElement): string {
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
return el.value;
}
- return el.textContent ?? "";
+ return editorValue(el);
}
function hoverTriggerAttrs(el: Element): Record
{
From 9af0e55a405bb3ca12bd869b9fe1438b92143945 Mon Sep 17 00:00:00 2001
From: shunxinyi-ljs <3515462408@qq.com>
Date: Fri, 13 Nov 2026 12:58:00 +0800
Subject: [PATCH 2/3] test(record): cover the non-breaking space Chrome types
at line edges
---
.../__tests__/record-editor-value.browser.test.ts | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts b/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts
index 01d75f329..9b9d5a77d 100644
--- a/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts
+++ b/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts
@@ -196,4 +196,16 @@ describe.skipIf(!process.env.BSK_CLICK_CHROME)("record contenteditable values",
expect(result.inner).toBe("One\n\nTwo!");
expect(finalValue(result.steps)).toBe(result.inner);
});
+
+ it("keeps a typed edge space as a space instead of the non-breaking space Chrome types", async () => {
+ const result = await recordEditor(editor, async (h) => {
+ await h.click("#editor");
+ await h.insert(" Alpha ");
+ });
+
+ // Chrome types a space at a line edge as U+00A0; the trace must not carry it.
+ expect(result.html).toContain(" ");
+ expect(finalValue(result.steps)).toBe(" Alpha ");
+ expect([...finalValue(result.steps)!].some((char) => char.codePointAt(0) === 0xa0)).toBe(false);
+ });
});
From e5a6d63bc7b74b64a2d23b9573d312f51cf54242 Mon Sep 17 00:00:00 2001
From: shunxinyi-ljs <3515462408@qq.com>
Date: Fri, 13 Nov 2026 18:14:58 +0800
Subject: [PATCH 3/3] test(record): type the CDP insert helper as Promise
The helper returned Input.insertText's reply, which does not match the
Promise the edit callback declares; tsc rejects it in CI.
---
.../src/content/__tests__/record-editor-value.browser.test.ts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts b/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts
index 9b9d5a77d..f60e63b96 100644
--- a/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts
+++ b/apps/extension/src/content/__tests__/record-editor-value.browser.test.ts
@@ -94,7 +94,9 @@ async function recordEditor(
);
}
};
- const insert = (text: string) => send("Input.insertText", { text }, sessionId);
+ const insert = async (text: string) => {
+ await send("Input.insertText", { text }, sessionId);
+ };
const enter = async (shift = false) => {
const key = {
key: "Enter",