visual-studio-code - 可以在 VS Code Webview API 中使用 cookie 吗?
问题描述
我正在尝试使用 Webview API 在 VS Code 中集成一个 Web 应用程序。我有这种错误,提到无法读取 cookie:
error: any
:
DOMException: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs. at HttpXsrfCookieExtractor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfCookieExtractor.getToken (http://127.0.0.1:8585/vendor.js:7688:37) at ApiXsrfInterceptor.push../src/app/lib/atlasmap-data-mapper/services/api-xsrf-interceptor.service.ts.ApiXsrfInterceptor.intercept (http://127.0.0.1:8585/main.js:8780:45) at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://127.0.0.1:8585/vendor.js:7129:33) at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http://127.0.0.1:8585/vendor.js:7720:25) at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://127.0.0.1:8585/vendor.js:7129:33) at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http://127.0.0.1:8585/vendor.js:7764:27) at MergeMapSubscriber.project (http://127.0.0.1:8585/vendor.js:6969:184) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://127.0.0.1:8585/vendor.js:106781:27) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (http://127.0.0.1:8585/vendor.js:106771:18) at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (http://127.0.0.1:8585/vendor.js:101228:18)
code
:
18
message
:
"Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs."
name
:
"SecurityError"
stack
:
"Error: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs.↵ at HttpXsrfCookieExtractor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfCookieExtractor.getToken (http://127.0.0.1:8585/vendor.js:7688:37)↵ at ApiXsrfInterceptor.push../src/app/lib/atlasmap-data-mapper/services/api-xsrf-interceptor.service.ts.ApiXsrfInterceptor.intercept (http://127.0.0.1:8585/main.js:8780:45)↵ at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://127.0.0.1:8585/vendor.js:7129:33)↵ at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http://127.0.0.1:8585/vendor.js:7720:25)↵ at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http://127.0.0.1:8585/vendor.js:7129:33)↵ at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http://127.0.0.1:8585/vendor.js:7764:27)↵ at MergeMapSubscriber.project (http://127.0.0.1:8585/vendor.js:6969:184)↵ at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (http://127.0.0.1:8585/vendor.js:106781:27)↵ at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (http://127.0.0.1:8585/vendor.js:106771:18)↵ at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (http://127.0.0.1:8585/vendor.js:101228:18)"
它是 VS Code Webview API 的限制吗?是要配置的吗?
作为参考,我尝试集成的项目是https://github.com/atlasmap/atlasmap,有一个带有“当前状态”的PR(又名不工作)
解决方案
VSCode webview API 也禁用了对 localstorage 和 cookie 的评估,这就是您出错的原因。
推荐阅读
- flutter - 如何在 Flutter 中裁剪图像?
- swiftui - Swiftui,点击时如何更改视图的阴影半径
- python - 在 django 中使用 sync_to_async 时如何运行协程函数?
- windows - 有什么方法可以控制类似于 LoadLibraryEx 的 LoadTypeLibEx 的目录顺序?
- python - 浏览一个 .gz 文件并使用 Python 复制以“trex”开头的句子
- android - 切换到深色模式时,Android Studio 将黑色变为白色
- javascript - 块内的函数声明
- sql - 在更新中按顺序编号记录
- c# - 可以对 ListView 的每个项目应用不同的透明度吗?
- mips - 在 mips 中使用过程调用将字符串写入另一个字符串