sendStepToContentScript function
Last updated: 2026-03-05T10:53:28.864Z
Metrics
LOC: 42
Complexity: 8
Params: 3
Signature
sendStepToContentScript(
step: FlowStep,
resolvedValue?: string,
): : Promise<StepResult>
Source Code
async function sendStepToContentScript(
step: FlowStep,
resolvedValue?: string,
): Promise<StepResult> {
const payload: ExecuteStepPayload = {
step,
resolvedValue,
replayConfig: config,
};
try {
const response = await chrome.tabs.sendMessage(tabId, {
type: "DEMO_EXECUTE_STEP",
payload,
});
if (response?.result) {
return response.result as StepResult;
}
return { status: "failed", error: "No response from content script" };
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
// If message fails, content script may be gone (after navigation)
if (msg.includes("Receiving end does not exist")) {
const injected = await injectContentScript(tabId);
if (injected) {
try {
const retry = await chrome.tabs.sendMessage(tabId, {
type: "DEMO_EXECUTE_STEP",
payload,
});
if (retry?.result) return retry.result as StepResult;
} catch {
// fall through
}
}
}
return { status: "failed", error: msg };
}
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| injectContentScript | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| runLoop | calls |