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

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.com

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.

Related

Force one tab only on web app (e.g. similar to WhatsApp and Google Messenger)

I have a strict requirement to only allow a logged in user to open my web app in one tab. I've noticed that WhatsApp and Google Messenger's web apps have implemented this. For example, trying to open those apps in more than one tab (be it on the same browser, different browser, or even different device) results in these warnings:
Anyone know how this is done? There must be some sort of sync happening between the server and the client to ensure that only one tab is open. But this would require a unique tab identifier, which can get quite complicated to build reliably. Anyone know how WhatsApp and Google Messenger are doing it? Their technique seems to work flawlessly.
I don't know exactly how this is done at WhatsApp and Google Messenger, but if you work with WebSockets (your post hast the tag "websocket", so I assume, you do) every tab has its single connection to the server, and if your users need to be logged in you could check if the user has already a open weboscket connection to your server.

How to get webcam feed in chrome extension persistently when chrome is open?

I am trying to make a chrome extension where I need access to the webcam feed once the user has allowed permission and has toggled on button in the extension popup. The feed should (and the extension) should keep running persistently until the user has stopped the feed via the control in the popup or has exited chrome.
Unfortunately, there's not sufficient information as to how to do this, let alone access webcam from the extension. I did read the related answer where its mentioned to use content scripts but there's no example code for it. (And no documentation as well).
Also, unfortunately I don't have enough working code to give insight of my progress.

How does website display notifications after its page closed?

After visiting Facebook website and closing its page, weeks after I'm still getting browser notifications from Facebook about messages, posts, etc.
How is it implemented? Could a website install some scripts to be executed indefinitely regardless of having the website opened in a browser?
The most of browsers are allowing what we called it Push notifications
For example if in Chrome Browser
if you look at chrome://settings/content/notifications
You will find all websites allowed to send you notifications, it's kind of embedded scripts that will be stored in the browser website's cache
The notifications are simply an implementation of Observer design Pattern
actually the website makes a socket connection with your browser so even if you close your browser you can get push notification!

Record current tab in chrome using chrome extension and getUserMedia()

I am trying to make a Chrome extension to record user activity in the current tab.
I found out that I can use getUserMedia() on the front, and chrome.desktopCapture in my background script.
However, when I try to use chrome.desktopCapture.chooseDesktopMedia(['tab'], onApproved), I get prompted for the tab I want to share. However, I would like to skip this step and share my current tab without the prompt.
I know that this can be done, because in the Screencastify Chrome extension, you can do that. The first option is to record the current tab and no popups are displayed.
Have you taken a look at chrome.tabCapture API? It can be used inside of an extension, and unlike the chrome.desktopCapture API can be called programmatically without a prompt. The limitation is that the chrome.tabCapture API can only be used within an extension, and cannot be used within a Chrome packaged app (tested and verified in my own attempts at using the "tabCapture" permission in a custom packaged app). So, if you are just writing an extension, the chrome.tabCapture API might be your best option.

Calling Javascript Notification API on Google Chrome for Android not working directly from a web page

I'm working with the JavaScript Notification API to show a small message to my users. It works on every desktop browser I've tested with, including Chrome...but not Chrome for Android (KitKat, at least). Everything I've read says that Android Chrome supports the Notification API as of April 2015, and the app even has settings for Notification permissions...yet nothing happens when I call new Notification(...) from within it. In fact, even the official Mozilla Notification API demo page doesn't show them, despite being able to grab permissions information, etc.
Is there something special I need to do to make Notifications compatible with Android Chrome?
On Chrome for Android you can only open a notification via a Service Worker. A service worker is a script that runs alongside the browser and can be loaded even when the page or browser are currently closed.
The main reasoning behind the service worker requirement is that a notification can outlive the length of the browser's lifetime (i.e, the user can close the browser) and the notification will still be active, therefore when a user clicks on the notification Android needs to wake "something" up, this "something" is the Service Worker.
This Notification Guide is a good introduction to the current state of Notifications on the Web and in Chrome - it focuses a little on Push messaging but also has all the details of how to trigger a notification from the Service Worker.
This might seem like an extra hoop to jump through but it actually is a net benefit: your notification will still work when clicked even when the browser is closed.
Check this for compatibility: http://caniuse.com/#feat=notifications
"Partial Support" Although as Kinlan mentioned, it's possible with Web Service Workers.
navigator.serviceWorker.register('sw.js');
Notification.requestPermission(function(result) {
if (result === 'granted') {
navigator.serviceWorker.ready.then(function(registration) {
registration.showNotification('Notification with ServiceWorker');
});
}
});
The sw.js file can just be a zero-byte file.
Credit Due: HTML5 Notification not working in Mobile Chrome

Categories

Resources