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

[question]: How to prevent web notifications from showing when tab is being viewed? #1676

Closed
1 task done
thatop007 opened this issue Mar 27, 2024 · 1 comment
Closed
1 task done

Comments

@thatop007
Copy link

thatop007 commented Mar 27, 2024

How can we help?

We currently able to receive web desktop notifications successfully and would like to know if it is possible and how to prevent web notifications from showing when the tab being viewed by the user is our site.

here is our current implementation in our react web app, in particular our attempt to not show the notification if the user is currently looking at our site.

  useEffect(() => {
    function foregroundWillDisplayListener (event) {
      console.log(event);
      //dont show notification if tab is currently being viewed
      if (document.visibilityState === 'visible') {
        return event.preventDefault();
        
      }
    }
        OneSignalDeferred.push(function () {
      OneSignal.Notifications.addEventListener("foregroundWillDisplay", foregroundWillDisplayListener);

    });

  }, []);

looking at foregroundWillDisplayListener event param I saw there are 2 params:

  • notification
  • preventDefault - when call the prevent default function we are getting this error:
Error: Browser does not support preventing display.
    at Object.preventDefault (ServiceWorkerManager.js:168:27)
image

your time and assistance is highly appreciated.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jkasten2
Copy link
Member

@thatop007 this repo only supports Android and iOS, and but I see you are using this on a web site, and using the OneSignal-Website-SDK.

I see you created an issue on the OneSignal-Website-SDK repo so I followed up with you there.

@OneSignal OneSignal locked as off-topic and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants