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

Can this work with server-side rendering? #42

Closed
elliotlings opened this issue Jul 31, 2018 · 2 comments
Closed

Can this work with server-side rendering? #42

elliotlings opened this issue Jul 31, 2018 · 2 comments

Comments

@elliotlings
Copy link

Do you know whether this library can work with server-side rendering?

@ai
Copy link
Owner

ai commented Jul 31, 2018

As I know it should work without document and other browser-specific API. It will just think that the page is always visible.

If you will have any problems, please report. I will try to fix it quickly.

@ai ai closed this as completed Jul 31, 2018
@mrlaseptima
Copy link

mrlaseptima commented Dec 29, 2020

hi . @elliotlings
i use it in SSR in after js ,
you can check server side rendering and then use dynamic import

 isServer() {
    return !(typeof window != "undefined" && window.document);
 }
 async chatBrowserNotif(title = "", options, onClick) {
    if (!isServer()) {
      //use dynamic import because this package cant run in server side
      const Visibility = await import("visibilityjs");
      if ("hidden" == Visibility.state()) {
        const notification = new Notification(title, {
          ...options,
        });
        notification.onclick = (e) => {
          onClick();
        };
      }
    }
  }

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

3 participants