waitForContentScript function test exported

Last updated: 2026-03-01T23:25:47.057Z

Metrics

LOC: 9 Complexity: 2 Params: 1

Signature

waitForContentScript(page: Page): : Promise<void>

Summary

Waits for the content script to finish initializing on the given page. The content script registers chrome.runtime.onMessage synchronously but may call async initContentScript() before being fully operational. We add a small delay after DOMContentLoaded to let that settle. If the page exposes window.__fillAllReady (set by the content script), we wait for that; otherwise we fall back to a 600 ms timeout which is sufficient for document_idle injection.

Source Code

export async function waitForContentScript(page: Page): Promise<void> {
  await page.waitForFunction(
    () =>
      document.readyState === "complete" ||
      document.readyState === "interactive",
  );
  // The content script is injected at `document_idle`; give it time to init.
  await page.waitForTimeout(600);
}

No outgoing dependencies.

Impact (Incoming)

graph LR waitForContentScript["waitForContentScript"] FieldSummary["FieldSummary"] FieldSummary -->|uses| waitForContentScript style waitForContentScript fill:#dbeafe,stroke:#2563eb,stroke-width:2px click waitForContentScript "5252ec99308fee44.html" click FieldSummary "b2a72169196ce9a2.html"
SourceType
FieldSummary uses