Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖

fix(capture): keep typed passwords out of the guide

Luis Ortizd774ddb5fd19
diff --git a/src/core/capture/dom/element-utils.ts b/src/core/capture/dom/element-utils.ts
index 4ddd846..dace91a 100644
--- a/src/core/capture/dom/element-utils.ts
+++ b/src/core/capture/dom/element-utils.ts
@@ -3,16 +3,32 @@ export const FOCUSABLE_SELECTOR =
const MAX_ELEMENT_RATIO = 0.8;
+function labelledControl(el: Element): HTMLElement | null {
+ const label = el.closest('label');
+ return label instanceof HTMLLabelElement && label.control instanceof HTMLElement ? label.control : null;
+}
+
+function shadowHost(el: Element): Element | null {
+ const root = el.getRootNode();
+ return root instanceof ShadowRoot && root.host instanceof Element ? root.host : null;
+}
+
export function findFocusableAncestor(el: Element): HTMLElement {
- let cursor: Element | null = el;
- while (cursor) {
- const match: Element | null = cursor.closest(FOCUSABLE_SELECTOR);
- if (match instanceof HTMLElement) return match;
- if (match) {
- cursor = match.parentElement;
- continue;
+ let scope: Element | null = el;
+ while (scope) {
+ let cursor: Element | null = scope;
+ while (cursor) {
+ const match: Element | null = cursor.closest(FOCUSABLE_SELECTOR);
+ if (match instanceof HTMLElement) return match;
+ if (match) {
+ cursor = match.parentElement;
+ continue;
+ }
+ break;
}
- break;
+ const control = labelledControl(scope);
+ if (control) return control;
+ scope = shadowHost(scope);
}
if (el instanceof HTMLElement) return el;
let parent: Element | null = el.parentElement;
@@ -45,12 +61,44 @@ export function isMimikElement(el: Element): boolean {
return !!el.closest('[data-mimik-ignore]');
}
+export function isSensitiveField(el: Element | null): boolean {
+ return el instanceof HTMLInputElement && el.type === 'password';
+}
+
+export function eventTarget(e: Event): Element | null {
+ const inner = e.composedPath?.()[0];
+ if (inner instanceof Element) return inner;
+ return e.target instanceof Element ? e.target : null;
+}
+
export function getFieldValue(el: HTMLElement): string {
+ if (isSensitiveField(el)) return '';
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) return el.value;
if (el.isContentEditable) return el.textContent?.trim() ?? '';
return '';
}
+function meaningfulLabel(text: string | null | undefined): string | null {
+ const trimmed = text?.trim();
+ if (!trimmed || !/[a-z0-9]/i.test(trimmed)) return null;
+ return (
+ trimmed
+ .split('\n')
+ .map((line) => line.trim())
+ .find((line) => /[a-z0-9]/i.test(line)) ?? null
+ );
+}
+
+function slottedLabel(el: Element): string | null {
+ const host = shadowHost(el);
+ if (!host) return null;
+ return (
+ meaningfulLabel(host.getAttribute('aria-label')) ??
+ meaningfulLabel(host.getAttribute('label')) ??
+ meaningfulLabel((host as HTMLElement).textContent)
+ );
+}
+
export function getFieldLabel(el: HTMLElement): string {
const ariaLabel = el.getAttribute('aria-label');
if (ariaLabel) return ariaLabel;
@@ -61,23 +109,26 @@ export function getFieldLabel(el: HTMLElement): string {
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
const labels = el.labels;
if (labels && labels.length > 0) {
- const labelText = labels[0].innerText?.trim();
+ const labelText = meaningfulLabel(labels[0].innerText);
if (labelText) return labelText;
}
}
+ const slotted = slottedLabel(el);
+ if (slotted) return slotted;
+
const id = el.getAttribute('id');
if (id) {
const label = document.querySelector(`label[for="${CSS.escape(id)}"]`);
if (label) {
- const labelText = (label as HTMLElement).innerText?.trim();
+ const labelText = meaningfulLabel((label as HTMLElement).innerText);
if (labelText) return labelText;
}
}
const parentLabel = el.closest('label');
if (parentLabel) {
- const labelText = parentLabel.innerText?.trim();
+ const labelText = meaningfulLabel(parentLabel.innerText);
if (labelText) return labelText;
}
diff --git a/src/core/capture/events/handlers.ts b/src/core/capture/events/handlers.ts
index 0f35040..c7bf2a9 100644
--- a/src/core/capture/events/handlers.ts
+++ b/src/core/capture/events/handlers.ts
@@ -7,9 +7,11 @@ import { sendMessage } from '@/lib/messaging';
import { extractDOMContext } from '../dom/context';
import { extractElementMeta, freezeRect } from '../dom/element-meta';
import {
+ eventTarget,
findFocusableAncestor,
isMimikElement,
isNavigatingClick,
+ isSensitiveField,
isTextField,
isTooLarge,
} from '../dom/element-utils';
@@ -136,7 +138,7 @@ class CaptureController {
}
private onMouseOver(e: Event) {
- const target = this.hoverTarget((e as MouseEvent).target);
+ const target = this.hoverTarget(eventTarget(e));
if (target === this.hovered) return;
this.hovered = target;
if (this.busy) return;
@@ -153,7 +155,7 @@ class CaptureController {
private onClick(e: Event) {
const me = e as MouseEvent;
- const raw = me.target;
+ const raw = eventTarget(me);
if (!raw || !(raw instanceof Element) || isReplayedClick(me) || me.shiftKey) return;
const target = findFocusableAncestor(raw);
if (isMimikElement(target)) return;
@@ -210,7 +212,7 @@ class CaptureController {
}
private onAuxClick(e: Event) {
- const raw = (e as MouseEvent).target;
+ const raw = eventTarget(e);
if (!raw || !(raw instanceof Element)) return;
const target = findFocusableAncestor(raw);
if (isMimikElement(target)) return;
@@ -219,7 +221,8 @@ class CaptureController {
private onKeydown(e: Event) {
const ke = e as KeyboardEvent;
- const target = ke.target instanceof HTMLElement ? ke.target : document.activeElement;
+ const resolved = eventTarget(ke);
+ const target = resolved instanceof HTMLElement ? resolved : document.activeElement;
if (!target || !(target instanceof HTMLElement) || isMimikElement(target)) return;
if (this.input.active && (ke.key === 'Enter' || ke.key === 'Escape')) {
@@ -227,12 +230,12 @@ class CaptureController {
return;
}
- if (isTextField(target)) return;
+ if (isSensitiveField(target) || isTextField(target)) return;
this.enqueue(this.capture(`keydown:${ke.key}`, target));
}
private onInput(e: Event) {
- const target = e.target;
+ const target = eventTarget(e);
if (!target || !(target instanceof HTMLElement)) return;
if (
!(
@@ -270,10 +273,8 @@ class CaptureController {
}
private onClipboard(e: Event) {
- const target =
- (e as ClipboardEvent).target instanceof HTMLElement
- ? ((e as ClipboardEvent).target as HTMLElement)
- : document.activeElement;
+ const resolved = eventTarget(e);
+ const target = resolved instanceof HTMLElement ? resolved : document.activeElement;
if (!target || !(target instanceof HTMLElement) || isMimikElement(target)) return;
this.enqueue(this.capture(e.type, target));
}
@@ -283,7 +284,7 @@ class CaptureController {
const pe = e as PointerEvent;
this.dragStartX = pe.pageX;
this.dragStartY = pe.pageY;
- this.dragStartElement = pe.target instanceof Element ? pe.target : null;
+ this.dragStartElement = eventTarget(pe);
}
private onPointerUp(e: Event) {
@@ -307,8 +308,9 @@ class CaptureController {
}
private onDragEnd(e: Event) {
- if (!e.target || !(e.target instanceof Element) || isMimikElement(e.target)) return;
- this.enqueue(this.capture('drag', findFocusableAncestor(e.target as Element)));
+ const target = eventTarget(e);
+ if (!target || isMimikElement(target)) return;
+ this.enqueue(this.capture('drag', findFocusableAncestor(target)));
}
stop() {
diff --git a/src/core/capture/events/input-session.ts b/src/core/capture/events/input-session.ts
index 54ee14b..81786f7 100644
--- a/src/core/capture/events/input-session.ts
+++ b/src/core/capture/events/input-session.ts
@@ -1,8 +1,9 @@
+import { i18n } from '#imports';
import { logger } from '@/lib/logger';
import { sendMessage } from '@/lib/messaging';
import { extractDOMContext } from '../dom/context';
import { extractElementMeta, type FrozenRect, freezeRect } from '../dom/element-meta';
-import { getFieldLabel, getFieldValue } from '../dom/element-utils';
+import { getFieldLabel, getFieldValue, isSensitiveField } from '../dom/element-utils';
export class InputSession {
stepId: string | null = null;
@@ -36,8 +37,15 @@ export class InputSession {
update(target: HTMLElement) {
if (!this.stepId) return;
this.atEvent = freezeRect(target);
+ const label = getFieldLabel(target);
+ if (isSensitiveField(target)) {
+ sendMessage('updateInputStep', { stepId: this.stepId, description: i18n.t('steps.typeSecret') }).catch((err) =>
+ logger.warn('Failed to update input step', err),
+ );
+ return;
+ }
const val = getFieldValue(target);
- const desc = val ? `Type "${val}" in ${getFieldLabel(target)}` : `Clear ${getFieldLabel(target)}`;
+ const desc = val ? `Type "${val}" in ${label}` : `Clear ${label}`;
sendMessage('updateInputStep', { stepId: this.stepId, description: desc, inputValue: val || undefined }).catch(
(err) => logger.warn('Failed to update input step', err),
);
diff --git a/src/core/guideme/content.ts b/src/core/guideme/content.ts
index 59e9dad..9b8a983 100644
--- a/src/core/guideme/content.ts
+++ b/src/core/guideme/content.ts
@@ -1,4 +1,5 @@
import { browser } from '#imports';
+import { isSensitiveField } from '@/core/capture/dom/element-utils';
import type { Step } from '@/core/guides/types';
import { logger } from '@/lib/logger';
import { sendMessage } from '@/lib/messaging';
@@ -108,6 +109,12 @@ export class GuideMeController {
private setupActionDetection(step: Step, target: HTMLElement) {
this.currentTarget = target;
+ if (step.action === 'input' && isSensitiveField(target)) {
+ this.clickHandler = () => this.advanceStep();
+ target.addEventListener('change', this.clickHandler, { once: true });
+ return;
+ }
+
if (step.action === 'input' && step.inputValue) {
if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
const proto =
diff --git a/src/locales/de.yml b/src/locales/de.yml
index c5468ee..f2796a4 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -387,6 +387,7 @@ steps:
click: "$1 anklicken"
typeIntoField: "In Feld $1 eingeben $2"
typeInto: "In $1 eingeben"
+ typeSecret: "Passwort eingeben"
copyFrom: "Aus $1 kopieren"
pasteInto: "In $1 einfügen"
cutFrom: "Aus $1 ausschneiden"
diff --git a/src/locales/en.yml b/src/locales/en.yml
index f785866..3ef91be 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -456,6 +456,7 @@ steps:
click: "Click $1"
typeIntoField: "Type into $1 field $2"
typeInto: "Type into $1"
+ typeSecret: "Type password"
copyFrom: "Copy from $1"
pasteInto: "Paste into $1"
cutFrom: "Cut from $1"
diff --git a/src/locales/es.yml b/src/locales/es.yml
index e3dfaa3..3b29ef0 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -456,6 +456,7 @@ steps:
click: "Clic en $1"
typeIntoField: "Escribir en el campo $1 $2"
typeInto: "Escribir en $1"
+ typeSecret: "Escribir contraseña"
copyFrom: "Copiar de $1"
pasteInto: "Pegar en $1"
cutFrom: "Cortar de $1"
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index 9606a5c..48c05d0 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -456,6 +456,7 @@ steps:
click: "Cliquer sur $1"
typeIntoField: "Saisir dans le champ $1 $2"
typeInto: "Saisir dans $1"
+ typeSecret: "Saisir le mot de passe"
copyFrom: "Copier depuis $1"
pasteInto: "Coller dans $1"
cutFrom: "Couper depuis $1"
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index 469287e..bd6250e 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -456,6 +456,7 @@ steps:
click: "Clicar em $1"
typeIntoField: "Digitar no campo $1 $2"
typeInto: "Digitar em $1"
+ typeSecret: "Digitar senha"
copyFrom: "Copiar de $1"
pasteInto: "Colar em $1"
cutFrom: "Recortar de $1"
diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml
index 81d3a04..61a7d10 100644
--- a/src/locales/zh-CN.yml
+++ b/src/locales/zh-CN.yml
@@ -456,6 +456,7 @@ steps:
click: "点击 $1"
typeIntoField: "在 $1 字段中输入 $2"
typeInto: "在 $1 中输入"
+ typeSecret: "输入密码"
copyFrom: "从 $1 复制"
pasteInto: "粘贴到 $1"
cutFrom: "从 $1 剪切"