The "Delayed Response" example in skills/playwright-cli/references/request-mocking.md doesn't work, because run-code has no setTimeout:
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):
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:
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.
The "Delayed Response" example in
skills/playwright-cli/references/request-mocking.mddoesn't work, becauserun-codehas nosetTimeout: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):
run-code "async page => typeof setTimeout"returns"undefined". The same is true ofURL,fetch,Buffer,cryptoandAbortController.Working version:
It would also help if
running-code.mdsaid thatrun-coderuns in a bare context without Node or timer globals.