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

guide me to Get action in serviceworker plz! #131

Open
shaahin18 opened this issue Jul 4, 2024 · 1 comment
Open

guide me to Get action in serviceworker plz! #131

shaahin18 opened this issue Jul 4, 2024 · 1 comment

Comments

@shaahin18
Copy link

hi majorimi
in your blazor-component notification, i can make notification appearing with 2 actions( copy paste your code!). but when clicking on notification buttons nothing happened. i know i must get that actions(action1,action2) in service worker.but can you explain or reference me to document for understanding how to do things such as go to a page or etc when user clicked on action buttons in notification popup.
thanks alot

@shaahin18 shaahin18 changed the title guid to Get action in serviceworker guide me to Get action in serviceworker plz! Jul 4, 2024
@A9G-Data-Droid
Copy link

The example in the demo code is here:
https://github.com/majorimi/blazor-components/blob/master/src/Majorsoft.Blazor.Components.TestApps.Common/wwwroot/sw.js

The actions you specify must be handled in the notificationclick event as described in related documentation:

https://docs.w3cub.com/dom/serviceworkerglobalscope/notificationclick_event

So in the example code you would do various things in JavaScript based on the action clicked:

self.addEventListener('notificationclick', event => {
    let action = event.action;
    let customData = event.notification.data;

    if (action = "action1") {
        !!!DoSomeJavaScriptHere!!!
    }

    let notification = event.notification;
    console.log("Notification clicked: " +  notification);
});

This is why you are passing the URL to a JavaScript file to the HtmlServiceWorkerNotificationOptions. That is where the action handlers live.

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

2 participants