Skip to content
Foxipa
Code Completion 5 Challenges

Complete the code: fetch(keepalive)

Fill in the missing superset flags — and the guarantee it still cannot give you.

Intermediate ~4 min read

Challenge 1

The flag that lets the request outlive the page.

js Your answer
await fetch(url, {
  method: 'POST',
  body,
  : true,
});

Press Ctrl⌘Enter to check your answer

Challenge 2

The header sendBeacon cannot send — fetch can.

js Your answer
await fetch(url, {
  method: 'POST',
  body,
  keepalive: true,
  headers: { '': `Bearer ${token}` },
});

Press Ctrl⌘Enter to check your answer

Challenge 3

Opt the keepalive send out of cookies.

js Your answer
await fetch(url, {
  method: 'POST',
  body,
  keepalive: true,
  credentials: '',
});

Press Ctrl⌘Enter to check your answer

Challenge 4

Check the delivery sendBeacon never reports.

js Your answer
const res = await fetch(url, { method: 'POST', body, keepalive: true });
if (!res.) throw new Error(`collector said ${res.status}`);

Press Ctrl⌘Enter to check your answer

Challenge 5

Complete the honest comment about the superset's gap.

js Your answer
// fetch(keepalive) MAY outlive the page, but only sendBeacon
// carries the spec's  on the hidden transition.

Press Ctrl⌘Enter to check your answer