You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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
    • 重新打开VS Code测试
  • 重置VS Code全局设置:打开命令面板(Ctrl+Shift+P / Cmd+Shift+P),执行Preferences: Reset Settings,重置后再尝试预览
  • 升级VS Code到最新版:旧版本可能存在已知的webview服务worker兼容bug,更新到稳定版可修复部分问题

内容的提问来源于stack exchange,提问作者Keshav Mittal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:44:50