doFillAllFields function
Last updated: 2026-03-04T23:21:38.398Z
Location
Metrics
LOC: 108
Complexity: 18
Params: 1
Signature
doFillAllFields(options?: {
fillEmptyOnly?: boolean;
}): : Promise<GenerationResult[]>
Architecture violations
- [warning] max-cyclomatic-complexity: 'doFillAllFields' has cyclomatic complexity 18 (max 10)
- [warning] max-lines: 'doFillAllFields' has 108 lines (max 80)
Source Code
async function doFillAllFields(options?: {
fillEmptyOnly?: boolean;
}): Promise<GenerationResult[]> {
const url = window.location.href;
const settings = await getSettings();
const fillEmptyOnly = options?.fillEmptyOnly ?? settings.fillEmptyOnly;
const results: GenerationResult[] = [];
// Determine AI function based on settings
const aiGenerateFn = await getAiFunction(settings);
// Load ignored fields for current URL
const ignoredFields = await getIgnoredFieldsForUrl(url);
const ignoredSelectors = new Set(ignoredFields.map((f) => f.selector));
// Create progress notification
const progress = createProgressNotification();
progress.show();
let totalFields = 0;
// Stream detection + fill progressively (field by field)
for await (const field of streamAllFields()) {
totalFields++;
// Show detecting state
progress.addDetecting(field);
// Detection already done by the stream — update badge
progress.updateDetected(field);
// Skip ignored fields
if (ignoredSelectors.has(field.selector)) continue;
// Skip fields that already have a value when fillEmptyOnly is enabled
if (fillEmptyOnly && fieldHasValue(field)) continue;
const fieldLabel =
field.label ??
field.name ??
field.id ??
field.fieldType ??
field.selector;
log.info(`⏳ Preenchendo [${field.fieldType}] "${fieldLabel}"...`);
const start = Date.now();
// Show filling state
progress.addFilling(field);
try {
const result = await resolveFieldValue(
field,
url,
aiGenerateFn,
settings.forceAIFirst,
settings.aiTimeoutMs,
);
await applyValueToField(field, result.value);
logAuditFill({
selector: field.selector,
fieldType: field.fieldType,
source: result.source,
value: String(result.value),
});
log.info(
`✅ Preenchido em ${Date.now() - start}ms via ${result.source}: "${String(result.value).slice(0, 40)}"`,
);
if (settings.highlightFilled) {
highlightField(
field.element,
field.label ?? field.fieldType ?? undefined,
);
}
if (settings.showAiBadge && result.source === "ai") {
showAiFieldBadge(field.element);
}
// Update progress — filled
progress.updateFilled(field, result);
results.push(result);
} catch (error) {
log.warn(
`❌ Falhou em ${Date.now() - start}ms — campo ${field.selector}:`,
error,
);
progress.updateError(
field,
error instanceof Error ? error.message : "falhou",
);
}
}
// Show summary
progress.done(results.length, totalFields);
const aiFilledCount = results.filter((r) => r.source === "ai").length;
if (settings.showFillToast !== false) {
showFillToast(results.length, totalFields, aiFilledCount);
}
return results;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getAiFunction | calls |
| createProgressNotification | calls |
| fieldHasValue | calls |
| applyValueToField | calls |
| highlightField | calls |
| showAiFieldBadge | calls |
| showFillToast | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| fillAllFields | calls |