{"record":{"id":"b38c6a407d1328c3","repo":"BigPizzaV3/CodexPlusPlus","slug":"codex-b38c6a","errorCode":null,"errorMessage":"Codex++ 会话接口尚未连接，请稍后点击刷新","messagePattern":"Codex\\+\\+ 会话接口尚未连接，请稍后点击刷新","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"tools/conversation-canvas/public/canvas.user.js","lineNumber":1141,"sourceCode":"      const needle=normalize(message.text).slice(0,100);\n      if(needle.length>=15){\n        const candidates=[...document.querySelectorAll('p,pre,[data-message-id],article')].filter(e=>!host.contains(e)&&normalize(e.textContent).includes(needle));\n        const leaves=candidates.filter(e=>!candidates.some(other=>other!==e&&e.contains(other)));\n        if(leaves.length===1)target=leaves[0];\n      }\n    }\n    if(!target){$('jump-status').textContent=({revealed:'已展开所属轮次，但该消息仍被折叠或未显示。可先查看对应原文。',unavailable:'当前页面的历史定位尚未就绪。可先查看对应原文。','missing-turn':'该来源缺少轮次信息。可先查看对应原文。',failed:'原聊天轮次展开失败。可先查看对应原文。'})[navigationState];return;}\n    closePanel();\n    target.scrollIntoView({behavior:'smooth',block:'center'});\n    target.animate([{outline:'2px solid #888',backgroundColor:'#8882'},{outline:'2px solid transparent',backgroundColor:'transparent'}],{duration:2000});\n    $('jump-status').textContent='正在定位原聊天消息…';\n    setTimeout(()=>{if(disposed||currentId()!==threadId)return;const r=target.getBoundingClientRect();$('jump-status').textContent=target.isConnected&&r.height>0&&r.bottom>0&&r.top<innerHeight?'已定位并高亮原聊天消息。':'消息已找到，滚动尚未完成。';},700);\n  }\n  async function readCanvasSource(id,signal,progress){\n    if(!nativeReadTasks.has(id)){\n      let result;\n      try{\n        if(typeof window.__codexSessionDeleteBridge!=='function')throw Error('Codex++ 会话接口尚未连接，请稍后点击刷新');\n        let timer;\n        try{result=await Promise.race([window.__codexSessionDeleteBridge('/session/export',{session_id:id}),new Promise((_,reject)=>{timer=setTimeout(()=>reject(Error('会话读取超时，请重试')),15000);})]);}\n        finally{clearTimeout(timer);}\n      }catch(error){if(!isExportSizeError(error.message))throw error;result={message:error.message};}\n      if(result?.status==='ok')return result;\n      if(!isExportSizeError(result?.message))throw Error(result?.message||'Codex++ 会话读取失败');\n      nativeReadTasks.add(id);\n    }\n    signal.throwIfAborted();progress('会话较大，正在改用原生分页读取…');\n    const {manager}=await nativeContext(id);\n    const messages=await readNativeHistory((method,params)=>manager.sendRequest(method,params,{priority:'background',timeoutMs:15000}),id,historyCache,progress,signal);\n    const signature=[];for(const message of messages){signal.throwIfAborted();signature.push(message.id+':'+await messageDigest(message));}\n    return {status:'ok',kind:'canvas-messages',session_id:id,messages,content:signature.join('|')};\n  }\n  async function sync(force=false){\n    const id=currentId();\n    if(!id){historyAbort?.abort();requestSequence++;active='';pending=null;data=null;revision='';taskCanvas.context('');$('pending-tray').replaceChildren();$('transcript').replaceChildren();$('details').hidden=true;status('请打开具体任务。');return;}\n    if(id!==active){","sourceCodeStart":1123,"sourceCodeEnd":1159,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/tools/conversation-canvas/public/canvas.user.js#L1123-L1159","documentation":"readCanvasSource in the userscript first tries the injected Codex++ bridge window.__codexSessionDeleteBridge to export a session. If that global function does not exist (the Codex++ extension has not injected its bridge into the page yet), it throws this message telling the user the session API isn't connected and to click refresh later.","triggerScenarios":"Calling readCanvasSource (e.g. via canvas load/refresh) while window.__codexSessionDeleteBridge is undefined or not a function — the userscript ran before the Codex++ bridge was injected, or the bridge was never injected on this page/frame.","commonSituations":"Page just loaded and canvas script executes before the extension content script; Codex++ extension disabled/not installed; bridge injection failed after a Codex web app update changed the injection point; canvas opened in an iframe without the bridge.","solutions":["Wait a moment and click the canvas refresh button so readCanvasSource retries after the bridge is injected","Verify the Codex++ extension is installed and enabled for the Codex site","Reload the Codex page to force bridge re-injection","Update the userscript/extension to matching versions if Codex UI changed"],"exampleFix":"// before\nif(typeof window.__codexSessionDeleteBridge!=='function')throw Error('Codex++ 会话接口尚未连接，请稍后点击刷新');\n// after\nif(typeof window.__codexSessionDeleteBridge!=='function'){await new Promise(r=>setTimeout(r,1500));}\nif(typeof window.__codexSessionDeleteBridge!=='function')throw Error('Codex++ 会话接口尚未连接，请稍后点击刷新');","handlingStrategy":"retry","validationCode":"function bridgeReady(){return typeof window.__codexSessionDeleteBridge==='function';}","typeGuard":"const hasBridge = (w)=>typeof w!=='undefined' && typeof w.__codexSessionDeleteBridge==='function';","tryCatchPattern":"try{await readCanvasSource(id,signal,progress);}catch(e){if(e.message.includes('尚未连接')){await new Promise(r=>setTimeout(r,1500));/* retry once */}else throw e;}","preventionTips":["Delay canvas init until window load plus a short grace period","Poll for the bridge global before enabling session-dependent UI","Keep extension and userscript versions in sync"],"tags":["userscript","bridge","session-export"],"backgroundTag":"missing-dependency","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}