From 87435b1e13ccf58464c929723c8f9cc5e6276567 Mon Sep 17 00:00:00 2001 From: Simon Kern Date: Fri, 12 Nov 2021 10:46:52 +0100 Subject: [PATCH 1/6] webpush add Edge --- push_notifications/conf/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push_notifications/conf/app.py b/push_notifications/conf/app.py index 6f0f027f..607edfa7 100644 --- a/push_notifications/conf/app.py +++ b/push_notifications/conf/app.py @@ -231,7 +231,7 @@ def _validate_wp_config(self, application_id, application_config): application_config.setdefault("POST_URL", { "CHROME": "https://fcm.googleapis.com/fcm/send", "OPERA": "https://fcm.googleapis.com/fcm/send", - "EDGE": "https://wns2-par02p.notify.windows.com/w", + "EDGE": "https://cloud.notify.windows.com", "FIREFOX": "https://updates.push.services.mozilla.com/wpush/v2", }) From 4518ae38d550af6b69c88d041f8c24e22b59789e Mon Sep 17 00:00:00 2001 From: Simon Kern Date: Fri, 12 Nov 2021 11:00:19 +0100 Subject: [PATCH 2/6] webpush - add edge endpoint --- push_notifications/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push_notifications/settings.py b/push_notifications/settings.py index 0eefecce..ac9116cb 100644 --- a/push_notifications/settings.py +++ b/push_notifications/settings.py @@ -41,7 +41,7 @@ "CHROME": PUSH_NOTIFICATIONS_SETTINGS["FCM_POST_URL"], "OPERA": PUSH_NOTIFICATIONS_SETTINGS["FCM_POST_URL"], "FIREFOX": "https://updates.push.services.mozilla.com/wpush/v2", - "EDGE": "https://wns2-par02p.notify.windows.com/w", + "EDGE": "https://cloud.notify.windows.com", }) PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_PRIVATE_KEY", None) PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_CLAIMS", None) From 85acbbb6cd4da57f6123d05e061ca99f6cdbdca9 Mon Sep 17 00:00:00 2001 From: Simon Kern Date: Fri, 12 Nov 2021 11:12:21 +0100 Subject: [PATCH 3/6] change edge endpoint --- push_notifications/conf/app.py | 2 +- push_notifications/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/push_notifications/conf/app.py b/push_notifications/conf/app.py index 607edfa7..6f0f027f 100644 --- a/push_notifications/conf/app.py +++ b/push_notifications/conf/app.py @@ -231,7 +231,7 @@ def _validate_wp_config(self, application_id, application_config): application_config.setdefault("POST_URL", { "CHROME": "https://fcm.googleapis.com/fcm/send", "OPERA": "https://fcm.googleapis.com/fcm/send", - "EDGE": "https://cloud.notify.windows.com", + "EDGE": "https://wns2-par02p.notify.windows.com/w", "FIREFOX": "https://updates.push.services.mozilla.com/wpush/v2", }) diff --git a/push_notifications/settings.py b/push_notifications/settings.py index ac9116cb..0eefecce 100644 --- a/push_notifications/settings.py +++ b/push_notifications/settings.py @@ -41,7 +41,7 @@ "CHROME": PUSH_NOTIFICATIONS_SETTINGS["FCM_POST_URL"], "OPERA": PUSH_NOTIFICATIONS_SETTINGS["FCM_POST_URL"], "FIREFOX": "https://updates.push.services.mozilla.com/wpush/v2", - "EDGE": "https://cloud.notify.windows.com", + "EDGE": "https://wns2-par02p.notify.windows.com/w", }) PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_PRIVATE_KEY", None) PUSH_NOTIFICATIONS_SETTINGS.setdefault("WP_CLAIMS", None) From 9f7e8f6c4e933a4b04ed9b1f31f6b12bd34a1abf Mon Sep 17 00:00:00 2001 From: Simon Kern Date: Fri, 12 Nov 2021 11:20:03 +0100 Subject: [PATCH 4/6] update README Show another, easier approach to extract the browsername and browser version --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 63b12a66..071bfc82 100644 --- a/README.rst +++ b/README.rst @@ -211,8 +211,8 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY const browserversion = browser.version; return { - name: browsername, - version: browserversion + name: browsername, + version: browserversion } } // Otherwise fallback to the old method via userAgent From f2ada74313e091da0cb6fe1eb8daa764aaca5d14 Mon Sep 17 00:00:00 2001 From: Simon Kern Date: Thu, 30 Dec 2021 13:39:05 +0100 Subject: [PATCH 5/6] more robust handling ofh userAgentData Relevant userAgentData ist not always stored in navigator.userAgentData.brands[0] It is necessary to loop through all available navigator.userAgentData.brands and try to find the relevant entry. In case of Edge it is also necessary to ignore any matches regarding chrome... addresses #640 --- README.rst | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 071bfc82..647a76a4 100644 --- a/README.rst +++ b/README.rst @@ -194,28 +194,49 @@ For WNS, you need both the ``WNS_PACKAGE_SECURITY_KEY`` and the ``WNS_SECRET_KEY } return outputArray; } - function loadVersionBrowser (userAgent) { - // If userAgentData is available, use this for browser detection + + function loadVersionBrowser () { if ("userAgentData" in navigator) { // navigator.userAgentData is not available in // Firefox and Safari const uaData = navigator.userAgentData; - // Outputs of navigator.userAgentData.brands[0].brand are + // Outputs of navigator.userAgentData.brands[n].brand are e.g. // Chrome: 'Google Chrome' // Edge: 'Microsoft Edge' // Opera: 'Opera' - const browser = uaData.brands[0]; - const brandname = browser.brand; - // If there is a space within brandname, we only care about the right part - const browsername = brandname.substr(brandname.indexOf(' ')+1); - const browserversion = browser.version; - - return { - name: browsername, - version: browserversion + let browsername; + let browserversion; + let chromeVersion = null; + for (var i = 0; i < uaData.brands.length; i++) { + let brand = uaData.brands[i].brand; + browserversion = uaData.brands[i].version; + if (brand.match(/opera|chrome|edge|safari|firefox|msie|trident/i) !== null) { + // If we have a chrome match, save the match, but try to find another match + // E.g. Edge can also produce a false Chrome match. + if (brand.match(/chrome/i) !== null) { + chromeVersion = browserversion; + } + // If this is not a chrome match return immediately + else { + browsername = brand.substr(brand.indexOf(' ')+1); + return { + name: browsername, + version: browserversion + } + } + } + } + // No non-Chrome match was found. If we have a chrome match, return it. + if (chromeVersion !== null) { + return { + name: "chrome", + version: chromeVersion + } } } - // Otherwise fallback to the old method via userAgent + // If no userAgentData is not present, or if no match via userAgentData was found, + // try to extract the browser name and version from userAgent + const userAgent = navigator.userAgent; var ua = userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; if (/trident/i.test(M[1])) { tem = /\brv[ :]+(\d+)/g.exec(ua) || []; From c88d5fed9921dc5ec92754c31abb06ae7c007eba Mon Sep 17 00:00:00 2001 From: Simon Kern Date: Thu, 30 Dec 2021 14:23:13 +0100 Subject: [PATCH 6/6] Fix WebpushDeviceAdmin Field "device_id" is not available for WebPushDevices. Instead add "browser" to ListView and "registration_id" to search_fields --- push_notifications/admin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/push_notifications/admin.py b/push_notifications/admin.py index 8645882c..7c6d1767 100644 --- a/push_notifications/admin.py +++ b/push_notifications/admin.py @@ -133,7 +133,17 @@ class GCMDeviceAdmin(DeviceAdmin): list_filter = ("active", "cloud_message_type") +class WebPushDeviceAdmin(DeviceAdmin): + list_display = ("__str__", "browser", "user", "active", "date_created") + list_filter = ("active", "browser") + + if hasattr(User, "USERNAME_FIELD"): + search_fields = ("name", "registration_id", "user__%s" % (User.USERNAME_FIELD)) + else: + search_fields = ("name", "registration_id") + + admin.site.register(APNSDevice, DeviceAdmin) admin.site.register(GCMDevice, GCMDeviceAdmin) admin.site.register(WNSDevice, DeviceAdmin) -admin.site.register(WebPushDevice, DeviceAdmin) +admin.site.register(WebPushDevice, WebPushDeviceAdmin)