Playwright · Middle · Question 18 of 75

How do you change a real API response slightly, e.g. one field?

await page.route("**/api/user", async (route) => {
  const response = await route.fetch();
  const json = await response.json();
  json.plan = "pro";
  await route.fulfill({ response, json });
});
Show the answer

Correct answer: Fetch it with route.fetch() and fulfill a modified copy

Explanation

This keeps the real backend in the loop while forcing one condition, such as a paid plan.

Further reading

Problem with a question

Playwright · Middle · question 18

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