Advanced Browser APIs — Series 3

Preview — 3 of 10 questions

The response headers arrive, then the signal aborts mid-download. What happens?

javascript
const c = new AbortController();
const res = await fetch('/big.json', { signal: c.signal });
console.log('headers', res.ok);

const p = res.json();
c.abort();

try {
  await p;
} catch (e) {
  console.log(e.name);
}
Aheaders true then nothing — the body is already fully buffered by the time fetch resolves.
Bheaders true then TypeError — aborting after the headers is a protocol error.
Cheaders true then AbortError
DThe fetch itself rejects, so headers is never logged.

Which statement is correct?

ArespondWith() supplies the response for the intercepted request and must be called synchronously in the fetch handler; waitUntil() extends the worker's lifetime so background work — such as populating the cache — can finish.
BBoth take a promise and are interchangeable; waitUntil is just the older name.
CrespondWith() may be called at any time, since the browser waits indefinitely for a service worker.
DwaitUntil() blocks the response until its promise settles, which is how cache-then-network is implemented.

You need a private two-way link between a page and one iframe, not a broadcast to every context of the origin. Which fits?

ABroadcastChannel, with a unique channel name per iframe.
BlocalStorage plus the storage event, the only cross-document channel.
CMessageChannel — transfer one of its two ports to the iframe with postMessage, then talk over the ports.
DNeither; cross-document messaging always reaches every same-origin context.

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.