diff --git a/tests/artwork_browser_test.mjs b/tests/artwork_browser_test.mjs index a204844..2e9c0d7 100644 --- a/tests/artwork_browser_test.mjs +++ b/tests/artwork_browser_test.mjs @@ -104,7 +104,13 @@ async function screenshot(name){ try{ let port; await waitFor(async()=>{try{port=Number((await readFile(profile+'/DevToolsActivePort','utf8')).split('\n')[0]);return true;}catch{return false;}},'Chrome startup'); - const tab=await(await fetch(`http://127.0.0.1:${port}/json/new?about:blank`,{method:'PUT'})).json(); + // Chrome writes DevToolsActivePort a moment before it accepts connections + // (CI run 416): a refused connection is tried again for a few seconds. + let tab; + for(let attempt=0;!tab;attempt++){ + try{tab=await(await fetch(`http://127.0.0.1:${port}/json/new?about:blank`,{method:'PUT'})).json();} + catch(error){if(attempt>=50||error?.cause?.code!=='ECONNREFUSED')throw error;await pause(200);} + } ws=new WebSocket(tab.webSocketDebuggerUrl); await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j;}); ws.onmessage=event=>{ diff --git a/tests/browser_test.mjs b/tests/browser_test.mjs index bf71c53..1686582 100644 --- a/tests/browser_test.mjs +++ b/tests/browser_test.mjs @@ -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});