VS Code图片预览失败:Webview加载及Service Worker注册报错
VS Code预览图片时Service Worker注册错误的解决办法
Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.
- 重启VS Code:临时进程异常引发的状态错误,重启后通常能自动恢复
- 排查并重置图片预览扩展:找到负责图片预览的扩展(如Image Preview),先禁用再重启VS Code,之后重新启用;若无效可卸载后重装
- 清理VS Code缓存:
- 关闭VS Code
- 删除对应缓存目录:
- Windows:
%APPDATA%\Code\Cache、%APPDATA%\Code\CachedData - macOS:
$HOME/Library/Application Support/Code/Cache、$HOME/Library/Application Support/Code/CachedData - Linux:
$HOME/.config/Code/Cache、$HOME/.config/Code/CachedData
- Windows:
- 重新打开VS Code测试
- 重置VS Code全局设置:打开命令面板(Ctrl+Shift+P / Cmd+Shift+P),执行
Preferences: Reset Settings,重置后再尝试预览 - 升级VS Code到最新版:旧版本可能存在已知的webview服务worker兼容bug,更新到稳定版可修复部分问题
内容的提问来源于stack exchange,提问作者Keshav Mittal
相关产品推荐
相关产品推荐

