summarylogtreecommitdiffstats
path: root/whatsapp-nativefier-inject.js
diff options
context:
space:
mode:
authorFredy García2021-11-02 15:57:13 -0500
committerFredy García2021-11-02 15:57:13 -0500
commitf399849b04cc480709c0b772a5925f791fc724a2 (patch)
tree8710c545d351f0928afdd88aa3090a7825db1a7b /whatsapp-nativefier-inject.js
parentceeefcd4326b7c8ffd136821dbebf83ac06b3a0b (diff)
downloadaur-f399849b04cc480709c0b772a5925f791fc724a2.tar.gz
Adding async invocations in case of delay in unsupported web browser message.
Diffstat (limited to 'whatsapp-nativefier-inject.js')
-rw-r--r--whatsapp-nativefier-inject.js68
1 files changed, 43 insertions, 25 deletions
diff --git a/whatsapp-nativefier-inject.js b/whatsapp-nativefier-inject.js
index d5ba62be5a07..54727e9cf0db 100644
--- a/whatsapp-nativefier-inject.js
+++ b/whatsapp-nativefier-inject.js
@@ -1,28 +1,46 @@
-console.info("Checking for service worker in navigator...");
-if ("serviceWorker" in navigator) {
- console.info("Service worker found in navigator.");
+const TIME_BETWEEN_INVOCATIONS = 5000; // Time between invocations (ms)
+const NUMBER_OF_INVOCATIONS = 5; // Number of invocations
- console.info("Checking cache names from service worker...");
- caches.keys().then(function (cacheNames) {
- console.info("CacheNames:", cacheNames);
- cacheNames.forEach(function (cacheName) {
- console.info("Deleting cache", cacheName, "...");
- caches.delete(cacheName).then(function (result) {
- console.info("Cache", cacheName, "deleted:", result);
- });
- });
- });
+console.info("Checking time between invocations:", TIME_BETWEEN_INVOCATIONS, ", Number of invocations:", NUMBER_OF_INVOCATIONS);
- console.info("Checking service worker registrations...");
- navigator.serviceWorker.getRegistrations().then(function(registrations) {
- console.info("Registrations:", registrations);
- registrations.forEach(function (registration) {
- console.info("Unregistering registration", registration, "...");
- registration.unregister().then(function(result) {
- console.info("Registration", registration, "unregistered:", result);
- });
- });
- });
-} else {
- console.info("Service worker not found in navigator.");
+let invocationNumber = 0;
+for(var number = 0; number < NUMBER_OF_INVOCATIONS; number++) {
+ setTimeout(function() {
+ console.info("*****", ++invocationNumber, "******")
+ console.info("Checking for service worker in navigator...");
+ if ("serviceWorker" in navigator) {
+ console.info("Service worker found in navigator. Checking for unsupported browser message...");
+ if (document.querySelector("a[href='https://support.google.com/chrome/answer/95414']")) {
+ console.info("Checking cache names from service worker...");
+ caches.keys().then(function (cacheNames) {
+ console.info("CacheNames:", cacheNames);
+ cacheNames.forEach(function (cacheName) {
+ console.info("Deleting cache", cacheName, "...");
+ caches.delete(cacheName).then(function (result) {
+ console.info("Cache", cacheName, "deleted:", result);
+ });
+ });
+ });
+
+ console.info("Checking service worker registrations...");
+ navigator.serviceWorker.getRegistrations().then(function(registrations) {
+ console.info("Registrations:", registrations);
+ registrations.forEach(function (registration) {
+ console.info("Unregistering registration", registration, "...");
+ registration.unregister().then(function(result) {
+ console.info("Registration", registration, "unregistered:", result);
+ });
+ });
+ });
+
+ setTimeout(function() {
+ document.location.reload();
+ });
+ } else {
+ console.info("Unsupported browser message not found.");
+ }
+ } else {
+ console.info("Service worker not found in navigator.");
+ }
+ }, number * TIME_BETWEEN_INVOCATIONS);
}