Skip to content
Foxipa
Code Completion 5 Challenges

Complete the code: Testing & Debugging

Fill in the missing Playwright interception patterns and lifecycle-state drivers.

Advanced ~4 min read

Challenge 1

Intercept the collector's beacons in Playwright.

js Your answer
await page.('**/collect', (route) => {
  expect(route.request().method()).toBe('POST');
  return route.fulfill({ status: 204 });
});

Press Ctrl⌘Enter to check your answer

Challenge 2

The DevTools setting without which page-death beacons vanish.

js Your answer
// DevTools > Network: enable
// '' BEFORE navigating away

Press Ctrl⌘Enter to check your answer

Challenge 3

Drive the visibility state directly through CDP.

js Your answer
const cdp = await page.context().newCDPSession(page);
await cdp.send('.setWebLifecycleState', { state: 'hidden' });

Press Ctrl⌘Enter to check your answer

Challenge 4

Fill the keepalive pool with synthetic pressure.

js Your answer
// occupy nearly 64 KiB of in-flight quota
await page.evaluate(async () => {
  window.holders = [];
  for (let i = 0; i < 8; i++) {
    window.holders.push(fetch('/slow', {
      method: 'POST',
      body: 'x'.repeat(7 * 1024),
      : true,
    }));
  }
});

Press Ctrl⌘Enter to check your answer

Challenge 5

Assert the silent-drop contract.

js Your answer
const queued = await page.evaluate(() =>
  navigator.sendBeacon('/collect', 'x'.repeat(10 * 1024))
);
expect(queued).toBe(); // quota refusal, no console error

Press Ctrl⌘Enter to check your answer