fillSingleField function exported
Last updated: 2026-03-04T23:21:38.398Z
Location
Metrics
LOC: 52
Complexity: 10
Params: 2
Signature
fillSingleField(
field: FormField,
): : Promise<GenerationResult | null>
Summary
Fills a single form field using the same priority chain as {@link fillAllFields}.
Tags
#@param field - The detected form field to fill#@returns The generation result, or `null` on failure
Source Code
export async function fillSingleField(
field: FormField,
): Promise<GenerationResult | null> {
const url = window.location.href;
const ignoredFields = await getIgnoredFieldsForUrl(url);
const ignoredSelectors = new Set(ignoredFields.map((f) => f.selector));
if (ignoredSelectors.has(field.selector)) {
log.debug(`Campo ignorado — skip: ${field.selector}`);
return null;
}
const settings = await getSettings();
const aiGenerateFn = await getAiFunction(settings);
const fieldLabel =
field.label ?? field.name ?? field.id ?? field.fieldType ?? field.selector;
log.info(`⏳ Preenchendo [${field.fieldType}] "${fieldLabel}"...`);
const start = Date.now();
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,
);
}
return result;
} catch (error) {
log.warn(
`❌ Falhou em ${Date.now() - start}ms — campo ${field.selector}:`,
error,
);
return null;
}
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| getAiFunction | calls |
| applyValueToField | calls |
| highlightField | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | uses |
| DomWatcherCallback | uses |
| refillNewFields | calls |
| initFieldIcon | uses |
| handleIconClick | calls |
| makeInput | uses |