Reputation: 649
I am creating an Angular web application that implements both AppCache, and Service workers. I have service workers enabled on my application, so my application works fine on all browsers except Internet explorer. I need a way to disable the service workers if the application is ran on IE. I am looking into the application detecting what browser it is being ran on, and invoking some code to disable service workers or something along the lines of that. If anyone has any experience regarding this, I would appreciate some guidance.
Upvotes: 2
Views: 2145
Reputation: 5263
The most common way to check for the browser's compatibility with Service Worker is this:
if ('ServiceWorker' in navigator) {
// supported
} else {
// not supported
}
Most of the time you don't need to explicitly check what browser the current user runs since that test gives you enough information. So don't check for the UA in this simple case.
It should be noted, though, that different version of Firefox and Chrome support different number of Service Worker functionality. This means that even if the test passes, it is possible to try to execute SW specific code that causes the browser to throw en error since the APIs or whatnot have not been implemented in the browser version currently in use. In these situations, a more careful inspection of the browser's capabilities is required.
Upvotes: 2