最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome Notifications - Magic Push even when the website is not open - Stack Overflow

programmeradmin5浏览0评论

I have built a chrome extension in the past and I have used chrome notifications API in that extension so I'm familiar with how it works.

I recently found this website which shows this notifications when something happens but the weirdest part is that even when this website is not opened in any tab it pushes these notifications (as long as chrome is open). I want to know how they do it.

I checked my settings->extensions list to see if I installed their extension somehow but there is none. So where are they running this magic javascript from?

Website is called

I have built a chrome extension in the past and I have used chrome notifications API in that extension so I'm familiar with how it works.

I recently found this website which shows this notifications when something happens but the weirdest part is that even when this website is not opened in any tab it pushes these notifications (as long as chrome is open). I want to know how they do it.

I checked my settings->extensions list to see if I installed their extension somehow but there is none. So where are they running this magic javascript from?

Website is called https://www.greentoe.

Share Improve this question edited Jul 28, 2015 at 19:14 Garbee 11k5 gold badges39 silver badges41 bronze badges asked Jul 28, 2015 at 17:22 sublimesublime 4,18110 gold badges57 silver badges97 bronze badges 5
  • 2 Push Notifications "The reason for this is that when a push message is received, the browser can start up a service worker, which runs in the background without a page being open, and dispatch an event so that you can decide how to handle that push message." – Andreas Commented Jul 28, 2015 at 17:35
  • 1 Yes, but when Worker Service is running in the background that pushes these notifications there has to be some Javascript that actually tells the worker service to push them. In usual case it's a chrome extension or a website's javascript. But they are doing it even when the website is not open and no extension is installed. – sublime Commented Jul 28, 2015 at 17:40
  • 1 Did you follow the link? It points to the google developer site regarding push notifications with all informations you need. Docu, sample repo, demo,... – Andreas Commented Jul 28, 2015 at 17:43
  • @Andreas Would you mind making an actual answer out of that? – Xan Commented Jul 28, 2015 at 23:00
  • 1 Since no one has mentioned its name, it's called Push API. There are also services like this that make it straightforward to add it to a website/blog – collimarco Commented Sep 3, 2016 at 8:03
Add a ment  | 

1 Answer 1

Reset to default 13 +25

According to the official documentation and as stated by @Andreas

The reason for this is that when a push message is received, the browser can start up a service worker, which runs in the background without a page being open, and dispatch an event so that you can decide how to handle that push message.

The javascript code you are asking for is inside the worker.

If you want to see the workers actually used in your browser just go to chrome://inspect/#service-workers in a new tab. You can see the worker code by clicking on the inspect link under the worker name.

发布评论

评论列表(0)

  1. 暂无评论