{"payload":{"allShortcutsEnabled":false,"fileTree":{"service-worker/fallback-response":{"items":[{"name":"README.md","path":"service-worker/fallback-response/README.md","contentType":"file"},{"name":"index.html","path":"service-worker/fallback-response/index.html","contentType":"file"},{"name":"index.js","path":"service-worker/fallback-response/index.js","contentType":"file"},{"name":"service-worker.js","path":"service-worker/fallback-response/service-worker.js","contentType":"file"}],"totalCount":4},"service-worker":{"items":[{"name":"basic","path":"service-worker/basic","contentType":"directory"},{"name":"custom-offline-page","path":"service-worker/custom-offline-page","contentType":"directory"},{"name":"fallback-response","path":"service-worker/fallback-response","contentType":"directory"},{"name":"foreign-fetch","path":"service-worker/foreign-fetch","contentType":"directory"},{"name":"immediate-control","path":"service-worker/immediate-control","contentType":"directory"},{"name":"mock-responses","path":"service-worker/mock-responses","contentType":"directory"},{"name":"multiple-handlers","path":"service-worker/multiple-handlers","contentType":"directory"},{"name":"offline-analytics","path":"service-worker/offline-analytics","contentType":"directory"},{"name":"post-message","path":"service-worker/post-message","contentType":"directory"},{"name":"prefetch-video","path":"service-worker/prefetch-video","contentType":"directory"},{"name":"prefetch","path":"service-worker/prefetch","contentType":"directory"},{"name":"read-through-caching","path":"service-worker/read-through-caching","contentType":"directory"},{"name":"registration-events","path":"service-worker/registration-events","contentType":"directory"},{"name":"registration","path":"service-worker/registration","contentType":"directory"},{"name":"selective-caching","path":"service-worker/selective-caching","contentType":"directory"},{"name":"window-caches","path":"service-worker/window-caches","contentType":"directory"},{"name":"windowclient-navigate","path":"service-worker/windowclient-navigate","contentType":"directory"},{"name":".eslintrc","path":"service-worker/.eslintrc","contentType":"file"},{"name":"README.md","path":"service-worker/README.md","contentType":"file"},{"name":"serviceworker-cache-polyfill.js","path":"service-worker/serviceworker-cache-polyfill.js","contentType":"file"}],"totalCount":20},"":{"items":[{"name":"SAMPLE_STARTING_POINT","path":"SAMPLE_STARTING_POINT","contentType":"directory"},{"name":"_includes","path":"_includes","contentType":"directory"},{"name":"_layouts","path":"_layouts","contentType":"directory"},{"name":"allow-popups-to-escape-sandbox","path":"allow-popups-to-escape-sandbox","contentType":"directory"},{"name":"app-install-banner","path":"app-install-banner","contentType":"directory"},{"name":"array-includes-es7","path":"array-includes-es7","contentType":"directory"},{"name":"array-methods-es6","path":"array-methods-es6","contentType":"directory"},{"name":"arrows-es6","path":"arrows-es6","contentType":"directory"},{"name":"async-clipboard","path":"async-clipboard","contentType":"directory"},{"name":"audio","path":"audio","contentType":"directory"},{"name":"auto-picture-in-picture","path":"auto-picture-in-picture","contentType":"directory"},{"name":"autocapitalize","path":"autocapitalize","contentType":"directory"},{"name":"battery-status","path":"battery-status","contentType":"directory"},{"name":"beacon","path":"beacon","contentType":"directory"},{"name":"block-modal-dialogs-sandboxed-iframe","path":"block-modal-dialogs-sandboxed-iframe","contentType":"directory"},{"name":"classes-es6","path":"classes-es6","contentType":"directory"},{"name":"collections-iterators-es6","path":"collections-iterators-es6","contentType":"directory"},{"name":"compute-pressure","path":"compute-pressure","contentType":"directory"},{"name":"computed-properties-es6","path":"computed-properties-es6","contentType":"directory"},{"name":"cookie-prefixes","path":"cookie-prefixes","contentType":"directory"},{"name":"csp-upgrade-insecure-requests","path":"csp-upgrade-insecure-requests","contentType":"directory"},{"name":"css-alpha-channel","path":"css-alpha-channel","contentType":"directory"},{"name":"css-attribute-case-sensitivity","path":"css-attribute-case-sensitivity","contentType":"directory"},{"name":"css-custom-properties","path":"css-custom-properties","contentType":"directory"},{"name":"css-escape","path":"css-escape","contentType":"directory"},{"name":"css-flexbox-abspos","path":"css-flexbox-abspos","contentType":"directory"},{"name":"css-hyphens","path":"css-hyphens","contentType":"directory"},{"name":"css-intrinsic-sizing","path":"css-intrinsic-sizing","contentType":"directory"},{"name":"css-motion-path","path":"css-motion-path","contentType":"directory"},{"name":"css-opacity-force-flattening","path":"css-opacity-force-flattening","contentType":"directory"},{"name":"css-shapes","path":"css-shapes","contentType":"directory"},{"name":"css-will-change-transform-rasterization","path":"css-will-change-transform-rasterization","contentType":"directory"},{"name":"cut-and-copy","path":"cut-and-copy","contentType":"directory"},{"name":"decorators-es7","path":"decorators-es7","contentType":"directory"},{"name":"default-parameters-es6","path":"default-parameters-es6","contentType":"directory"},{"name":"destructuring-es6","path":"destructuring-es6","contentType":"directory"},{"name":"dialog","path":"dialog","contentType":"directory"},{"name":"encoding-api","path":"encoding-api","contentType":"directory"},{"name":"event-istrusted","path":"event-istrusted","contentType":"directory"},{"name":"event-listeners-mandatory-arguments","path":"event-listeners-mandatory-arguments","contentType":"directory"},{"name":"event-timestamp","path":"event-timestamp","contentType":"directory"},{"name":"extended-object-literals-es6","path":"extended-object-literals-es6","contentType":"directory"},{"name":"extended-unicode-escapes","path":"extended-unicode-escapes","contentType":"directory"},{"name":"fetch-api","path":"fetch-api","contentType":"directory"},{"name":"file-constructor","path":"file-constructor","contentType":"directory"},{"name":"focus-navigation-start-point","path":"focus-navigation-start-point","contentType":"directory"},{"name":"font-face-set","path":"font-face-set","contentType":"directory"},{"name":"formdata-methods","path":"formdata-methods","contentType":"directory"},{"name":"generators","path":"generators","contentType":"directory"},{"name":"hdcp-detection","path":"hdcp-detection","contentType":"directory"},{"name":"idb-getall","path":"idb-getall","contentType":"directory"},{"name":"image-capture","path":"image-capture","contentType":"directory"},{"name":"image-rendering-pixelated","path":"image-rendering-pixelated","contentType":"directory"},{"name":"images","path":"images","contentType":"directory"},{"name":"indexeddb-observers","path":"indexeddb-observers","contentType":"directory"},{"name":"input-device-capabilities","path":"input-device-capabilities","contentType":"directory"},{"name":"intersectionobserver","path":"intersectionobserver","contentType":"directory"},{"name":"intrinsic-size","path":"intrinsic-size","contentType":"directory"},{"name":"keyboardevent-code-attribute","path":"keyboardevent-code-attribute","contentType":"directory"},{"name":"keyboardevent-key-attribute","path":"keyboardevent-key-attribute","contentType":"directory"},{"name":"lexical-declarations-es6","path":"lexical-declarations-es6","contentType":"directory"},{"name":"media-capabilities","path":"media-capabilities","contentType":"directory"},{"name":"media-hover-pointer","path":"media-hover-pointer","contentType":"directory"},{"name":"media-session","path":"media-session","contentType":"directory"},{"name":"media","path":"media","contentType":"directory"},{"name":"mouseevent-get-modifier-state","path":"mouseevent-get-modifier-state","contentType":"directory"},{"name":"multi-column-css","path":"multi-column-css","contentType":"directory"},{"name":"muted-autoplay","path":"muted-autoplay","contentType":"directory"},{"name":"network-information","path":"network-information","contentType":"directory"},{"name":"new-target-es6","path":"new-target-es6","contentType":"directory"},{"name":"notifications","path":"notifications","contentType":"directory"},{"name":"object-assign-es6","path":"object-assign-es6","contentType":"directory"},{"name":"paymentrequest","path":"paymentrequest","contentType":"directory"},{"name":"permissions","path":"permissions","contentType":"directory"},{"name":"picture-element","path":"picture-element","contentType":"directory"},{"name":"picture-in-picture","path":"picture-in-picture","contentType":"directory"},{"name":"play-return-promise","path":"play-return-promise","contentType":"directory"},{"name":"presentation-api","path":"presentation-api","contentType":"directory"},{"name":"promise-rejection-events","path":"promise-rejection-events","contentType":"directory"},{"name":"proxies-es6","path":"proxies-es6","contentType":"directory"},{"name":"push-messaging-and-notifications","path":"push-messaging-and-notifications","contentType":"directory"},{"name":"quictransport","path":"quictransport","contentType":"directory"},{"name":"report-validity","path":"report-validity","contentType":"directory"},{"name":"resizeobserver","path":"resizeobserver","contentType":"directory"},{"name":"rest-parameters-es6","path":"rest-parameters-es6","contentType":"directory"},{"name":"screen-orientation","path":"screen-orientation","contentType":"directory"},{"name":"service-worker","path":"service-worker","contentType":"directory"},{"name":"spread-operator","path":"spread-operator","contentType":"directory"},{"name":"styles","path":"styles","contentType":"directory"},{"name":"subresource-integrity","path":"subresource-integrity","contentType":"directory"},{"name":"template-literals-es6","path":"template-literals-es6","contentType":"directory"},{"name":"touch-action","path":"touch-action","contentType":"directory"},{"name":"typedarray-methods-es6","path":"typedarray-methods-es6","contentType":"directory"},{"name":"urlsearchparams","path":"urlsearchparams","contentType":"directory"},{"name":"variable-fonts-experiments","path":"variable-fonts-experiments","contentType":"directory"},{"name":"vibration","path":"vibration","contentType":"directory"},{"name":"web-animations","path":"web-animations","contentType":"directory"},{"name":"web-application-manifest","path":"web-application-manifest","contentType":"directory"},{"name":"web-bluetooth","path":"web-bluetooth","contentType":"directory"},{"name":"web-nfc","path":"web-nfc","contentType":"directory"},{"name":"web-share","path":"web-share","contentType":"directory"},{"name":"web-vr","path":"web-vr","contentType":"directory"},{"name":"webassembly","path":"webassembly","contentType":"directory"},{"name":"webaudio-audiocontext-close","path":"webaudio-audiocontext-close","contentType":"directory"},{"name":"webaudio-audionode-disconnect","path":"webaudio-audionode-disconnect","contentType":"directory"},{"name":"webaudio-method-chaining","path":"webaudio-method-chaining","contentType":"directory"},{"name":"webaudio-offlinecontext-rendering","path":"webaudio-offlinecontext-rendering","contentType":"directory"},{"name":"webaudio-suspend-resume","path":"webaudio-suspend-resume","contentType":"directory"},{"name":"webtransport","path":"webtransport","contentType":"directory"},{"name":".DS_Store","path":".DS_Store","contentType":"file"},{"name":".eslintignore","path":".eslintignore","contentType":"file"},{"name":".eslintrc","path":".eslintrc","contentType":"file"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"Gemfile","path":"Gemfile","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"_config.yml","path":"_config.yml","contentType":"file"},{"name":"index.html","path":"index.html","contentType":"file"},{"name":"package-lock.json","path":"package-lock.json","contentType":"file"},{"name":"package.json","path":"package.json","contentType":"file"}],"totalCount":121}},"fileTreeProcessingTime":15.524087000000002,"foldersToFetch":[],"repo":{"id":20438302,"defaultBranch":"gh-pages","name":"samples","ownerLogin":"GoogleChrome","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2014-06-03T10:15:52.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1778935?v=4","public":true,"private":false,"isOrgOwned":true},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"gh-pages","listCacheKey":"v0:1710262882.0","canEdit":false,"refType":"branch","currentOid":"c4f3954989c7f3dc2a39b61bbd11a7781554080b"},"path":"service-worker/fallback-response/index.html","currentUser":null,"blob":{"rawLines":["---","feature_name: \"Service Worker Sample: Fallback Response\"","chrome_version: 42","feature_id: 6561526227927040","---","","

Background

","

"," This sample demonstrates basic service worker registration, with the service worker providing"," fallback responses when specific HTTP requests fail. This is done within the fetch handler of"," the service worker, and will only work for responses that are not"," opaque,"," since we need to examine the response's HTTP status code.","

","","{% capture initial_output_content %}","

"," Each of these buttons will trigger a CORS-enabled HTTP request to fetch a list of videos from"," the YouTube Data API. One button makes a valid request, and the other makes an invalid request"," that always trigger an error response (due to an invalid API key). The service worker takes care"," of translating the error response into a valid fallback response, which is treated by the host"," page exactly like any other valid response.","

","","","","{% endcapture %}","{% include output_helper.html initial_output_content=initial_output_content %}","","{% include js_snippet.html filename='index.js' title=\"This Page's JavaScript\" %}","{% include js_snippet.html filename='service-worker.js' displayonly=true title=\"Service Worker's JavaScript\" %}"],"stylingDirectives":[[],[],[],[],[],[],[{"start":0,"end":1,"cssClass":"pl-kos"},{"start":1,"end":3,"cssClass":"pl-ent"},{"start":3,"end":4,"cssClass":"pl-kos"},{"start":14,"end":16,"cssClass":"pl-kos"},{"start":16,"end":18,"cssClass":"pl-ent"},{"start":18,"end":19,"cssClass":"pl-kos"}],[{"start":0,"end":1,"cssClass":"pl-kos"},{"start":1,"end":2,"cssClass":"pl-ent"},{"start":2,"end":3,"cssClass":"pl-kos"}],[],[],[],[{"start":2,"end":3,"cssClass":"pl-kos"},{"start":3,"end":4,"cssClass":"pl-ent"},{"start":5,"end":9,"cssClass":"pl-c1"},{"start":11,"end":74,"cssClass":"pl-s"},{"start":75,"end":76,"cssClass":"pl-kos"},{"start":82,"end":84,"cssClass":"pl-kos"},{"start":84,"end":85,"cssClass":"pl-ent"},{"start":85,"end":86,"cssClass":"pl-kos"}],[],[{"start":0,"end":2,"cssClass":"pl-kos"},{"start":2,"end":3,"cssClass":"pl-ent"},{"start":3,"end":4,"cssClass":"pl-kos"}],[],[],[{"start":0,"end":1,"cssClass":"pl-kos"},{"start":1,"end":2,"cssClass":"pl-ent"},{"start":2,"end":3,"cssClass":"pl-kos"}],[],[],[],[],[],[{"start":0,"end":2,"cssClass":"pl-kos"},{"start":2,"end":3,"cssClass":"pl-ent"},{"start":3,"end":4,"cssClass":"pl-kos"}],[],[{"start":0,"end":1,"cssClass":"pl-kos"},{"start":1,"end":7,"cssClass":"pl-ent"},{"start":8,"end":10,"cssClass":"pl-c1"},{"start":12,"end":26,"cssClass":"pl-s"},{"start":28,"end":36,"cssClass":"pl-c1"},{"start":36,"end":37,"cssClass":"pl-kos"},{"start":55,"end":57,"cssClass":"pl-kos"},{"start":57,"end":63,"cssClass":"pl-ent"},{"start":63,"end":64,"cssClass":"pl-kos"}],[{"start":0,"end":1,"cssClass":"pl-kos"},{"start":1,"end":7,"cssClass":"pl-ent"},{"start":8,"end":10,"cssClass":"pl-c1"},{"start":12,"end":28,"cssClass":"pl-s"},{"start":30,"end":38,"cssClass":"pl-c1"},{"start":38,"end":39,"cssClass":"pl-kos"},{"start":59,"end":61,"cssClass":"pl-kos"},{"start":61,"end":67,"cssClass":"pl-ent"},{"start":67,"end":68,"cssClass":"pl-kos"}],[],[],[],[],[]],"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/GoogleChrome/samples/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"index.html","displayUrl":"https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/fallback-response/index.html?raw=true","headerInfo":{"blobSize":"1.42 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"9178baa","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2FGoogleChrome%2Fsamples%2Fblob%2Fgh-pages%2Fservice-worker%2Ffallback-response%2Findex.html","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"31","truncatedSloc":"27"},"mode":"executable file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"HTML","languageID":146,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/GoogleChrome/samples/blob/gh-pages/service-worker/fallback-response/index.html","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/GoogleChrome/samples/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/GoogleChrome/samples/raw/gh-pages/service-worker/fallback-response/index.html","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":{"timed_out":false,"not_analyzed":true,"symbols":[]}},"copilotInfo":null,"copilotAccessAllowed":false,"csrf_tokens":{"/GoogleChrome/samples/branches":{"post":"dAadl3LvXCekyA9ag_zScKLL637DFJxkrBzsZPK4DDHgjw_fDdj8tVmtRR7QNSbXsSdYbmAWKFGabrZKJmtqhQ"},"/repos/preferences":{"post":"tCQT0uaCu3EIfuoUIoWIx4JpTWq2GIrXZZ7hSQdWAeywZbq3L2Vz12_e0Qp5jMeoWLkVzG5NDlGM-fr7jWh_Gg"}}},"title":"samples/service-worker/fallback-response/index.html at gh-pages ยท GoogleChrome/samples"}