This library is very useful and I would like to use it for service workers too. I noticed that it uses window object to attach detect to it. window object is inaccessible in service workers, but we can use this to achieve the same results.
I implemented and tested this solution:
Instead of passing window object to the function directly:
(function(root, undefined) {
// function body
})(window);
We can check first if window is undefined which means we run this library in a service worker. If so we can use this instead:
(function(root, undefined) {
// function body
})(typeof window == 'undefined' ? this : window);
This library is very useful and I would like to use it for service workers too. I noticed that it uses
windowobject to attachdetectto it.windowobject is inaccessible in service workers, but we can usethisto achieve the same results.I implemented and tested this solution:
Instead of passing window object to the function directly:
We can check first if window is undefined which means we run this library in a service worker. If so we can use
thisinstead: