fix(ext): v0.5.8 false positive zombie socket disconnect bug resolve (timestamp replace setTimeout)
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
*/
|
||||
|
||||
export function generateApprovalObserverScript(_port: number): string {
|
||||
// Port is hardcoded as fallback, but renderer also reads ag-bridge-ports.json for multi-bridge
|
||||
return `
|
||||
// Port is hardcoded as fallback, but renderer also reads ag-bridge-ports.json for multi-bridge
|
||||
return `
|
||||
// ── Gravity Bridge v3: Approval Observer (deep DOM traversal — iframes, webviews, shadow DOMs) ──
|
||||
(function(){
|
||||
'use strict';
|
||||
@@ -217,20 +217,36 @@ export function generateApprovalObserverScript(_port: number): string {
|
||||
}
|
||||
|
||||
function discoverPort(cb){
|
||||
log('Trying hardcoded port '+HARDCODED_PORT+'...');
|
||||
tryPingAsync(HARDCODED_PORT).then(function(ok){
|
||||
if(ok){log('Port discovered (hardcoded): '+HARDCODED_PORT);cb(HARDCODED_PORT);return;}
|
||||
log('Hardcoded port failed, retrying with backoff...');
|
||||
|
||||
var attempts=0;
|
||||
var timer=setInterval(function(){
|
||||
attempts++;
|
||||
if(attempts>60){clearInterval(timer);log('Port discovery timeout after 2min');return;}
|
||||
tryPingAsync(HARDCODED_PORT).then(function(ok2){
|
||||
if(ok2){clearInterval(timer);log('Port discovered (retry #'+attempts+'): '+HARDCODED_PORT);cb(HARDCODED_PORT);}
|
||||
log('Waiting for Gravity Bridge status bar item to appear in DOM...');
|
||||
var attempts=0;
|
||||
var timer=setInterval(function(){
|
||||
attempts++;
|
||||
// Search for our specific port injected by the extension host for THIS window.
|
||||
// This prevents cross-project leakage by ignoring the hardcoded port from the shared HTML file.
|
||||
var items = document.querySelectorAll('[aria-label^="Gravity Bridge Control"], [title^="Gravity Bridge Control"]');
|
||||
if (items.length > 0) {
|
||||
var text = items[0].getAttribute('aria-label') || items[0].getAttribute('title') || '';
|
||||
var m = text.match(/port:(\\d+)/);
|
||||
if (m && m[1]) {
|
||||
var domPort = parseInt(m[1], 10);
|
||||
log('Determined correct window port from DOM: ' + domPort);
|
||||
clearInterval(timer);
|
||||
tryPingAsync(domPort).then(function(ok){
|
||||
if(ok){ cb(domPort); } else { log('Ping failed on DOM port ' + domPort); cb(HARDCODED_PORT); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback if status bar never appears
|
||||
if(attempts>150){
|
||||
clearInterval(timer);
|
||||
log('DOM discovery timeout after 5 min. Falling back to hardcoded.');
|
||||
tryPingAsync(HARDCODED_PORT).then(function(ok){
|
||||
if(ok){ cb(HARDCODED_PORT); }
|
||||
});
|
||||
},2000);
|
||||
});
|
||||
}
|
||||
},2000);
|
||||
}
|
||||
|
||||
discoverPort(function(port){
|
||||
|
||||
Reference in New Issue
Block a user