initContentScript function
Last updated: 2026-03-05T10:53:28.853Z
Metrics
LOC: 105
Complexity: 8
Params: 0
Signature
initContentScript(): : Promise<void>
Source Code
async function initContentScript(): Promise<void> {
await initLogger();
const settings = await getSettings();
await initI18n(settings.uiLanguage ?? "auto");
// Configure the detection pipeline from user settings
if (settings.detectionPipeline?.length) {
setActiveClassifiers(
buildClassifiersFromSettings(settings.detectionPipeline),
);
}
// Init the per-field icon only if enabled
if (settings.showFieldIcon !== false) {
initFieldIcon(settings.fieldIconPosition ?? "inside");
}
// Load pre-trained model artefacts (generated by `npm run train:model`).
// Falls back silently to runtime keyword classifier if artefacts are absent.
loadPretrainedModel().catch(() => {});
// Auto-start watcher if enabled in settings
if (settings.watcherEnabled) {
startWatching(
(newFieldsCount) => {
if (newFieldsCount > 0) {
showNotification(
`🔄 ${newFieldsCount} novo(s) campo(s) detectado(s) — re-preenchendo...`,
);
}
},
settings.watcherAutoRefill,
{
autoRefill: settings.watcherAutoRefill,
debounceMs: settings.watcherDebounceMs,
shadowDOM: settings.watcherShadowDOM,
},
);
}
// Restore a recording session that was persisted before a traditional form submit
// (non-AJAX GET/POST) caused a full page navigation.
const restoredSession = tryRestoreRecordingSession();
if (restoredSession) {
// Notify the devtools panel about the restored session (with all steps captured
// before and during the form submit) so it can repopulate the action list.
chrome.runtime
.sendMessage({
type: "RECORDING_RESTORED",
payload: {
steps: restoredSession.steps.map((step) => ({
type: step.type,
selector: step.selector,
value: step.value,
url: step.url,
label: step.label,
assertion: step.assertion,
})),
},
})
.catch(() => {});
setOnStepAdded((step, index) => {
chrome.runtime
.sendMessage({
type: "RECORDING_STEP_ADDED",
payload: {
step: {
type: step.type,
selector: step.selector,
value: step.value,
url: step.url,
label: step.label,
assertion: step.assertion,
},
index,
},
})
.catch(() => {});
});
setOnStepUpdated((step, index) => {
chrome.runtime
.sendMessage({
type: "RECORDING_STEP_UPDATED",
payload: {
step: {
type: step.type,
selector: step.selector,
value: step.value,
url: step.url,
label: step.label,
assertion: step.assertion,
},
index,
},
})
.catch(() => {});
});
showNotification(
`🔴 Gravação retomada (${restoredSession.steps.length} passos)`,
);
}
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| showNotification | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | calls |