← back to Rentv

5x/firms-probe.js

29 lines

const puppeteer=require(process.env.HOME+'/.npm-global/lib/node_modules/puppeteer');
const AUTH='Basic '+Buffer.from('admin:DW2024!').toString('base64');
(async()=>{
  const b=await puppeteer.launch({headless:'new',executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',args:['--no-sandbox']});
  const p=await b.newPage(); await p.setExtraHTTPHeaders({Authorization:AUTH}); await p.setViewport({width:1500,height:950});
  await p.goto('http://localhost:9704/crm',{waitUntil:'domcontentloaded',timeout:30000});
  await p.waitForFunction("document.querySelectorAll('#rows .row,.tbl tbody tr').length>0",{timeout:12000});
  const before=await p.evaluate(()=>document.querySelectorAll('#rows .row,.tbl tbody tr').length);
  console.log('initial rows:',before);
  // is there a firms button?
  const hasFirms=await p.evaluate(()=>!!document.querySelector('button[data-type="firms"]'));
  console.log('firms button exists:',hasFirms);
  if(hasFirms){
    await p.evaluate(()=>document.querySelector('button[data-type="firms"]').click());
    await new Promise(r=>setTimeout(r,3000));
    const after=await p.evaluate(()=>document.querySelectorAll('#rows .row,.tbl tbody tr').length);
    const ls=await p.evaluate(()=>JSON.stringify(Object.keys(localStorage)));
    console.log('rows after firms click:',after);
    console.log('localStorage keys:',ls);
  }
  // now reload and see what state persists
  await p.goto('http://localhost:9704/crm',{waitUntil:'domcontentloaded',timeout:30000});
  await new Promise(r=>setTimeout(r,1500));
  const afterReload=await p.evaluate(()=>document.querySelectorAll('#rows .row,.tbl tbody tr').length);
  const onchip=await p.evaluate(()=>{const c=document.querySelector('.chip.on,[data-type].on');return c?c.getAttribute('data-type'):'none';});
  console.log('rows after RELOAD (post-firms):',afterReload,'| active type:',onchip);
  await b.close();
})().catch(e=>{console.error('FATAL',e.message);process.exit(1);});