// Synthetic QA only; tile traffic is blocked to avoid automated OSM downloads. const target = await ( await fetch('http://127.0.0.1:9224/json/new?about:blank', { method: 'PUT' }) ).json(); const ws = new WebSocket(target.webSocketDebuggerUrl); await new Promise((resolve) => ws.addEventListener('open', resolve, { once: true }), ); let sequence = 0; const pending = new Map(); const errors = []; ws.onmessage = (event) => { const message = JSON.parse(event.data); if (message.method === 'Runtime.exceptionThrown') errors.push(message.params.exceptionDetails.text); if (message.id) { const callback = pending.get(message.id); pending.delete(message.id); if (message.error) callback.reject(message.error); else callback.resolve(message.result); } }; const send = (method, params = {}) => new Promise((resolve, reject) => { const id = ++sequence; pending.set(id, { resolve, reject }); ws.send(JSON.stringify({ id, method, params })); }); const evaluate = async (expression) => { const response = await send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true, }); if (response.exceptionDetails) throw Error(JSON.stringify(response.exceptionDetails)); return response.result?.value; }; const wait = async (expression) => { for (let i = 0; i < 150; i++) { if (await evaluate(expression)) return; await new Promise((resolve) => setTimeout(resolve, 100)); } throw Error('Timed out: ' + expression); }; try { await send('Runtime.enable'); await send('Page.enable'); await send('Network.enable'); await send('Network.setBlockedURLs', { urls: ['*://tile.openstreetmap.org/*'], }); await send('Page.navigate', { url: 'http://127.0.0.1:18027/oportunidades', }); await wait(`document.querySelectorAll('.leaflet-marker-icon').length===1`); await evaluate(`document.querySelector('.leaflet-marker-icon').click()`); await wait( `document.querySelector('.leaflet-popup-content')?.textContent.includes('Synthetic map marker')`, ); if ( !(await evaluate( `document.querySelector('.leaflet-popup-content a')?.getAttribute('href')==='/oportunidades/synthetic-map-browser'`, )) ) throw Error('Missing detail link'); await evaluate( `document.querySelector('.leaflet-control-zoom-in').click()`, ); const layouts = []; for (const width of [390, 1440]) { await send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: width < 600, }); layouts.push({ width, noOverflow: await evaluate( 'document.documentElement.scrollWidth<=innerWidth+1', ), }); } await evaluate( `window.__mapSentinel=1;document.querySelector('main form input').focus()`, ); await send('Input.insertText', { text: 'NoMatchingSyntheticInvestment' }); await wait( `location.search.includes('NoMatchingSyntheticInvestment') && document.querySelectorAll('.leaflet-marker-icon').length===0`, ); if (!(await evaluate(`window.__mapSentinel===1`))) throw Error('Full page reload detected'); if (errors.length || layouts.some((l) => !l.noOverflow)) throw Error('Browser validation failed'); console.log( JSON.stringify({ marker: true, popup: true, detail_link: true, zoom_control: true, automatic_filter: true, no_full_reload: true, layouts, javascript_errors: errors.length, tiles_blocked_for_test: true, }), ); } finally { ws.close(); await fetch(`http://127.0.0.1:9224/json/close/${target.id}`); }