@zibby/mcp-browser 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
- var ne=Object.create;var W=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var ae=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of se(n))!oe.call(e,t)&&t!==r&&W(e,t,{get:()=>n[t],enumerable:!(s=re(n,t))||s.enumerable});return e};var le=(e,n,r)=>(r=e!=null?ne(ie(e)):{},ae(n||!e||!e.__esModule?W(r,"default",{value:e,enumerable:!0}):r,e));const{spawn:ce,execFileSync:de}=require("child_process"),m=require("fs"),S=require("path"),A=S.join(__dirname,"..","src","stable-id-inject.js"),Y=S.join(require("os").tmpdir(),"zibby-mcp-debug.log");function i(e){const n=`[${new Date().toISOString()}] ${e}
3
- `;m.appendFileSync(Y,n),console.error(`[Zibby MCP] ${e}`)}m.appendFileSync(Y,`
2
+ var ne=Object.create;var W=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var ae=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of se(n))!oe.call(e,t)&&t!==r&&W(e,t,{get:()=>n[t],enumerable:!(s=re(n,t))||s.enumerable});return e};var le=(e,n,r)=>(r=e!=null?ne(ie(e)):{},ae(n||!e||!e.__esModule?W(r,"default",{value:e,enumerable:!0}):r,e));const{spawn:ce,execFileSync:de}=require("child_process"),S=require("fs"),f=require("path"),x=[f.join(__dirname,"..","src","stable-id-inject.js"),f.join(__dirname,"..","stable-id-inject.js")].find(e=>S.existsSync(e))||f.join(__dirname,"..","src","stable-id-inject.js"),Y=f.join(require("os").tmpdir(),"zibby-mcp-debug.log");function i(e){const n=`[${new Date().toISOString()}] ${e}
3
+ `;S.appendFileSync(Y,n),console.error(`[Zibby MCP] ${e}`)}S.appendFileSync(Y,`
4
4
  === Zibby MCP Started ${new Date().toISOString()} PID:${process.pid} ===
5
- `),i(`Args: ${process.argv.slice(2).join(" ")}`),i(`Env ZIBBY_NODE_SESSION_PATH=${process.env.ZIBBY_NODE_SESSION_PATH||"(not set)"}`),i(`Env ZIBBY_SESSION_PATH=${process.env.ZIBBY_SESSION_PATH||"(not set)"}`),i(`Env ZIBBY_SESSION_INFO=${process.env.ZIBBY_SESSION_INFO||"(not set)"}`);let o=null,B="none";const w=[];let q=null;function fe(){if(process.env.ZIBBY_NODE_SESSION_PATH){o=process.env.ZIBBY_NODE_SESSION_PATH,B="env:ZIBBY_NODE_SESSION_PATH",m.mkdirSync(o,{recursive:!0}),i(`\u{1F4C1} Session from env: ${o}`);return}const e=process.argv.slice(2);for(const r of e)if(r.startsWith("--output-dir=")){o=r.split("=").slice(1).join("="),B="arg:--output-dir",m.mkdirSync(o,{recursive:!0}),i(`\u{1F4C1} Session from --output-dir: ${o}`);return}if(process.env.ZIBBY_SESSION_PATH){const r=S.join(process.env.ZIBBY_SESSION_PATH,".session-info.json");if(m.existsSync(r))try{const s=JSON.parse(m.readFileSync(r,"utf-8")),t=s.currentNode||"execute_live";o=S.join(s.sessionPath||process.env.ZIBBY_SESSION_PATH,t),B="file:per-session",m.mkdirSync(o,{recursive:!0}),i(`\u{1F4C1} Session from per-session file: ${o}`);return}catch(s){i(`\u26A0\uFE0F Per-session file read error: ${s.message}`)}}const n=[process.env.ZIBBY_SESSION_INFO,S.join(process.cwd(),".zibby/output/.session-info.json"),S.join(process.cwd(),"test-results/.session-info.json")].filter(Boolean);for(const r of n)if(m.existsSync(r))try{const s=JSON.parse(m.readFileSync(r,"utf-8")),t=s.currentNode||"execute_live";if(s.sessionPath){o=S.join(s.sessionPath,t),B=`file:shared(${S.basename(r)})`,m.mkdirSync(o,{recursive:!0}),i(`\u26A0\uFE0F Session from SHARED file (race-prone): ${o}`);return}}catch(s){i(`\u26A0\uFE0F Shared file read error: ${s.message}`)}i("\u26A0\uFE0F No session path resolved \u2014 events will not be recorded")}function G(e){const n=Math.floor(e/1e3),r=Math.floor(n/3600),s=Math.floor(n%3600/60),t=n%60,a=e%1e3;return`${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}:${String(t).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function y(e,n){if(!o)return;const r=Date.now();q||(q=r);const s=r-q,t={id:w.length,type:e,timestamp:new Date(r).toISOString(),videoOffsetMs:s,videoOffsetFormatted:G(s),data:n,_recordedBy:"zibby-wrapper-v2"};return w.push(t),i(`\u{1F4DD} Event #${t.id}: ${e}${n.stableId?` [${n.stableId}]`:""}`),e==="close"?pe():N(),t.id}function ue(e,n){if(!o||e<0||e>=w.length)return;const r=w[e];r&&!r.data.stableId&&n&&(r.data.stableId=n,i(`\u{1F517} Event #${e} stableId: ${n}`),N())}function me(e){function a(f,d,u){if(d>=f.length)return null;const I=f[d];let b=1,z=128;for(;b<=8&&!(I&z);)b++,z>>=1;if(b>8||d+b>f.length)return null;let C=u?I:I&z-1;for(let Z=1;Z<b;Z++)C=C<<8|f[d+Z];return{value:C,length:b}}function l(f,d){if(d>=f.length)return null;const u=a(f,d,!0);if(!u)return null;d+=u.length;const I=a(f,d,!1);return I?(d+=I.length,{id:u.value,dataStart:d,dataSize:I.value,dataEnd:d+I.value}):null}function _(f,d,u){let I=0;for(let b=0;b<u;b++)I=I<<8|f[d+b];return I}function E(f,d,u){return u===4?f.readFloatBE(d):u===8?f.readDoubleBE(d):null}let c=0,p=1e6,v=null;const P=l(e,c);if(!P)return null;c=P.dataEnd;const j=l(e,c);if(!j||j.id!==408125543)return null;c=j.dataStart;const te=Math.min(j.dataEnd,e.length);for(;c<te;){const f=l(e,c);if(!f)break;if(f.id===357149030){let d=f.dataStart;for(;d<f.dataEnd;){const u=l(e,d);if(!u)break;u.id===2807729?p=_(e,u.dataStart,u.dataSize):u.id===17545&&(v=E(e,u.dataStart,u.dataSize)),d=u.dataEnd}break}c=f.dataEnd}return v!==null?v*p/1e6:null}function Se(e){try{const n=de("ffprobe",["-v","error","-show_entries","format=duration","-of","default=noprint_wrappers=1:nokey=1",e],{encoding:"utf-8",timeout:5e3}),r=parseFloat(n.trim());if(!isNaN(r)){const s=Math.round(r*1e3);return i(`\u{1F4CF} Video duration (ffprobe): ${s}ms`),s}}catch{i("\u26A0\uFE0F ffprobe not available, using WebM parser fallback")}try{const n=m.readFileSync(e),r=me(n);if(r){const s=Math.round(r);return i(`\u{1F4CF} Video duration (WebM parser): ${s}ms`),s}}catch(n){i(`\u26A0\uFE0F WebM parsing failed: ${n.message}`)}return null}function pe(){if(!o||w.length===0)return;let e=null,n=0;const r=40;let s=0,t=0;for(;!e&&n<r;){n++;let c=null;if(m.existsSync(S.join(o,"recording.webm")))c=S.join(o,"recording.webm"),n===1&&i("Found recording.webm");else try{const p=m.readdirSync(o);n===1&&i(`Directory contains ${p.length} files: ${p.join(", ")}`);const v=p.filter(P=>P.endsWith(".webm"));n===1&&v.length>0&&i(`Found ${v.length} .webm file(s): ${v.join(", ")}`),v.length>0&&(c=S.join(o,v[0]))}catch(p){n===1&&i(`\u26A0\uFE0F Error reading directory: ${p.message}`)}if(c&&m.existsSync(c))try{const v=m.statSync(c).size;if(v>0&&v===s){if(t++,t>=2){e=c,i(`\u2705 Video file stable after ${n} attempts: ${S.basename(e)} (${v} bytes)`);break}}else t=0,s=v}catch(p){i(`\u26A0\uFE0F Error checking file: ${p.message}`)}if(!e){n%5===0&&i(`\u23F3 Waiting for stable video file... (attempt ${n}/${r}, size: ${s})`);const p=Date.now();for(;Date.now()-p<500;);}}if(!e){i(`\u26A0\uFE0F Video file not found/stable after ${n} attempts in: ${o}`),N();return}const a=Se(e);if(!a){i("\u26A0\uFE0F Could not determine video duration, using fallback"),N();return}const l=w.find(c=>c.type==="close");if(!l){i("\u26A0\uFE0F No close event found"),N();return}const _=new Date(l.timestamp).getTime(),E=_-a;i(`\u{1F4CA} Calculated video start: ${new Date(E).toISOString()}`),i(` Close timestamp: ${_}ms`),i(` Video duration: ${a}ms`),w.forEach(c=>{const p=new Date(c.timestamp).getTime();c.videoOffsetMs=p-E,c.videoOffsetFormatted=G(c.videoOffsetMs)}),i(`\u2705 Recalculated ${w.length} events using accurate video start time`),N()}function N(){if(o)try{const e=S.join(o,"events.json");m.writeFileSync(e,JSON.stringify(w,null,2))}catch{}}i(`CWD: ${process.cwd()}`),fe();const U=process.argv.slice(2);let O=null;for(const e of U){const n=e.match(/^--save-video=(\d+)x(\d+)$/);if(n){O={width:parseInt(n[1],10),height:parseInt(n[2],10)};break}}const h=U.filter(e=>!e.startsWith("--save-video"));m.existsSync(A)?(h.unshift("--init-script",A),i(`\u2705 Stable ID injection enabled: ${A}`)):i(`\u26A0\uFE0F Stable ID script not found: ${A}`);const x=h.findIndex(e=>e==="--caps");if(x>=0&&h[x+1])h[x+1].includes("devtools")||(h[x+1]+=",devtools");else{const e=h.findIndex(n=>n.startsWith("--caps="));e>=0?h[e].includes("devtools")||(h[e]+=",devtools"):h.push("--caps","devtools")}if(o){const e=h.findIndex(n=>n.startsWith("--output-dir"));e!==-1?h[e]=`--output-dir=${o}`:h.push("--output-dir",o),i(`\u{1F4F9} Video output: ${o} (source: ${B})`)}const ve=S.dirname(require.resolve("@playwright/mcp")),he=S.join(ve,"cli.js"),g=ce(process.execPath,[he,...h],{stdio:["pipe","pipe","inherit"]});let $=!1,H=!1,Q=8e5;const D=new Set;function Ie(){if(H||!o)return;H=!0;const e=Q++;D.add(e);const n=o?S.join(o,"recording.webm"):"recording.webm",r={jsonrpc:"2.0",id:e,method:"tools/call",params:{name:"browser_start_video",arguments:{filename:n,...O?{size:O}:{}}}};try{g.stdin.write(JSON.stringify(r)+`
6
- `),i(`\u{1F3AC} Auto-started video recording${O?` (${O.width}x${O.height})`:""}`)}catch(s){D.delete(e),i(`\u26A0\uFE0F browser_start_video send failed: ${s.message}`)}}function _e(){if(!H)return;const e=Q++;D.add(e);const n={jsonrpc:"2.0",id:e,method:"tools/call",params:{name:"browser_stop_video",arguments:{}}};try{g.stdin.write(JSON.stringify(n)+`
7
- `),i("\u{1F3AC} Auto-stopped video recording")}catch(r){D.delete(e),i(`\u26A0\uFE0F browser_stop_video send failed: ${r.message}`)}}const ge=2e3,be=5e3,K="frames";let X=0,we=1e6;const R=new Set;let k=null;function L(){k&&(clearInterval(k),k=null)}function $e(){if(o)try{m.mkdirSync(S.join(o,K),{recursive:!0})}catch{}}function J(){return S.join(o,K,`live-frame-${Date.now()}.png`)}function ye(){L(),!(!$||!o)&&(k=setInterval(()=>{if(!$||!o){L();return}ee(!0,J())},be))}function ee(e,n){if(!o||!$)return;$e();const r=Date.now();if(!e&&r-X<ge)return;X=r;const s=n||J(),t=we++;R.add(t);const a={jsonrpc:"2.0",id:t,method:"tools/call",params:{name:"browser_take_screenshot",arguments:{type:"png",filename:s}}};try{g.stdin.write(JSON.stringify(a)+`
8
- `),i(`\u{1F4F8} live-frame queued: ${s}`)}catch(l){R.delete(t),i(`\u26A0\uFE0F live-frame send failed: ${l.message}`)}}function Ee(e){!e||typeof e!="string"||!e.startsWith("browser_")||e==="browser_close"||e==="browser_take_screenshot"||!o||!$||ee(!1,J())}const T=new Map;let Ne=9e5;const V=new Map;let F="";process.stdin.on("data",e=>{F+=e.toString();const n=F.split(`
9
- `);F=n.pop()||"";for(const r of n)if(r.trim()){try{const s=JSON.parse(r);if(s.method&&i(`\u{1F4E8} STDIN: ${s.method} ${s.params?.name||""}`),s.method==="tools/call"&&s.params){const t=s.params.name,a=s.params.arguments||{};T.set(s.id,{toolName:t,toolArgs:a});let l=-1;t==="browser_navigate"?($=!0,ye(),l=y("navigate",{url:a.url})):t==="browser_click"?l=y("click",{element:a.element,ref:a.ref}):t==="browser_type"?l=y("type",{element:a.element,ref:a.ref,text:a.text}):t==="browser_select_option"?l=y("select",{element:a.element,ref:a.ref,values:a.values}):t==="browser_fill_form"?l=y("fill_form",{fields:a.fields}):t==="browser_hover"?l=y("hover",{element:a.element,ref:a.ref}):t==="browser_close"?(_e(),l=y("close",{}),$=!1,L()):t==="browser_snapshot"&&(l=y("snapshot",{})),l>=0&&(T.get(s.id).eventId=l)}}catch{}g.stdin.write(r+`
10
- `)}}),process.stdin.on("end",()=>{F.trim()&&g.stdin.write(F+`
11
- `),g.stdin.end()});let M="";g.stdout.on("data",e=>{M+=e.toString();const n=M.split(`
12
- `);M=n.pop()||"";for(const r of n){if(!r.trim())continue;let s=!0;try{const t=JSON.parse(r);if(t.id&&D.has(t.id))D.delete(t.id),t.error&&i(`\u26A0\uFE0F Video RPC error: ${t.error?.message||JSON.stringify(t.error)}`),s=!1;else if(t.id&&R.has(t.id))R.delete(t.id),t.error&&i(`\u26A0\uFE0F Screenshot RPC error: ${t.error?.message||JSON.stringify(t.error)}`),s=!1;else if(t.id&&T.has(t.id)){const a=T.get(t.id);if(T.delete(t.id),!t.error&&$&&Ee(a.toolName),!t.error&&a.toolName==="browser_navigate"&&Ie(),!t.error&&$&&a.eventId>=0&&["browser_click","browser_type","browser_select_option","browser_fill_form","browser_hover"].includes(a.toolName)){const _=Ne++,E={jsonrpc:"2.0",id:_,method:"tools/call",params:{name:"browser_evaluate",arguments:{function:"() => { const match = document.cookie.match(/(?:^|; )__zibbyLastStableId=([^;]*)/); const id = match ? decodeURIComponent(match[1]) : (window.__zibbyLastStableId || null); return id; }"}}};i(`\u{1F50D} Querying stable ID for event #${a.eventId}`),V.set(_,{eventId:a.eventId}),g.stdin.write(JSON.stringify(E)+`
13
- `)}}if(t.id&&V.has(t.id)){const a=V.get(t.id);if(V.delete(t.id),i(`\u{1F4E5} Stable ID response for event #${a.eventId}: ${JSON.stringify(t.result||t.error||"no result").slice(0,200)}`),t.result?.content?.[0]?.text){const l=t.result.content[0].text,_=l.match(/zibby-[a-zA-Z0-9-]+/);_?(i(`\u2705 Found stable ID: ${_[0]}`),ue(a.eventId,_[0])):i(`\u26A0\uFE0F No stable ID found in: ${l.slice(0,100)}`)}else t.error&&i(`\u274C Stable ID query error: ${t.error?.message||JSON.stringify(t.error)}`);s=!1}}catch{}s&&process.stdout.write(r+`
14
- `)}}),g.on("close",e=>{L(),$=!1,M.trim()&&process.stdout.write(M),process.exit(e||0)}),process.on("SIGINT",()=>{g.kill("SIGINT")}),process.on("SIGTERM",()=>{g.kill("SIGTERM")});
5
+ `),i(`Args: ${process.argv.slice(2).join(" ")}`),i(`Env ZIBBY_NODE_SESSION_PATH=${process.env.ZIBBY_NODE_SESSION_PATH||"(not set)"}`),i(`Env ZIBBY_SESSION_PATH=${process.env.ZIBBY_SESSION_PATH||"(not set)"}`),i(`Env ZIBBY_SESSION_INFO=${process.env.ZIBBY_SESSION_INFO||"(not set)"}`);let o=null,j="none";const w=[];let q=null;function fe(){if(process.env.ZIBBY_NODE_SESSION_PATH){o=process.env.ZIBBY_NODE_SESSION_PATH,j="env:ZIBBY_NODE_SESSION_PATH",S.mkdirSync(o,{recursive:!0}),i(`\u{1F4C1} Session from env: ${o}`);return}const e=process.argv.slice(2);for(const r of e)if(r.startsWith("--output-dir=")){o=r.split("=").slice(1).join("="),j="arg:--output-dir",S.mkdirSync(o,{recursive:!0}),i(`\u{1F4C1} Session from --output-dir: ${o}`);return}if(process.env.ZIBBY_SESSION_PATH){const r=f.join(process.env.ZIBBY_SESSION_PATH,".session-info.json");if(S.existsSync(r))try{const s=JSON.parse(S.readFileSync(r,"utf-8")),t=s.currentNode||"execute_live";o=f.join(s.sessionPath||process.env.ZIBBY_SESSION_PATH,t),j="file:per-session",S.mkdirSync(o,{recursive:!0}),i(`\u{1F4C1} Session from per-session file: ${o}`);return}catch(s){i(`\u26A0\uFE0F Per-session file read error: ${s.message}`)}}const n=[process.env.ZIBBY_SESSION_INFO,f.join(process.cwd(),".zibby/output/.session-info.json"),f.join(process.cwd(),"test-results/.session-info.json")].filter(Boolean);for(const r of n)if(S.existsSync(r))try{const s=JSON.parse(S.readFileSync(r,"utf-8")),t=s.currentNode||"execute_live";if(s.sessionPath){o=f.join(s.sessionPath,t),j=`file:shared(${f.basename(r)})`,S.mkdirSync(o,{recursive:!0}),i(`\u26A0\uFE0F Session from SHARED file (race-prone): ${o}`);return}}catch(s){i(`\u26A0\uFE0F Shared file read error: ${s.message}`)}i("\u26A0\uFE0F No session path resolved \u2014 events will not be recorded")}function G(e){const n=Math.floor(e/1e3),r=Math.floor(n/3600),s=Math.floor(n%3600/60),t=n%60,a=e%1e3;return`${String(r).padStart(2,"0")}:${String(s).padStart(2,"0")}:${String(t).padStart(2,"0")}.${String(a).padStart(3,"0")}`}function y(e,n){if(!o)return;const r=Date.now();q||(q=r);const s=r-q,t={id:w.length,type:e,timestamp:new Date(r).toISOString(),videoOffsetMs:s,videoOffsetFormatted:G(s),data:n,_recordedBy:"zibby-wrapper-v2"};return w.push(t),i(`\u{1F4DD} Event #${t.id}: ${e}${n.stableId?` [${n.stableId}]`:""}`),e==="close"?pe():N(),t.id}function ue(e,n){if(!o||e<0||e>=w.length)return;const r=w[e];r&&!r.data.stableId&&n&&(r.data.stableId=n,i(`\u{1F517} Event #${e} stableId: ${n}`),N())}function me(e){function a(u,d,m){if(d>=u.length)return null;const h=u[d];let b=1,z=128;for(;b<=8&&!(h&z);)b++,z>>=1;if(b>8||d+b>u.length)return null;let C=m?h:h&z-1;for(let Z=1;Z<b;Z++)C=C<<8|u[d+Z];return{value:C,length:b}}function l(u,d){if(d>=u.length)return null;const m=a(u,d,!0);if(!m)return null;d+=m.length;const h=a(u,d,!1);return h?(d+=h.length,{id:m.value,dataStart:d,dataSize:h.value,dataEnd:d+h.value}):null}function I(u,d,m){let h=0;for(let b=0;b<m;b++)h=h<<8|u[d+b];return h}function E(u,d,m){return m===4?u.readFloatBE(d):m===8?u.readDoubleBE(d):null}let c=0,p=1e6,v=null;const M=l(e,c);if(!M)return null;c=M.dataEnd;const P=l(e,c);if(!P||P.id!==408125543)return null;c=P.dataStart;const te=Math.min(P.dataEnd,e.length);for(;c<te;){const u=l(e,c);if(!u)break;if(u.id===357149030){let d=u.dataStart;for(;d<u.dataEnd;){const m=l(e,d);if(!m)break;m.id===2807729?p=I(e,m.dataStart,m.dataSize):m.id===17545&&(v=E(e,m.dataStart,m.dataSize)),d=m.dataEnd}break}c=u.dataEnd}return v!==null?v*p/1e6:null}function Se(e){try{const n=de("ffprobe",["-v","error","-show_entries","format=duration","-of","default=noprint_wrappers=1:nokey=1",e],{encoding:"utf-8",timeout:5e3}),r=parseFloat(n.trim());if(!isNaN(r)){const s=Math.round(r*1e3);return i(`\u{1F4CF} Video duration (ffprobe): ${s}ms`),s}}catch{i("\u26A0\uFE0F ffprobe not available, using WebM parser fallback")}try{const n=S.readFileSync(e),r=me(n);if(r){const s=Math.round(r);return i(`\u{1F4CF} Video duration (WebM parser): ${s}ms`),s}}catch(n){i(`\u26A0\uFE0F WebM parsing failed: ${n.message}`)}return null}function pe(){if(!o||w.length===0)return;let e=null,n=0;const r=40;let s=0,t=0;for(;!e&&n<r;){n++;let c=null;if(S.existsSync(f.join(o,"recording.webm")))c=f.join(o,"recording.webm"),n===1&&i("Found recording.webm");else try{const p=S.readdirSync(o);n===1&&i(`Directory contains ${p.length} files: ${p.join(", ")}`);const v=p.filter(M=>M.endsWith(".webm"));n===1&&v.length>0&&i(`Found ${v.length} .webm file(s): ${v.join(", ")}`),v.length>0&&(c=f.join(o,v[0]))}catch(p){n===1&&i(`\u26A0\uFE0F Error reading directory: ${p.message}`)}if(c&&S.existsSync(c))try{const v=S.statSync(c).size;if(v>0&&v===s){if(t++,t>=2){e=c,i(`\u2705 Video file stable after ${n} attempts: ${f.basename(e)} (${v} bytes)`);break}}else t=0,s=v}catch(p){i(`\u26A0\uFE0F Error checking file: ${p.message}`)}if(!e){n%5===0&&i(`\u23F3 Waiting for stable video file... (attempt ${n}/${r}, size: ${s})`);const p=Date.now();for(;Date.now()-p<500;);}}if(!e){i(`\u26A0\uFE0F Video file not found/stable after ${n} attempts in: ${o}`),N();return}const a=Se(e);if(!a){i("\u26A0\uFE0F Could not determine video duration, using fallback"),N();return}const l=w.find(c=>c.type==="close");if(!l){i("\u26A0\uFE0F No close event found"),N();return}const I=new Date(l.timestamp).getTime(),E=I-a;i(`\u{1F4CA} Calculated video start: ${new Date(E).toISOString()}`),i(` Close timestamp: ${I}ms`),i(` Video duration: ${a}ms`),w.forEach(c=>{const p=new Date(c.timestamp).getTime();c.videoOffsetMs=p-E,c.videoOffsetFormatted=G(c.videoOffsetMs)}),i(`\u2705 Recalculated ${w.length} events using accurate video start time`),N()}function N(){if(o)try{const e=f.join(o,"events.json");S.writeFileSync(e,JSON.stringify(w,null,2))}catch{}}i(`CWD: ${process.cwd()}`),fe();const U=process.argv.slice(2);let O=null;for(const e of U){const n=e.match(/^--save-video=(\d+)x(\d+)$/);if(n){O={width:parseInt(n[1],10),height:parseInt(n[2],10)};break}}const _=U.filter(e=>!e.startsWith("--save-video"));S.existsSync(x)?(_.unshift("--init-script",x),i(`\u2705 Stable ID injection enabled: ${x}`)):i(`\u26A0\uFE0F Stable ID script not found: ${x}`);const A=_.findIndex(e=>e==="--caps");if(A>=0&&_[A+1])_[A+1].includes("devtools")||(_[A+1]+=",devtools");else{const e=_.findIndex(n=>n.startsWith("--caps="));e>=0?_[e].includes("devtools")||(_[e]+=",devtools"):_.push("--caps","devtools")}if(o){const e=_.findIndex(n=>n.startsWith("--output-dir"));e!==-1?_[e]=`--output-dir=${o}`:_.push("--output-dir",o),i(`\u{1F4F9} Video output: ${o} (source: ${j})`)}const ve=f.dirname(require.resolve("@playwright/mcp")),_e=f.join(ve,"cli.js"),g=ce(process.execPath,[_e,..._],{stdio:["pipe","pipe","inherit"]});let $=!1,H=!1,Q=8e5;const D=new Set;function he(){if(H||!o)return;H=!0;const e=Q++;D.add(e);const n=o?f.join(o,"recording.webm"):"recording.webm",r={jsonrpc:"2.0",id:e,method:"tools/call",params:{name:"browser_start_video",arguments:{filename:n,...O?{size:O}:{}}}};try{g.stdin.write(JSON.stringify(r)+`
6
+ `),i(`\u{1F3AC} Auto-started video recording${O?` (${O.width}x${O.height})`:""}`)}catch(s){D.delete(e),i(`\u26A0\uFE0F browser_start_video send failed: ${s.message}`)}}function Ie(){if(!H)return;const e=Q++;D.add(e);const n={jsonrpc:"2.0",id:e,method:"tools/call",params:{name:"browser_stop_video",arguments:{}}};try{g.stdin.write(JSON.stringify(n)+`
7
+ `),i("\u{1F3AC} Auto-stopped video recording")}catch(r){D.delete(e),i(`\u26A0\uFE0F browser_stop_video send failed: ${r.message}`)}}const ge=2e3,be=5e3,K="frames";let X=0,we=1e6;const R=new Set;let k=null;function L(){k&&(clearInterval(k),k=null)}function $e(){if(o)try{S.mkdirSync(f.join(o,K),{recursive:!0})}catch{}}function J(){return f.join(o,K,`live-frame-${Date.now()}.png`)}function ye(){L(),!(!$||!o)&&(k=setInterval(()=>{if(!$||!o){L();return}ee(!0,J())},be))}function ee(e,n){if(!o||!$)return;$e();const r=Date.now();if(!e&&r-X<ge)return;X=r;const s=n||J(),t=we++;R.add(t);const a={jsonrpc:"2.0",id:t,method:"tools/call",params:{name:"browser_take_screenshot",arguments:{type:"png",filename:s}}};try{g.stdin.write(JSON.stringify(a)+`
8
+ `),i(`\u{1F4F8} live-frame queued: ${s}`)}catch(l){R.delete(t),i(`\u26A0\uFE0F live-frame send failed: ${l.message}`)}}function Ee(e){!e||typeof e!="string"||!e.startsWith("browser_")||e==="browser_close"||e==="browser_take_screenshot"||!o||!$||ee(!1,J())}const B=new Map;let Ne=9e5;const V=new Map;let T="";process.stdin.on("data",e=>{T+=e.toString();const n=T.split(`
9
+ `);T=n.pop()||"";for(const r of n)if(r.trim()){try{const s=JSON.parse(r);if(s.method&&i(`\u{1F4E8} STDIN: ${s.method} ${s.params?.name||""}`),s.method==="tools/call"&&s.params){const t=s.params.name,a=s.params.arguments||{};B.set(s.id,{toolName:t,toolArgs:a});let l=-1;t==="browser_navigate"?($=!0,ye(),l=y("navigate",{url:a.url})):t==="browser_click"?l=y("click",{element:a.element,ref:a.ref}):t==="browser_type"?l=y("type",{element:a.element,ref:a.ref,text:a.text}):t==="browser_select_option"?l=y("select",{element:a.element,ref:a.ref,values:a.values}):t==="browser_fill_form"?l=y("fill_form",{fields:a.fields}):t==="browser_hover"?l=y("hover",{element:a.element,ref:a.ref}):t==="browser_close"?(Ie(),l=y("close",{}),$=!1,L()):t==="browser_snapshot"&&(l=y("snapshot",{})),l>=0&&(B.get(s.id).eventId=l)}}catch{}g.stdin.write(r+`
10
+ `)}}),process.stdin.on("end",()=>{T.trim()&&g.stdin.write(T+`
11
+ `),g.stdin.end()});let F="";g.stdout.on("data",e=>{F+=e.toString();const n=F.split(`
12
+ `);F=n.pop()||"";for(const r of n){if(!r.trim())continue;let s=!0;try{const t=JSON.parse(r);if(t.id&&D.has(t.id))D.delete(t.id),t.error&&i(`\u26A0\uFE0F Video RPC error: ${t.error?.message||JSON.stringify(t.error)}`),s=!1;else if(t.id&&R.has(t.id))R.delete(t.id),t.error&&i(`\u26A0\uFE0F Screenshot RPC error: ${t.error?.message||JSON.stringify(t.error)}`),s=!1;else if(t.id&&B.has(t.id)){const a=B.get(t.id);if(B.delete(t.id),!t.error&&$&&Ee(a.toolName),!t.error&&a.toolName==="browser_navigate"&&he(),!t.error&&$&&a.eventId>=0&&["browser_click","browser_type","browser_select_option","browser_fill_form","browser_hover"].includes(a.toolName)){const I=Ne++,E={jsonrpc:"2.0",id:I,method:"tools/call",params:{name:"browser_evaluate",arguments:{function:"() => { const match = document.cookie.match(/(?:^|; )__zibbyLastStableId=([^;]*)/); const id = match ? decodeURIComponent(match[1]) : (window.__zibbyLastStableId || null); return id; }"}}};i(`\u{1F50D} Querying stable ID for event #${a.eventId}`),V.set(I,{eventId:a.eventId}),g.stdin.write(JSON.stringify(E)+`
13
+ `)}}if(t.id&&V.has(t.id)){const a=V.get(t.id);if(V.delete(t.id),i(`\u{1F4E5} Stable ID response for event #${a.eventId}: ${JSON.stringify(t.result||t.error||"no result").slice(0,200)}`),t.result?.content?.[0]?.text){const l=t.result.content[0].text,I=l.match(/zibby-[a-zA-Z0-9-]+/);I?(i(`\u2705 Found stable ID: ${I[0]}`),ue(a.eventId,I[0])):i(`\u26A0\uFE0F No stable ID found in: ${l.slice(0,100)}`)}else t.error&&i(`\u274C Stable ID query error: ${t.error?.message||JSON.stringify(t.error)}`);s=!1}}catch{}s&&process.stdout.write(r+`
14
+ `)}}),g.on("close",e=>{L(),$=!1,F.trim()&&process.stdout.write(F),process.exit(e||0)}),process.on("SIGINT",()=>{g.kill("SIGINT")}),process.on("SIGTERM",()=>{g.kill("SIGTERM")});
package/dist/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@zibby/mcp-browser",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Wrapper for @playwright/mcp with stable ID support and event recording",
5
5
  "type": "commonjs",
6
- "main": "bin/mcp-browser-zibby.js",
6
+ "main": "dist/bin/mcp-browser-zibby.js",
7
7
  "bin": {
8
- "mcp-browser-zibby": "bin/mcp-browser-zibby.js"
8
+ "mcp-browser-zibby": "dist/bin/mcp-browser-zibby.js"
9
9
  },
10
10
  "files": [
11
- "bin/",
12
- "src/",
11
+ "dist/",
13
12
  "README.md",
14
13
  "LICENSE"
15
14
  ],
@@ -41,7 +40,7 @@
41
40
  },
42
41
  "license": "MIT",
43
42
  "author": "Zibby",
44
- "homepage": "https://zibby.app",
43
+ "homepage": "https://zibby.dev",
45
44
  "devDependencies": {
46
45
  "esbuild": "^0.28.0"
47
46
  }
@@ -1 +1 @@
1
- (function(){if(window.__zibbyInitialized)return;window.__zibbyInitialized=!0;function y(t){if(t.getAttribute("aria-label"))return t.getAttribute("aria-label").trim();const e=t.getAttribute("aria-labelledby");if(e){const n=document.getElementById(e);if(n)return n.textContent.trim()}if(t.id){const n=document.querySelector(`label[for="${t.id}"]`);if(n)return n.textContent.trim()}const o=t.closest("label");if(o){const n=o.cloneNode(!0);n.querySelectorAll("input, select, textarea").forEach(c=>c.remove());const a=n.textContent.trim();if(a)return a}if(t.placeholder)return t.placeholder;const r=t.tagName.toLowerCase();return r==="button"||r==="a"||t.getAttribute("role")==="button"?(t.textContent||"").trim().slice(0,50):t.title?t.title:r==="input"&&(t.type==="submit"||t.type==="button")&&t.value||""}function p(t){const e=[],o=t.closest("form");if(o)if(o.id)e.push("form#"+o.id);else if(o.name)e.push("form[name="+o.name+"]");else if(o.action)try{const i=new URL(o.action,window.location.origin).pathname;e.push("form[action="+i+"]")}catch{e.push("form[action="+o.getAttribute("action")+"]")}else{const i=document.querySelectorAll("form"),s=Array.from(i).indexOf(o);e.push("form:nth("+s+")")}const r=t.closest('header, nav, main, footer, aside, [role="banner"], [role="navigation"], [role="main"], [role="contentinfo"]');if(r){const i=r.tagName.toLowerCase(),s=r.getAttribute("role");e.push(s||i)}const n=t.closest('section, article, [role="region"]');if(n){const i=n.querySelector("h1, h2, h3, h4, h5, h6");i&&e.push("section:"+i.textContent.trim().slice(0,30))}const a=t.closest("fieldset");if(a){const i=a.querySelector("legend");i&&e.push("fieldset:"+i.textContent.trim())}const c=t.closest('dialog, [role="dialog"], [role="alertdialog"]');if(c){const i=c.querySelector('[role="heading"], h1, h2, h3');i?e.push("dialog:"+i.textContent.trim().slice(0,30)):e.push("dialog")}return e.join("/")}function f(t){const e=t.tagName.toLowerCase(),o=t.id||"",r=t.name||"",n=t.type||"",a=t.getAttribute("role")||"";let c="";if(t.href)try{c=new URL(t.href,window.location.origin).pathname.slice(0,50)}catch{c=t.getAttribute("href")?.slice(0,50)||""}const i=y(t).slice(0,50).replace(/\s+/g," "),s=p(t),h=[e,o,r,n,a,c,i,s].join("|");let l=5381;for(let b=0;b<h.length;b++)l=(l<<5)+l^h.charCodeAt(b);return"zibby-"+(l>>>0).toString(36)}function m(){if(!document.body)return;const t=["button","a","input","select","textarea","label[for]",'[role="button"]','[role="link"]','[role="textbox"]','[role="checkbox"]','[role="radio"]','[role="combobox"]','[role="menuitem"]','[role="tab"]','[role="option"]','[role="switch"]','[role="slider"]',"[onclick]","[data-action]"].join(", "),e=new Map;try{document.querySelectorAll(t).forEach(o=>{const r=window.getComputedStyle(o);if(r.display==="none"||r.visibility==="hidden")return;let n=f(o);const a=n,c=e.get(a)||0;c>0&&(n=a+"-"+c),e.set(a,c+1),o.setAttribute("data-zibby-id",n)})}catch(o){console.error("[Zibby] Error injecting stable IDs:",o)}}function g(){if(!document.body&&document.readyState==="loading"){document.addEventListener("DOMContentLoaded",g);return}m();const t=new MutationObserver(()=>{requestAnimationFrame(m)});document.body&&t.observe(document.body,{childList:!0,subtree:!0})}window.__zibbyGetStableId=function(t){return t?.getAttribute("data-zibby-id")||null};function w(){const t=window.location.hostname.split(".");return t.length>=2?"."+t.slice(-2).join("."):window.location.hostname}Object.defineProperty(window,"__zibbyLastStableId",{get:function(){const t=document.cookie.match(/(?:^|; )__zibbyLastStableId=([^;]*)/);return t?decodeURIComponent(t[1]):null},set:function(t){if(t){const e=w();document.cookie=`__zibbyLastStableId=${encodeURIComponent(t)}; domain=${e}; path=/; max-age=3600; SameSite=Lax`}}});function d(t){const e=t.closest("[data-zibby-id]");if(e)return e;const o=t.closest("label");if(o){if(o.htmlFor){const a=document.getElementById(o.htmlFor);if(a?.getAttribute("data-zibby-id"))return a}const n=o.querySelector('input, select, textarea, [role="checkbox"], [role="radio"]');if(n?.getAttribute("data-zibby-id"))return n}const r=t.closest('[class*="select"], [class*="dropdown"], [class*="checkbox"], [class*="radio"]');if(r){const n=r.querySelector("[data-zibby-id]");if(n)return n}return null}function u(t){if(!t)return null;const e=t.getAttribute("data-zibby-id");if(e)return e;const o=f(t);return t.setAttribute("data-zibby-id",o),o}document.addEventListener("click",t=>{let e=d(t.target);!e&&t.target.matches('button, a, input, select, textarea, [role="button"], [onclick]')&&(e=t.target),e&&(window.__zibbyLastStableId=u(e))},!0),document.addEventListener("focusin",t=>{let e=d(t.target);!e&&t.target.matches('input, select, textarea, [role="textbox"], [role="combobox"]')&&(e=t.target),e&&(window.__zibbyLastStableId=u(e))},!0),document.addEventListener("change",t=>{let e=d(t.target);e||(e=t.target),e&&(window.__zibbyLastStableId=u(e))},!0),g()})();
1
+ (function(){if(window.__zibbyInitialized)return;window.__zibbyInitialized=!0;function y(t){if(t.getAttribute("aria-label"))return t.getAttribute("aria-label").trim();let e=t.getAttribute("aria-labelledby");if(e){let n=document.getElementById(e);if(n)return n.textContent.trim()}if(t.id){let n=document.querySelector(`label[for="${t.id}"]`);if(n)return n.textContent.trim()}let o=t.closest("label");if(o){let n=o.cloneNode(!0);n.querySelectorAll("input, select, textarea").forEach(c=>c.remove());let a=n.textContent.trim();if(a)return a}if(t.placeholder)return t.placeholder;let r=t.tagName.toLowerCase();return r==="button"||r==="a"||t.getAttribute("role")==="button"?(t.textContent||"").trim().slice(0,50):t.title?t.title:r==="input"&&(t.type==="submit"||t.type==="button")&&t.value||""}function p(t){let e=[],o=t.closest("form");if(o)if(o.id)e.push("form#"+o.id);else if(o.name)e.push("form[name="+o.name+"]");else if(o.action)try{let i=new URL(o.action,window.location.origin).pathname;e.push("form[action="+i+"]")}catch{e.push("form[action="+o.getAttribute("action")+"]")}else{let i=document.querySelectorAll("form"),s=Array.from(i).indexOf(o);e.push("form:nth("+s+")")}let r=t.closest('header, nav, main, footer, aside, [role="banner"], [role="navigation"], [role="main"], [role="contentinfo"]');if(r){let i=r.tagName.toLowerCase(),s=r.getAttribute("role");e.push(s||i)}let n=t.closest('section, article, [role="region"]');if(n){let i=n.querySelector("h1, h2, h3, h4, h5, h6");i&&e.push("section:"+i.textContent.trim().slice(0,30))}let a=t.closest("fieldset");if(a){let i=a.querySelector("legend");i&&e.push("fieldset:"+i.textContent.trim())}let c=t.closest('dialog, [role="dialog"], [role="alertdialog"]');if(c){let i=c.querySelector('[role="heading"], h1, h2, h3');i?e.push("dialog:"+i.textContent.trim().slice(0,30)):e.push("dialog")}return e.join("/")}function f(t){let e=t.tagName.toLowerCase(),o=t.id||"",r=t.name||"",n=t.type||"",a=t.getAttribute("role")||"",c="";if(t.href)try{c=new URL(t.href,window.location.origin).pathname.slice(0,50)}catch{c=t.getAttribute("href")?.slice(0,50)||""}let i=y(t).slice(0,50).replace(/\s+/g," "),s=p(t),h=[e,o,r,n,a,c,i,s].join("|"),l=5381;for(let b=0;b<h.length;b++)l=(l<<5)+l^h.charCodeAt(b);return"zibby-"+(l>>>0).toString(36)}function m(){if(!document.body)return;let t=["button","a","input","select","textarea","label[for]",'[role="button"]','[role="link"]','[role="textbox"]','[role="checkbox"]','[role="radio"]','[role="combobox"]','[role="menuitem"]','[role="tab"]','[role="option"]','[role="switch"]','[role="slider"]',"[onclick]","[data-action]"].join(", "),e=new Map;try{document.querySelectorAll(t).forEach(o=>{let r=window.getComputedStyle(o);if(r.display==="none"||r.visibility==="hidden")return;let n=f(o),a=n,c=e.get(a)||0;c>0&&(n=a+"-"+c),e.set(a,c+1),o.setAttribute("data-zibby-id",n)})}catch(o){console.error("[Zibby] Error injecting stable IDs:",o)}}function g(){if(!document.body&&document.readyState==="loading"){document.addEventListener("DOMContentLoaded",g);return}m();let t=new MutationObserver(()=>{requestAnimationFrame(m)});document.body&&t.observe(document.body,{childList:!0,subtree:!0})}window.__zibbyGetStableId=function(t){return t?.getAttribute("data-zibby-id")||null};function w(){let t=window.location.hostname.split(".");return t.length>=2?"."+t.slice(-2).join("."):window.location.hostname}Object.defineProperty(window,"__zibbyLastStableId",{get:function(){let t=document.cookie.match(/(?:^|; )__zibbyLastStableId=([^;]*)/);return t?decodeURIComponent(t[1]):null},set:function(t){if(t){let e=w();document.cookie=`__zibbyLastStableId=${encodeURIComponent(t)}; domain=${e}; path=/; max-age=3600; SameSite=Lax`}}});function d(t){let e=t.closest("[data-zibby-id]");if(e)return e;let o=t.closest("label");if(o){if(o.htmlFor){let a=document.getElementById(o.htmlFor);if(a?.getAttribute("data-zibby-id"))return a}let n=o.querySelector('input, select, textarea, [role="checkbox"], [role="radio"]');if(n?.getAttribute("data-zibby-id"))return n}let r=t.closest('[class*="select"], [class*="dropdown"], [class*="checkbox"], [class*="radio"]');if(r){let n=r.querySelector("[data-zibby-id]");if(n)return n}return null}function u(t){if(!t)return null;let e=t.getAttribute("data-zibby-id");if(e)return e;let o=f(t);return t.setAttribute("data-zibby-id",o),o}document.addEventListener("click",t=>{let e=d(t.target);!e&&t.target.matches('button, a, input, select, textarea, [role="button"], [onclick]')&&(e=t.target),e&&(window.__zibbyLastStableId=u(e))},!0),document.addEventListener("focusin",t=>{let e=d(t.target);!e&&t.target.matches('input, select, textarea, [role="textbox"], [role="combobox"]')&&(e=t.target),e&&(window.__zibbyLastStableId=u(e))},!0),document.addEventListener("change",t=>{let e=d(t.target);e||(e=t.target),e&&(window.__zibbyLastStableId=u(e))},!0),g()})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/mcp-browser",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Wrapper for @playwright/mcp with stable ID support and event recording",
5
5
  "type": "commonjs",
6
6
  "main": "dist/bin/mcp-browser-zibby.js",
@@ -8,7 +8,6 @@
8
8
  "mcp-browser-zibby": "dist/bin/mcp-browser-zibby.js"
9
9
  },
10
10
  "files": [
11
- "dist/bin/",
12
11
  "dist/",
13
12
  "README.md",
14
13
  "LICENSE"
@@ -41,7 +40,7 @@
41
40
  },
42
41
  "license": "MIT",
43
42
  "author": "Zibby",
44
- "homepage": "https://zibby.app",
43
+ "homepage": "https://zibby.dev",
45
44
  "devDependencies": {
46
45
  "esbuild": "^0.28.0"
47
46
  }