Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

service worker self.clients

addEventListener('notificationclick', event => {
  event.waitUntil(async function() {
    const allClients = await clients.matchAll({
      includeUncontrolled: true
    });

    let chatClient;

    // Let's see if we already have a chat window open:
    for (const client of allClients) {
      const url = new URL(client.url);

      if (url.pathname == '/chat/') {
        // Excellent, let's use it!
        client.focus();
        chatClient = client;
        break;
      }
    }

    // If we didn't find an existing chat window,
    // open a new one:
    if (!chatClient) {
      chatClient = await clients.openWindow('/chat/');
    }

    // Message the client:
    chatClient.postMessage("New chat messages!");
  }());
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue router "savedposition" with ajax call 
Javascript :: js remove trailling lines 
Javascript :: when click play sound 
Javascript :: get buildspec.yml file for react app 
Javascript :: using javascript array create bootstrap card 
Javascript :: validate ajax nonce request wordpress 
Javascript :: appregistry react native 
Javascript :: escape double quotes in json 
Javascript :: build json object 
Javascript :: find consecutive numbers in an array javascript 
Javascript :: Hide ReactTooltip after hover off 
Javascript :: react native elements bottom sheet 
Javascript :: use obj property inside itself 
Javascript :: router.push next js 
Javascript :: modal example react native 
Javascript :: pass object in asyncstorage in react native 
Javascript :: javascript true string to boolean 
Javascript :: res.write in node js 
Javascript :: cypress check element has an attribute 
Javascript :: slice() in javascript 
Javascript :: get search value from reacr route3 
Javascript :: js recursive fetch 
Javascript :: hide urls in .env in react app 
Javascript :: hook use effect with hooks 
Javascript :: how to create object js 
Javascript :: audio customization 
Javascript :: react native dropdown 
Javascript :: adding mui theme to index.js 
Javascript :: a function that returns a string javascript 
Javascript :: lazy load npm package 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =