startWatching function exported

Last updated: 2026-03-04T23:21:38.393Z

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)

graph LR startWatching["startWatching"] getCurrentFieldSignature["getCurrentFieldSignature"] observeShadowRoots["observeShadowRoots"] startWatching -->|calls| getCurrentFieldSignature startWatching -->|calls| observeShadowRoots style startWatching fill:#dbeafe,stroke:#2563eb,stroke-width:2px click startWatching "f5ff88d04d3dd953.html" click getCurrentFieldSignature "e72508d8f19c287a.html" click observeShadowRoots "9252c52a7fc52fba.html"

Impact (Incoming)

graph LR startWatching["startWatching"] FillableElement["FillableElement"] FillableElement -->|uses| startWatching style startWatching fill:#dbeafe,stroke:#2563eb,stroke-width:2px click startWatching "f5ff88d04d3dd953.html" click FillableElement "2ecf5aaac3f668a8.html"
SourceType
FillableElement uses