request-mocking.md "Delayed Response" example uses setTimeout, which run-code doesn't provide

Author: ezroverCreated Sep 28, 2026Updated Sep 28, 2026

The "Delayed Response" example in skills/playwright-cli/references/request-mocking.md doesn't work, because run-code has no setTimeout:

bash
playwright-cli run-code "async page => {
  await page.route('**/api/slow', async route => {
    await new Promise(r => setTimeout(r, 3000));
    route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
  });
}"

When the route fires, the handler throws ReferenceError: setTimeout is not defined, and the request never gets fulfilled (it hangs until the client gives up).

Repro (playwright-cli 0.1.21, Chrome 153, macOS):

bash
playwright-cli -s=t open http://127.0.0.1:8767/page.html
playwright-cli -s=t run-code "async page => { await page.route('**/api/slow', async route => { await new Promise(r => setTimeout(r, 300)); route.fulfill({ body: 'loaded' }); }); }"
playwright-cli -s=t --raw eval "async () => { const c = new AbortController(); setTimeout(() => c.abort(), 5000); try { const r = await fetch('/api/slow', { signal: c.signal }); return r.status; } catch (e) { return e.name; } }"
# prints ReferenceError: setTimeout is not defined, then "AbortError"

run-code "async page => typeof setTimeout" returns "undefined". The same is true of URL, fetch, Buffer, crypto and AbortController.

Working version:

javascript
await page.route('**/api/slow', async route => {
  await page.waitForTimeout(3000);
  route.fulfill({ body: JSON.stringify({ data: 'loaded' }) });
});

It would also help if running-code.md said that run-code runs in a bare context without Node or timer globals.

Source: microsoft/playwright-cli