startWatching function exported
Last updated: 2026-03-04T23:21:38.393Z
Location
Metrics
LOC: 28
Complexity: 8
Params: 4
Signature
startWatching(
callback?: DomWatcherCallback,
autoRefill?: boolean,
config?: WatcherConfig,
): : void
Summary
Starts watching the DOM for form changes. When new fields are detected, calls the callback and optionally re-fills.
Source Code
export function startWatching(
callback?: DomWatcherCallback,
autoRefill?: boolean,
config?: WatcherConfig,
): void {
if (isWatching) return;
activeConfig = {
debounceMs: config?.debounceMs ?? DEFAULT_DEBOUNCE_MS,
autoRefill: config?.autoRefill ?? autoRefill ?? false,
shadowDOM: config?.shadowDOM ?? false,
};
onNewFieldsCallback = callback ?? null;
lastFieldSignature = getCurrentFieldSignature();
isWatching = true;
observer = new MutationObserver(handleMutations);
observer.observe(document.body, OBSERVE_OPTIONS);
if (activeConfig.shadowDOM) {
observeShadowRoots(document.body);
}
log.debug(
`DOM watcher started (debounce=${activeConfig.debounceMs}ms, autoRefill=${activeConfig.autoRefill}, shadowDOM=${activeConfig.shadowDOM})`,
);
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getCurrentFieldSignature | calls |
| observeShadowRoots | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | uses |