import { attach } from '/tmp/cdp3.mjs'; const wait = ms => new Promise(z => setTimeout(z, ms)); const c = await attach('/web/sheinProduct/add') || await attach('dianxiaomi.com'); console.log('url:', await c.evalJS('location.href')); // 探测可用的消息库 const probe = await c.evalJS(`(()=>{const keys=['MYJ','Vue','antd','$message','ELEMENT']; const found={}; keys.forEach(k=>{ try{ found[k]=typeof window[k]; }catch(e){ found[k]='err'; } }); return JSON.stringify(found);})()`); console.log('全局对象:', String(probe)); // 埋钩子(尽量广) const hook = await c.evalJS(`(()=>{window.__cap=[]; let n=0; function wrap(obj,name,label){ try{ if(!obj||!obj[name])return; const o=obj[name]; obj[name]=function(){ try{ window.__cap.push(label+': '+Array.prototype.slice.call(arguments).map(function(a){return typeof a==='string'?a:JSON.stringify(a);}).join(' ').slice(0,200)); }catch(e){} return o.apply(obj,arguments); }; n++; }catch(e){} } try{ if(window.MYJ&&window.MYJ.message){ ['error','warning','info','success'].forEach(k=>wrap(window.MYJ.message,k,'MYJ.'+k)); } }catch(e){} try{ if(window.antd&&window.antd.message){ ['error','warning','info','success'].forEach(k=>wrap(window.antd.message,k,'antd.'+k)); } }catch(e){} try{ if(window.$message){ ['error','warning','info','success'].forEach(k=>wrap(window.$message,k,'$message.'+k)); } }catch(e){} return 'wrapped '+n;})()`); console.log('钩子:', String(hook)); // 点保存 await c.evalJS(`window.scrollTo(0,0)`); await wait(600); await c.evalJS(`(()=>{const x=[...document.querySelectorAll('button')].filter(e=>e.offsetParent!==null).find(e=>/^\\s*保存\\s*$/.test((e.innerText||'').trim())); if(x) for(const ev of ['mousedown','mouseup','click']) x.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 1;})()`); await wait(9000); const cap = await c.evalJS(`JSON.stringify(window.__cap||[])`); console.log('★ 捕获:', String(cap).slice(0,600)); const errs = await c.evalJS(`JSON.stringify([].slice.call(document.querySelectorAll('.ant-form-item-explain-error')).map(function(e){ var p=e.closest?e.closest('.ant-form-item'):null; var l=p?(p.querySelector('label')||{}).innerText||'':''; return l.replace(/\\s+/g,' ').trim().slice(0,30)+' → '+(e.innerText||'').trim();}).filter(Boolean))`); console.log('行内错误:', String(errs).slice(0,400)); const errItems = await c.evalJS(`JSON.stringify([].slice.call(document.querySelectorAll('.ant-form-item-has-error')).map(function(x){var l=x.querySelector('label');return l?(l.innerText||'').replace(/\\s+/g,' ').trim().slice(0,36):'?';}))`); console.log('出错字段:', String(errItems).slice(0,300)); process.exit(0);