Adding Vuetify dependency to my project gives SecurityError: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet

Adding Vuetify dependency to my project gives SecurityError: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet

我想实现一个在新 window 中打开 CKEditor 组件的 Vue 应用程序。我使用 this post. I have also implemented a Codesandbox 显示工作示例的方法成功实现了它。

现在,当我使用 vue add vuetify 添加 vuetify 的依赖项时,CKEditor window 缺少 CSS 并且浏览器控制台(Chrome 或 Firefox)正在显示CORS 错误:

[Vue warn]: Error in callback for watcher "open": "SecurityError: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet"

(不幸的是,我无法将 vuetify 依赖项正确添加到我的 Codesandbox - 添加依赖项后,我最终遇到编译错误。)

经过进一步调查,发现 Vuetify 插入了两个对外部样式表的引用:

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">

在 window.open() 之后调用函数 copyStyles() 将所有 CSS 转移到新的 window。但是,由于两个外部 CSS 引用,document.stylesheet.cssrules.get() 失败并出现 CORS 错误,并且由于这两个引用位于所有样式表的开头,copyStyles() 函数终止并且新的 window 缺少所有样式表。

为了避免这种情况并在新 window 中包含其他样式表,在函数 copyStyles() 中使用一个简单的 try/catch 就足够了。