// browser2chat.8 (CHAT-04, Vorlage v1.2): Der Mini-Player bleibt beim Scrollen des Verlaufs erreichbar (feste Stelle, im Fenster). // Aufruf: node chat-player-scroll.mjs (Testinstanz wie chat-layout.mjs; die Antwort der Attrappe ist lang) import * as cdp from './lib.mjs'; const BASE=process.env.NEXUS_BASE||'http://127.0.0.1:18122', pw=process.argv[2]; const b=await cdp.start({port:9376,args:['--autoplay-policy=no-user-gesture-required']}); const ok=(n,c,d='')=>{console.log(`${c?'ok ':'FEHLER'} ${n}${d?' – '+d:''}`); if(!c) process.exitCode=1;}; const warte=ms=>new Promise(r=>setTimeout(r,ms)); const ev=x=>b.eval(x); try{ await b.login(BASE,'claude',pw); await b.viewport(1100,700,{mobile:false}); await b.goto(BASE+'/ui/chat'); await warte(1200); await ev(`(()=>{const s=document.getElementById('chat-sprache'); s.value='tts-base'; s.dispatchEvent(new Event('change',{bubbles:true}));})()`); await warte(800); await ev(`document.getElementById('chat-max').value='400'`); await ev(`document.getElementById('chat-text').value='Lange Antwort bitte'`); await ev(`document.getElementById('chat-senden').click()`); for(let i=0;i<300;i++){ await warte(500); if(await ev(`!document.getElementById('chat-senden').disabled && document.querySelectorAll('.blase.assistant').length>0`)) break; } await warte(1200); const pos=()=>ev(`(()=>{const p=document.getElementById('chat-player').getBoundingClientRect(); const v=document.getElementById('chat-verlauf'); return {oben:Math.round(p.top), unten:Math.round(p.bottom), innen:p.top>=0&&p.bottom<=window.innerHeight, scrollbar:v.scrollHeight>v.clientHeight, scrollTop:Math.round(v.scrollTop)};})()`); const unten=await pos(); await ev(`document.getElementById('chat-verlauf').scrollTop=0`); await warte(400); const oben=await pos(); ok('Der Verlauf ist länger als sein Fenster (es wird wirklich gescrollt)', unten.scrollbar && unten.scrollTop>oben.scrollTop, JSON.stringify([unten,oben])); ok('Player bleibt beim Scrollen an derselben Stelle und im Fenster', oben.innen && unten.oben===oben.oben, JSON.stringify([unten.oben,oben.oben])); await b.shot('/tmp/chat-player-scroll.png'); }catch(e){console.log('Fehler im Lauf:',e.message); process.exitCode=1;} finally{b.close();}