Skip to content

Service Worker is not working as expected in react typescript #208

@chetanshinde118

Description

@chetanshinde118

Below is the error which I received.
TypeError: Failed to register a ServiceWorker for scope ('http://localhost:9000/') with script ('http://localhost:9000/serviceWorker.js'): A bad HTTP response code (404) was received when fetching the script.

Below are the script added in index.html and serviceWorker.js is added at same location.
for now I kept serviceWorker.js empty
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('serviceWorker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions