Skip to content
masterclass Buddy

Playwright · Method

page.addInitScript

Installs JavaScript that runs in new page documents before the page's own scripts. It is useful for changing the page environment, such as making Math.random predictable.

Last updated

Since
v1.9

Syntax

page.addInitScript(script[, arg[, options]])

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • browserContext.addInitScript()
  • page.exposeFunction()
  • page.evaluate()

Source: Page | Playwright. Checked 2026-11-03.