fix(observer): ensure inline script injection before </body> for Electron execution + add BEACON diagnostic ping
- html-patcher: relocate inline script from after </html> to before </body> - html-patcher: clean up duplicate </html> tags from previous bad insertions - observer-script: add immediate BEACON fetch to /ping on script load - http-bridge: add diagnostic request logging for non-polling endpoints - devlog 003: crash recovery session notes
This commit is contained in:
@@ -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 </body> for Electron execution
|
||||
const inlineMarkerStart = '<!-- AG SDK INLINE [variet-gravity-bridge] -->';
|
||||
const inlineMarkerEnd = '<!-- /AG SDK INLINE [variet-gravity-bridge] -->';
|
||||
const inlineBlock = `${inlineMarkerStart}\n<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}`;
|
||||
|
||||
if (html.includes(inlineMarkerStart)) {
|
||||
// Remove existing block (may be in wrong position, e.g. after </body>)
|
||||
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<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}`);
|
||||
logToFile(`[OBSERVER] ${spec.name} inline script UPDATED`);
|
||||
html = html.replace(re, '');
|
||||
// Remove duplicate </html> if present (from previous bad insertions)
|
||||
html = html.replace(/(<\/html>\s*){2,}/gi, '</html>\n');
|
||||
logToFile(`[OBSERVER] ${spec.name} removed old inline script block`);
|
||||
}
|
||||
// Insert BEFORE </body> (not </html>) to ensure Electron executes it
|
||||
if (html.includes('</body>')) {
|
||||
html = html.replace('</body>',
|
||||
`\n${inlineBlock}\n</body>`);
|
||||
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </body>`);
|
||||
} else {
|
||||
// Fallback: insert before </html>
|
||||
html = html.replace('</html>',
|
||||
`\n${inlineMarkerStart}\n<script>\n${combinedScript}\n</script>\n${inlineMarkerEnd}\n</html>`);
|
||||
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED`);
|
||||
`\n${inlineBlock}\n</html>`);
|
||||
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </html> (fallback)`);
|
||||
}
|
||||
// SAFETY: Final validation before write
|
||||
if (html.length < 500 || !html.includes('<!DOCTYPE html>') || !html.includes(spec.requiredMarker)) {
|
||||
|
||||
@@ -79,6 +79,11 @@ export function startHttpBridge(ctx: HttpBridgeContext, sdk: any): Promise<numbe
|
||||
|
||||
const url = new URL(req.url, `http://127.0.0.1`);
|
||||
|
||||
// DIAGNOSTIC: log ALL requests (except noisy polling endpoints)
|
||||
if (!['/trigger-click', '/deep-inspect-trigger'].includes(url.pathname)) {
|
||||
ctx.logToFile(`[HTTP-REQ] ${req.method} ${url.pathname}`);
|
||||
}
|
||||
|
||||
// POST /pending — renderer reports a detected approval button
|
||||
if (req.method === 'POST' && url.pathname === '/pending') {
|
||||
_handlePending(req, res, ctx);
|
||||
|
||||
@@ -12,6 +12,13 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
function log(m){console.log('[GB Observer] '+m);}
|
||||
log('v8 Script loaded — Full-DOM AG Native Parser');
|
||||
|
||||
// DIAGNOSTIC BEACON: immediate POST to confirm script execution in renderer
|
||||
try {
|
||||
fetch('http://127.0.0.1:${_port}/ping?beacon=1&t='+Date.now())
|
||||
.then(function(r){log('BEACON ping OK: '+r.status);})
|
||||
.catch(function(e){log('BEACON ping FAIL: '+e.message);});
|
||||
} catch(e){ log('BEACON error: '+e); }
|
||||
|
||||
// React-Compatible Synthetic Clicker
|
||||
function dispatchReactClick(el){
|
||||
if (!el) return;
|
||||
|
||||
Reference in New Issue
Block a user