"Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context .." with PWA on iOS

"Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context .." with PWA on iOS

我目前在 Vue 3 中实现 Web Share API(2 级)时遇到问题,使用它来 iOS 14 上的 share/download 图片(作为实验性功能)和 iOS 15 在渐进式 Web 应用程序上下文中。

观察:当应用程序直接在浏览器中 运行 时(不在 PWA 上下文中——这是一个本地 PWA,可通过 iOS 上的主屏幕书签访问),它也按预期工作没有任何错误。

作为 PWA 安装,但是,第一次共享按预期工作,但在保存图像后,它拒绝触发带有错误消息的本机共享机制(请注意它总是工作一次):

Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

navigator.share直接点击事件触发,资源也提前加载分享

它似乎在 Android 设备上正常工作,但在 IOS

这似乎(又)是旧 WebKit 错误的回归。过去,这被反复报告,例如WebKit bug #216913 or WebKit bug #218156

report this to the WebKit team, providing the exact iOS and Safari version you encountered this on. Feel free to use this demo app 我已经准备好了,它是一个可安装的 PWA 并展示了 Web 共享 API。