Playwright · Middle · Question 40 of 75

How do you run code in the page before any of its scripts load?

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.

Further reading

Problem with a question

Playwright · Middle · question 40

Test yourself

Take the Playwright · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz