// service-worker.js
self.addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
if (url.pathname === "/salamander.jpg") {
event.respondWith(Response.error());
}
});Response: error() static method / notebook
Response: error() static method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// main.js
const image = document.querySelector("#image");
try {
const response = await fetch("salamander.jpg");
const blob = await response.blob();
const objectURL = URL.createObjectURL(blob);
image.src = objectURL;
} catch (e) {
console.error(e);
}