Skip to content

Compatibility with service workers #62

@alwaleedibrahim

Description

@alwaleedibrahim

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions