I'm trying to add a service worker to my Rails app with the serviceworker gem.
I've been following this guide https://rossta.net/blog/offline-page-for-your-rails-application.html and started receiving the error listed in the title.
I've reviewed other questions similar, but most are due to syntax errors. As this post Rails 5 Heroku deploy error: ExecJS::ProgramError: SyntaxError: Unexpected token: name (autoRegisterNamespace)
My error is due to the token name (catch) which was supplied via the serviceworker gem file.
Here is my code where the error is occurring ...
function onFetch(event) {
// Fetch from network, fallback to cached content, then offline.html for same-origin GET requests
var request = event.request;
if (!request.url.match(/^https?:\/\/example.com/) ) { return; }
if (request.method !== 'GET') { return; }
event.respondWith(
fetch(request). // first, the network
.catch(function fallback() {
caches.match(request).then(function(response) { // then, the cache
response || caches.match("/offline.html.erb"); // then, /offline cache
})
})
);
I understand the error is at .catch , I'm just not sure how to solve the issue.
Any help is much appreciated, thanks!