You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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})(typeofwindow=='undefined' ? this : window);
The text was updated successfully, but these errors were encountered:
This library is very useful and I would like to use it for service workers too. I noticed that it uses
window
object to attachdetect
to it.window
object is inaccessible in service workers, but we can usethis
to 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
this
instead:The text was updated successfully, but these errors were encountered: