Playwright · Middle · Question 40 of 75
How do you run code in the page before any of its scripts load?
- 1
page.beforeLoad() - 2
page.evaluate() - 3
page.addInitScript()
Show the answer
Correct answer: page.addInitScript()
Explanation
Init scripts run in every new document before page scripts, e.g. to stub Math.random or set a feature flag in localStorage.