简睿 (@jianrui) 在 Claude Code 扩展在 Cursor / Kiro 中出现 Cannot read properties of undefined (reading 'trim') 的临时修复方法 中发帖
最近在 Cursor / Kiro 里使用 Claude Code 扩展时,遇到一个 webview 崩溃问题,表现为:
Something went wrong
Re-launch the extension to continue.
Error rendering content: Cannot read properties of undefined (reading 'trim')
我排查了一下,发现问题出在扩展打包后的 webview/index.js 里,有几处代码在调用 .trim() 前没有先判断字段是否存在,所以当数据里某个字段是 undefined 时,整个 webview 会直接崩掉。
根本原因
主要有两类问题:
1. 文本内容未判空就调用 .trim()
原逻辑类似这样:
function eB1($){return!$.text.trim()||$....