{
  "slug": "addinitscript-accepts-functions-as-arguments-3f8b9d21c097",
  "title": "addInitScript() accepts functions as arguments",
  "tools": [
    "playwright"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-07-24T21:55:03.000Z",
  "announced_at": "2026-07-24T21:55:03.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When an init script needs a function in its argument, pass a function as the script and set `exposeFunctions: true`. The function is callable from the init script and returns a Promise.",
    "examples": [
      "await page.addInitScript(({ callback }) => { window.result = callback(); }, { callback: async () => 'value' }, { exposeFunctions: true });",
      "await browserContext.addInitScript(({ callback }) => { window.result = callback(); }, { callback: async () => 'value' }, { exposeFunctions: true });"
    ],
    "gotchas": [
      "Version: v1.62.0",
      "script (required): Function, string, or object describing the init script; `arg` is supported only with a function.",
      "arg: Optional argument passed to the script function; with `exposeFunctions: true`, functions in it are exposed to the page.",
      "options.exposeFunctions: Boolean; set to `true` to expose functions passed inside `arg`. Calls return Promises. Defaults to `false`, when functions are silently dropped. No mutually exclusive sub-keys are documented.",
      "Prerequisite: Use Playwright v1.62.0 or later for `exposeFunctions`; it was added in v1.62."
    ]
  },
  "why_it_matters": "Pass a function as an init-script argument when configuring page or context setup in a test.",
  "sources": [
    "https://github.com/microsoft/playwright/releases/tag/v1.62.0",
    "https://playwright.dev/docs/api/class-page",
    "https://playwright.dev/docs/api/class-browsercontext"
  ],
  "rank": 0.93031,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v1+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "backfill-20261007",
    "verdict_id": "backfill-20261007:backfill-20261007-48c92cac04e84aed-10:gate",
    "evidence_hash": "b17276139b84e8e6a01d64416d3a7c27f07ddffc91b7a327300bf595585d287e"
  },
  "review": {
    "draft_hash": "18164b433cd459792ccf52859baedf801ae3ed974592978cd90f8c11cb1e98fc",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "backfill-20261007:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.93 >= 0.9; 2 needed) and Jev gave 0.63 (>= 0.6 needed)."
  }
}
