I've got a service worker that I am using for push notifications in chrome and firefox, how can I exclude the service worker from running on Safari since it's causing exceptions. I've tried a couple of different ways of detecting if the user agent is safari, but it was always detecting as false even though it is Safari.
The last detection method I've used is as following:
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) {
return p.toString() === "[object SafariRemoteNotification]"; })
(!window['safari'] || (typeof safari !== 'undefined' &&
safari.pushNotification));
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;
var ua = navigator.userAgent.toLowerCase();
var safariWindows = ua.indexOf("safari/") !== -1 && ua.indexOf("windows")
!== -1 && ua.indexOf("chrom") === -1;
if (!isSafari && !safariWindows) {
//run service worker
}