Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with service workers #62

Open
alwaleedibrahim opened this issue Oct 19, 2024 · 0 comments
Open

Compatibility with service workers #62

alwaleedibrahim opened this issue Oct 19, 2024 · 0 comments

Comments

@alwaleedibrahim
Copy link

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant