Wednesday, 12 May 2021

Using the Notification API from a bookmarklet

I am trying to write a bookmarklet that sends me a desktop notification when CI on GitHub completes. Notification.requestPermission runs correctly, and asks me for permission, and the console.log statements run correctly, but the notification does not appear. Here is the text of the bookmarklet script:

(function() {
  Notification.requestPermission().then(() => {
    const search = setInterval(() => {
      if (window.find("All checks have passed")) {
        console.log('all checks passed');
        clearTimeout(search);
        new Notification('Github checks passed!');
      } else {
        console.log('checks pending');
      }
    }, 1000);
  });
})();

i.e.

javascript:(function() {Notification.requestPermission().then(() => {const search = setInterval(() => {if (window.find("All checks have passed")) {console.log('all checks passed');clearTimeout(search);new Notification('Github checks passed!');} else {console.log('checks pending');}}, 1000);});})();

Is this a sandboxing thing?



from Using the Notification API from a bookmarklet

No comments:

Post a Comment