【发布时间】:2020-06-18 14:57:31
【问题描述】:
我已经构建了一个带有 Angular 前端的 ASP.NET Core 应用程序。 Angular 应用程序具有 @angular/pwa 节点包设置,因此它是一个渐进式 Web 应用程序,可以安装在 android/windows 上,其行为类似于原生应用程序。
我已经使用 Microsoft.AspNetCore.Identity 设置了外部登录(Microsoft、Google、Facebook、Twitter)。从我的 Angular 应用程序中,我打开了一个到外部登录页面的弹出窗口:
this.authWindow = window.open(`${this.baseUrl}/web/v2/Account/${this.action}/${medium}/${this.platform}`, null, 'width=600,height=400');
弹出窗口的 url 路由到我有 return Challenge() 调用的 ASP.NET Core 端点,它返回特定外部提供商(Microsoft、Google、Facebook、Twitter)的登录页面。
在 Windows 上的 Chrome 中,单击触发 window.open() 的按钮以打开带有外部登录页面的窗口。成功登录后,您将被重定向到回调页面,这是一个剃须刀页面,它向包含 Angular 应用程序的主窗口发送消息。正在处理消息并正在关闭弹出窗口。
问题
当我在 Android 版 Chrome 上使用该网站时,我可以将 PWA 安装为应用程序,这会在我的 android 主页上添加一个图标。当我打开 PWA 并单击按钮打开弹出窗口时,弹出窗口正在我的 PWA 的弹出窗口中打开,所以没有问题。
当我在 Android 上打开 Chrome 并访问该网站时,在安装 PWA 的情况下,window.open() 调用不会打开 Chrome 浏览器的弹出窗口,而是尝试打开 Progressive Web App 的弹出窗口。由于是这种情况,PWA 内的弹出窗口无法在 Chrome 中通知网站登录成功(呃……)。
但是当没有安装 PWA 时,window.open() 可以正常工作并在 Chrome 本身中打开弹出窗口。
所以底线是,PWA 安装在 android 上。我希望能够在 Chrome 中从我的网站调用 window.open(),并让它在 Chrome 浏览器而不是 PWA 中打开弹出窗口。
我尝试过的事情
-
修改 ngsw-config.json
{ ..., “导航网址”:[ "/", "!//.", "!//__", "!//__/", "!/web/v2/Account/connect//", "!/web/v2/Account/add//**" ] }
-
用
target='_system'打开窗口this.authWindow = window.open(
${this.baseUrl}/web/v2/Account/${this.action}/${medium}/${this.platform}, '_system', 'width=600,height=400'); -
用
target='_blank'打开窗口this.authWindow = window.open(
${this.baseUrl}/web/v2/Account/${this.action}/${medium}/${this.platform}, '_blank', 'width=600,height=400'); -
用
target='_blank'打开窗口,不用baseUrl,只是一个绝对路径。this.authWindow = window.open(
/web/v2/Account/${this.action}/${medium}/${this.platform}, '_blank', 'width=600,height=400'); -
使用 ngsw-bypass
this.authWindow = window.open(
/web/v2/Account/${this.action}/${medium}/${this.platform}?ngsw-bypass=true, '_blank', 'width=600,height=400');
但所有技巧似乎都表现相同,并且仍然在 PWA 中打开窗口。
【问题讨论】:
-
有兴趣的朋友,点赞following issue
标签: progressive-web-apps window.open