test: the browser tests try Chrome's first connection again while it starts (CI run 416)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 8m27s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m18s

Chrome writes DevToolsActivePort a moment before it accepts connections;
run 416 connected in that gap (ECONNREFUSED, then "DevTools listening") and
failed before any page loaded. Both browser tests now retry a refused first
connection for up to ten seconds; any other error still fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-02 15:12:22 -03:00
parent cc460c6e0c
commit dea8036b73
2 changed files with 17 additions and 2 deletions

View File

@@ -46,8 +46,17 @@ class Page {
try{
let port;
await waitFor(async()=>{try{port=Number((await readFile(profile+'/DevToolsActivePort','utf8')).split('\n')[0]);return true;}catch{return false;}},'Chrome startup');
// Chrome writes DevToolsActivePort a moment before it accepts connections
// (CI run 416: ECONNREFUSED, then "DevTools listening"): a refused
// connection is tried again for a few seconds; any other error fails.
async function newTab(url){
for(let attempt=0;;attempt++){
try{return await (await fetch('http://localhost:'+port+'/json/new?'+encodeURIComponent(url),{method:'PUT'})).json();}
catch(error){if(attempt>=50||error?.cause?.code!=='ECONNREFUSED')throw error;await pause(200);}
}
}
async function page(url){
const tab=await (await fetch('http://localhost:'+port+'/json/new?'+encodeURIComponent(url),{method:'PUT'})).json();
const tab=await newTab(url);
const ws=new WebSocket(tab.webSocketDebuggerUrl);await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j;});
const p=new Page(ws);clients.push(p);await p.call('Runtime.enable');await p.call('Page.enable');
await p.call('Emulation.setDeviceMetricsOverride',{width:1440,height:1000,deviceScaleFactor:1,mobile:false});