detectAllFieldsAsync function exported β 100.0%
Last updated: 2026-03-04T23:21:38.397Z
Location
Metrics
LOC: 80
Complexity: 18
Params: 0
Coverage: 100.0% (35/35 lines, 0x executed)
Signature
detectAllFieldsAsync(): : Promise<DetectionResult>
Summary
Async detection β runs the full DEFAULT_COLLECTION_PIPELINE and adds per-detector summary logging.
Architecture violations
- [warning] max-cyclomatic-complexity: 'detectAllFieldsAsync' has cyclomatic complexity 18 (max 10)
Source Code
export async function detectAllFieldsAsync(): Promise<DetectionResult> {
const url = window.location.href;
const t0 = performance.now();
log.groupCollapsed(`π DetecΓ§Γ£o iniciada β ${new URL(url).hostname}`);
log.debug(`π URL: ${url}`);
// Use the async pipeline so the Chrome AI classifier (detectAsync) is active
// for native inputs. Custom selects also run the full async pipeline so TF.js
// and Chrome AI can classify fields the adapter left as "unknown".
const nativeFields = await detectNativeFieldsAsync();
const customFields = await classifyCustomFieldsAsync(
detectCustomComponents(),
);
const fields = deduplicateFields(nativeFields, customFields);
const byMethod: Record<DetectionMethod, number> = {
"html-type": 0,
keyword: 0,
tensorflow: 0,
"chrome-ai": 0,
"html-fallback": 0,
"custom-select": 0,
interactive: 0,
"user-override": 0,
};
fields.forEach((field, idx) => {
log.debug(`π Campo #${idx + 1} detectado:`, field);
const method = field.detectionMethod ?? "html-fallback";
byMethod[method as DetectionMethod]++;
const tag = field.element.tagName.toLowerCase();
const htmlType =
field.element instanceof HTMLInputElement ? field.element.type : "β";
log.groupCollapsed(
`#${idx + 1} <${tag} type="${htmlType}"> β id="${field.id ?? ""}" name="${field.name ?? ""}"`,
);
log.debug(field);
log.debug(`π Label: "${field.label ?? "(nenhum)"}"`);
log.debug(`π‘ Sinais: "${field.contextSignals || "(nenhum)"}"`);
const fieldMs = field.detectionDurationMs ?? 0;
const fieldMsStr =
fieldMs >= 1
? `${fieldMs.toFixed(1)}ms`
: `${(fieldMs * 1000).toFixed(0)}Β΅s`;
log.debug(
`β
Tipo final: "${field.fieldType}" [${method} | ${((field.detectionConfidence ?? 0) * 100).toFixed(0)}%] β‘ ${fieldMsStr}`,
);
log.groupEnd();
});
const summary = (Object.entries(byMethod) as [DetectionMethod, number][])
.filter(([, n]) => n > 0)
.map(([m, n]) => `${m}: ${n}`)
.join(" Β· ");
log.info(`β
${fields.length} campo(s) Β· ${summary}`);
// ββ Performance summary ββββββββββββββββββββββββββββββββββββββββββββββββββββ
const totalMs = performance.now() - t0;
const perfSorted = [...fields]
.filter((f) => (f.detectionDurationMs ?? 0) > 0)
.sort(
(a, b) => (b.detectionDurationMs ?? 0) - (a.detectionDurationMs ?? 0),
);
const slowTop = perfSorted.slice(0, 3).map((f) => {
const fIdx = fields.indexOf(f) + 1;
const ms = (f.detectionDurationMs ?? 0).toFixed(1);
const label = f.label ?? f.id ?? f.name ?? "?";
return `#${fIdx} "${label}" ${ms}ms [${f.detectionMethod}]`;
});
log.debug(
`β± ${totalMs.toFixed(0)}ms total${slowTop.length ? ` Β· π’ ${slowTop.join(" Β· ")}` : ""}`,
);
log.groupEnd();
return { fields };
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| detectNativeFieldsAsync | calls |
| classifyCustomFieldsAsync | calls |
| detectCustomComponents | calls |
| deduplicateFields | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | uses |
| DomWatcherCallback | uses |
| refillNewFields | calls |
| setNativeValue | uses |
| fillContextualAI | calls |
| captureFormValues | calls |
| applyTemplate | calls |
| makeField | uses |