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)

graph LR sendStepToContentScript["sendStepToContentScript"] injectContentScript["injectContentScript"] sendStepToContentScript -->|calls| injectContentScript style sendStepToContentScript fill:#dbeafe,stroke:#2563eb,stroke-width:2px click sendStepToContentScript "98a94012c260f4a2.html" click injectContentScript "8371aca98c2d1d41.html"
TargetType
injectContentScript calls

Impact (Incoming)

graph LR sendStepToContentScript["sendStepToContentScript"] runLoop["runLoop"] runLoop -->|calls| sendStepToContentScript style sendStepToContentScript fill:#dbeafe,stroke:#2563eb,stroke-width:2px click sendStepToContentScript "98a94012c260f4a2.html" click runLoop "c94a70bb97b4ccad.html"
SourceType
runLoop calls