Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions apps/x/apps/main/src/browser/page-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ const getElementType = (element) => {
return null;
};

const isTextEntryElement = (element) => (
element instanceof HTMLInputElement
|| element instanceof HTMLTextAreaElement
|| (element instanceof HTMLElement && element.isContentEditable)
);

const shouldRedactVerificationValue = (element) => (
element instanceof HTMLInputElement
? !['checkbox', 'radio', 'range', 'button', 'submit', 'reset'].includes((element.type || '').toLowerCase())
: element instanceof HTMLTextAreaElement
|| (element instanceof HTMLElement && element.isContentEditable)
);

const getElementLabel = (element) => {
const ariaLabel = truncateText(element.getAttribute('aria-label') ?? '', 120);
if (ariaLabel) return ariaLabel;
Expand All @@ -121,10 +134,12 @@ const getElementLabel = (element) => {
const placeholder = truncateText(element.getAttribute('placeholder') ?? '', 120);
if (placeholder) return placeholder;

if (isTextEntryElement(element)) {
return null;
}

const text = truncateText(
element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement
? element.value
: element.textContent ?? '',
element.textContent ?? '',
120,
);
return text || null;
Expand Down Expand Up @@ -187,7 +202,9 @@ const getVerificationTargetState = (element) => {
? element.checked
: null,
value:
element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement
shouldRedactVerificationValue(element)
? null
: element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement
? truncateText(element.value ?? '', 200)
: element instanceof HTMLSelectElement
? truncateText(element.value ?? '', 200)
Expand Down