From 4d6344e51268e717f16dff07351d585c2184e03c Mon Sep 17 00:00:00 2001 From: Sinan Keskin Date: Thu, 22 Apr 2021 23:12:37 +0300 Subject: [PATCH] Fix cannot read property 'indexOf' of null error --- service-worker/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service-worker/index.js b/service-worker/index.js index 2e8c288..f6d8337 100644 --- a/service-worker/index.js +++ b/service-worker/index.js @@ -34,7 +34,8 @@ self.addEventListener('fetch', (event) => { let request = event.request; let url = new URL(request.url); let isGETRequest = request.method === 'GET'; - let isHTMLRequest = request.headers.get('accept').indexOf('text/html') !== -1; + let acceptHeader = request.headers !== null ? request.headers.get('accept') : null; + let isHTMLRequest = acceptHeader !== null ? acceptHeader.indexOf('text/html') !== -1 : true; let isLocal = url.origin === location.origin; let scopeExcluded = urlMatchesAnyPattern(request.url, INDEX_EXCLUDE_SCOPE); let scopeIncluded = !INDEX_INCLUDE_SCOPE.length || urlMatchesAnyPattern(request.url, INDEX_INCLUDE_SCOPE);