Safari:“因为它是跨域请求,所以阻止https://...要求提供凭据".更新到Angular 8之后 [英] Safari: "Blocked https://... from asking for credentials because it is a cross-origin request." after updating to Angular 8

查看:333
本文介绍了Safari:“因为它是跨域请求,所以阻止https://...要求提供凭据".更新到Angular 8之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已使用基本身份验证保护了Angular网络应用的安全. 将我们的应用程序从Angular 7更新到到8.0 后,不再要求我们在Safari中提供凭据,并且控制台中出现以下错误:

We have secured our Angular web app with Basic Auth. After updating our app from Angular 7 to 8.0, we are no longer asked for the credentials in Safari and the following errors appear in the console:

[Error] Blocked https://*/runtime-es2015.4f263ec725bc7710f1f5.js from asking for credentials because it is a cross-origin request.
[Error] Blocked https://*/main-es2015.6fa442dd5c5a204f47da.js from asking for credentials because it is a cross-origin request.
[Error] Blocked https://*/polyfills-es2015.fd951ae1d7572efa3bc6.js from asking for credentials because it is a cross-origin request.

在Firefox和Chrome中,该应用仍然可以正常运行. Safari版本为12.1.1.

In Firefox and Chrome the app still runs without problems. Safari version is 12.1.1.

有人知道Safari是什么问题吗?

Does anyone have any idea what the problem with Safari is?

推荐答案

自angular/cli 8.1(PR)起,ng build命令就有一个 crossOrigin 选项(

Since angular/cli 8.1 (PR) there is a option crossOrigin for the ng build command (documentation). Possible values are: none | anonymous | use-credentials (defaults to none).

使用此选项将更改index.html中的脚本标签以添加crossorigin属性.

Using this option will alter the script tags in index.html to add the crossorigin attribute.

您可以使用以下临时方式进行构建: ng build --crossOrigin=anonymous

You can either use this temporary for a build using: ng build --crossOrigin=anonymous

或在architect.build.options下的angular.json中使用该选项:

Or use the option in your angular.json under architect.build.options:

"architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "crossOrigin": "anonymous", // <-- set value here
        // other options

这篇关于Safari:“因为它是跨域请求,所以阻止https://...要求提供凭据".更新到Angular 8之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆