简体   繁体   English

Android 上的 Microsoft Edge 中的 Web 推送通知不起作用

[英]Web push notifications in Microsoft Edge on Android not working

I am developing a site which is sending web push notifications and have so far tested this successfully with Chrome.我正在开发一个发送 web 推送通知的网站,并且到目前为止已经使用 Chrome 成功测试了它。 I am currently testing in other browsers including Microsoft Edge but I have run into some problems.我目前正在其他浏览器(包括 Microsoft Edge)中进行测试,但遇到了一些问题。 Any push notification I try to send only gets displayed with the text "This site was updated in the background".我尝试发送的任何推送通知只会显示文本“此站点已在后台更新”。 To isolate the problem I have managed to reproduce it using one of Googles own examples:为了隔离问题,我设法使用 Google 自己的示例之一重现了该问题:

https://developers.google.com/web/fundamentals/codelabs/push-notifications https://developers.google.com/web/fundamentals/codelabs/push-notifications

Step-by-step:一步步:

  1. Setup the example as described in the text (including using the correct public key from the companion site)按照文本中的描述设置示例(包括使用来自配套站点的正确公钥)
  2. Make the resulting site available to your Android phone, eg by using ngrok使生成的站点可用于您的 Android 电话,例如使用 ngrok
  3. Visit the site on using Edge on your phone, enable notifications and copy the subscription info.访问有关在手机上使用 Edge 的网站,启用通知并复制订阅信息。
  4. Use the subscription info to send a message from the companion site.使用订阅信息从配套站点发送消息。

Expected Result: A notification should appear with the data sent in the companion site.预期结果:伴随站点中发送的数据应出现一条通知。

Actual result: If site is in foreground, no notification appears If site is in background, a notification appears with the text "This site was updated in the background"实际结果:如果网站在前台,则不会显示任何通知如果网站在后台,则会显示一条通知,其中包含“此网站已在后台更新”的文本

Does anyone know if this is supposed to work on the mobile Edge browser and what could be the problem?有谁知道这是否应该在移动 Edge 浏览器上工作,可能是什么问题?

I am working on a solution since some weeks/months.几个星期/几个月以来,我一直在研究解决方案。 But without any result.但没有任何结果。

I wrote a webpage to test webpush and get some debug result, using this library:我写了一个网页来测试 webpush 并得到一些调试结果,使用这个库:
https://github.com/web-push-libs/web-push-php https://github.com/web-push-libs/web-push-php

Step by step:一步步:

  • From Javascript:来自 Javascript:
    • You have to create a service worker你必须创建一个服务工作者
    • You need to subscribe to an endpoint您需要订阅端点
    • You need to send the endpoint data to your server您需要将端点数据发送到您的服务器

And now the first anomaly :现在是第一个异常
Edge should give you a link like this (created on Edge for Windows): Edge 应该会给你一个这样的链接(在 Edge for Windows 上创建):

https://par02p.notify.windows.com/w/?token=BQYAAADYEvwVC+0moKngTpL9/XDZEynRAIYReS0el5m9zff+SBQKeHiQBNEh7rK7RJqyHkNUMw58nEfK6oUpkHTPXZhy1G3z9DS33SKtCM0WUzlCEE/AM0bbysCnmbUzwvlskhobPJSUF63tjsePeDvTmyA+Oi88akIGdrCr+102eR2BbWAZNeW+o86nIfM0zoVYS5pHnw0MwHg/k06tQBLPfxQNEKLYZpD8Qtv+dLnFY5BNzLIw3rEus/eeoKczDNsDetRNlF251GvJoFr1MFwtH8E+s5JAMWNL9oC71KIYqQoRmKSh4D10YneyJjiQDQGwDxCKCB7pBS40RErdkfN3Edeb

But instead you will receive a link like this:但是您会收到这样的链接:

https://fcm.googleapis.com/fcm/send/cGi0NgjCSa4:APA91bG9nWfn6UKevtmQjMdzSnleKGLnz4XPx-pfISfCT8ypWwUsfsiSiOwpd91-S-u3D_u3c2M1VVxZapS8StQHhH_asqDwseiTLKusw-5ARQ2siFwVlHnz6txZvJRtMoCVSk1U0_3U

So, even if it is a Microsoft product, you get a Google link.因此,即使它是 Microsoft 产品,您也会获得 Google 链接。

Step by step:一步步:

  • From PHP Server来自 PHP 服务器
    • Create valid VAPID codes创建有效的 VAPID 代码
    • Send the message to the endpoint server将消息发送到端点服务器
    • Check if the server has accepted the message检查服务器是否接受了消息
  • From the webpage从网页
    • Wait for push notification等待推送通知

And now the second anomaly :现在是第二个异常
The Google server is accepting the message sent and will forward it to the webpage. Google 服务器正在接受发送的消息并将其转发到网页。 Unfortunately the message is empty!不幸的是,消息是空的! 控制台日志 You can play around with different settings (without paddings, aesgcm encryption, different payloads), the result is always the same.您可以尝试不同的设置(没有填充、aesgcm 加密、不同的有效负载),结果总是一样的。

So, why does it not work?那么,为什么它不起作用?
1- Edge for Android is still (december 2020) using chromium 77.0.3865.116 from summer 2019 1- Android 的边缘仍然(2020 年 12 月)使用 2019 年夏季的 chromium 77.0.3865.116
2- Microsoft is redirecting requests to Google servers, instead of Microsoft servers 2- Microsoft 将请求重定向到 Google 服务器,而不是 Microsoft 服务器
3- Google FCM is sending an empty message (even if the payload was accepted successfully). 3- Google FCM 正在发送一条空消息(即使已成功接受有效负载)。

Many issues at the same time.很多问题同时发生。
Maybe Chromium 77 was still not able to subscribe correctly for web push notifications.也许 Chromium 77 仍然无法正确订阅 web 推送通知。
Maybe Google is blocking all Edge requests or removes all payloads as they don't want promote Edge as browser.也许谷歌正在阻止所有 Edge 请求或删除所有有效负载,因为他们不想将 Edge 提升为浏览器。

Hope Microsoft will give some more info about this (Tech-Community: https://techcommunity.microsoft.com/t5/discussions/web-push-notification-bug-edge-for-android/mp/1774677 )希望微软能提供更多相关信息(技术社区: https://techcommunity.microsoft.com/t5/discussions/web-push-notification-bug-edge-for-android/mp/1774677

Also because PWA doesn't work like expected if Edge is the default browser on Android:此外,如果 Edge 是 Android 上的默认浏览器,PWA 无法按预期工作:
https://github.com/pwa-builder/PWABuilder/issues/1274 https://github.com/pwa-builder/PWABuilder/issues/1274

With the update of today (Sept. 2021), it works also on Edge for Android. It use the chromium 93.随着今天(2021 年 9 月)的更新,它也适用于 Android 的 Edge。它使用铬 93。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM