diff --git a/docs/devlog/entries/20260412-003.md b/docs/devlog/entries/20260412-003.md new file mode 100644 index 0000000..c077d2a --- /dev/null +++ b/docs/devlog/entries/20260412-003.md @@ -0,0 +1,28 @@ +# Observer v8 Electron 실행 보장 + 진단 beacon 추가 + +- **시간**: 2026-04-12 21:00~21:30 +- **Commit**: (이전 세션 크래시 복구 커밋) + +## 배경 +- 이전 세션(f9491880)에서 Observer v8이 렌더러에서 실행되지 않는 문제 디버깅 중 크래시 발생 +- deep-inspect 엔드포인트가 `timeout` 반환 — 인라인 스크립트가 Electron에서 실행 안 됨 +- 원인: 인라인 스크립트가 `` 뒤에 삽입되어 Electron이 무시하는 것으로 추정 + +## 변경 사항 + +### observer-script.ts +- DIAGNOSTIC BEACON 추가: 스크립트 로드 즉시 `/ping?beacon=1`으로 fetch → 실행 여부 확인 가능 + +### html-patcher.ts +- 인라인 스크립트 삽입 위치를 `` 앞에서 **`` 앞**으로 변경 +- 기존 잘못된 위치의 인라인 블록을 제거 후 재삽입하는 로직 추가 +- 이전 패칭에서 발생한 중복 `` 태그 정리 로직 추가 + +### http-bridge.ts +- 진단용 HTTP 요청 로깅 추가 (폴링 엔드포인트 제외) + +## 미완료 +- AG 리로드 후 observer 작동 확인 (beacon ping 수신 확인) +- deep-inspect로 실제 DOM 구조 캡처 +- observer-script 셀렉터 미세조정 (bot-color 제거, MarkdownRenderer 타겟팅) +- Discord 릴레이 E2E 검증 diff --git a/extension/src/html-patcher.ts b/extension/src/html-patcher.ts index 9b84c2c..e749078 100644 --- a/extension/src/html-patcher.ts +++ b/extension/src/html-patcher.ts @@ -275,23 +275,33 @@ function _patchHtmlFiles(scriptDir: string, combinedScript: string, logToFile: ( logToFile(`[OBSERVER] removed external script tag from ${spec.name}`); } - // Insert or update inline script + // Insert or update inline script — MUST be BEFORE for Electron execution const inlineMarkerStart = ''; const inlineMarkerEnd = ''; + const inlineBlock = `${inlineMarkerStart}\n\n${inlineMarkerEnd}`; if (html.includes(inlineMarkerStart)) { + // Remove existing block (may be in wrong position, e.g. after ) const re = new RegExp( - inlineMarkerStart.replace(/[[\]]/g, '\\$&') + + '\\n?' + inlineMarkerStart.replace(/[[\]]/g, '\\$&') + '[\\s\\S]*?' + - inlineMarkerEnd.replace(/[[\]]/g, '\\$&') + inlineMarkerEnd.replace(/[[\]]/g, '\\$&') + '\\n?' ); - html = html.replace(re, - `${inlineMarkerStart}\n\n${inlineMarkerEnd}`); - logToFile(`[OBSERVER] ${spec.name} inline script UPDATED`); + html = html.replace(re, ''); + // Remove duplicate if present (from previous bad insertions) + html = html.replace(/(<\/html>\s*){2,}/gi, '\n'); + logToFile(`[OBSERVER] ${spec.name} removed old inline script block`); + } + // Insert BEFORE (not ) to ensure Electron executes it + if (html.includes('')) { + html = html.replace('', + `\n${inlineBlock}\n`); + logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before `); } else { + // Fallback: insert before html = html.replace('', - `\n${inlineMarkerStart}\n\n${inlineMarkerEnd}\n`); - logToFile(`[OBSERVER] ${spec.name} inline script INSERTED`); + `\n${inlineBlock}\n`); + logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before (fallback)`); } // SAFETY: Final validation before write if (html.length < 500 || !html.includes('') || !html.includes(spec.requiredMarker)) { diff --git a/extension/src/http-bridge.ts b/extension/src/http-bridge.ts index dc99a9b..154b72b 100644 --- a/extension/src/http-bridge.ts +++ b/extension/src/http-bridge.ts @@ -79,6 +79,11 @@ export function startHttpBridge(ctx: HttpBridgeContext, sdk: any): Promise