sliccy 1.45.0 → 1.47.0
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.
- package/dist/ui/assets/{bsh-watchdog-DOU_MEY1.js → bsh-watchdog-CQMLMgnM.js} +42 -1
- package/dist/ui/assets/{cdp-DhV8bm4P.js → cdp-D7T7EeS9.js} +14 -2
- package/dist/ui/assets/{index-GgBfVMPy.js → index-Bz9k6iOo.js} +782 -581
- package/dist/ui/assets/lick-manager-GREmMVtO.js +1 -0
- package/dist/ui/assets/provider-settings-Bkf2ADq8.js +1 -0
- package/dist/ui/assets/shell-DT3Tu0xL.js +1 -0
- package/dist/ui/assets/sprinkle-renderer-C3k5w6Bs.js +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/ui/packages/webapp/index.html +2 -2
- package/package.json +1 -1
- package/dist/ui/assets/lick-manager-Cm93KfGK.js +0 -1
- package/dist/ui/assets/provider-settings-YOjGG5m2.js +0 -1
- package/dist/ui/assets/shell-o0ztF_0C.js +0 -1
- package/dist/ui/assets/sprinkle-renderer-Dlqdvfe5.js +0 -1
|
@@ -1,2 +1,43 @@
|
|
|
1
1
|
import{t as e}from"./logger-B-No_qN_.js";var t=[`/workspace`,`/shared`];async function n(e){let n=[],i=new Set;for(let a of t)await e.exists(a)&&await r(e,a,n,i);return n}async function r(e,t,n,r){for await(let o of e.walk(t)){if(!o.endsWith(`.bsh`)||r.has(o))continue;r.add(o);let t=i(o);if(!t)continue;let s=await e.readFile(o,{encoding:`utf-8`}),c=a(typeof s==`string`?s:new TextDecoder().decode(s));n.push({path:o,hostnamePattern:t,matchPatterns:c})}}function i(e){let t=e.split(`/`).pop()??``;if(!t.endsWith(`.bsh`))return null;let n=t.slice(0,-4);return n?n.startsWith(`-.`)?`*`+n.slice(1):n:null}function a(e){let t=e.split(`
|
|
2
|
-
`).slice(0,10),n=[];for(let e of t){let t=e.match(/^\s*\/\/\s*@match\s+(.+)$/);t&&n.push(t[1].trim())}return n}function o(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e===t.slice(2)||e.endsWith(n)&&e.length>n.length}return e===t}function s(e,t){try{let n=new URL(e),r=t.match(/^(\*|https?):\/\/([^/]+)(\/.*)?$/);if(!r)return!1;let[,i,a,s]=r;return i!==`*`&&n.protocol.slice(0,-1)!==i||!o(n.hostname,a)?!1:s?c(n.pathname+n.search,s):!0}catch{return!1}}function c(e,t){let n=`^`+t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)+`$`;return new RegExp(n).test(e)}function l(e,t){try{let n=new URL(t);return e.filter(e=>o(n.hostname,e.hostnamePattern)?e.matchPatterns.length>0?e.matchPatterns.some(e=>s(t,e)):!0:!1)}catch{return[]}}var u=e(`bsh-watchdog`),d=class{transport;browserAPI;fs;discoveryIntervalMs;entries=[];discoveryTimer=null;running=!1;executing=new Set;constructor(e){if(!e.transport&&!e.browserAPI)throw Error(`BshWatchdog requires either transport or browserAPI`);this.browserAPI=e.browserAPI,this.transport=e.transport??e.browserAPI.getTransport(),this.fs=e.fs,this.discoveryIntervalMs=e.discoveryIntervalMs??1e4}async start(){this.running||(this.running=!0,await this.discover(),this.discoveryTimer=setInterval(()=>{this.discover()},this.discoveryIntervalMs),this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),this.browserAPI&&this.browserAPI.setSessionChangeCallback((e,t)=>{t!==this.transport&&this.setTransport(t)}),u.info(`BSH watchdog started`,{scriptCount:this.entries.length}))}stop(){this.running&&(this.running=!1,this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.discoveryTimer&&=(clearInterval(this.discoveryTimer),null),this.browserAPI&&this.browserAPI.setSessionChangeCallback(void 0),this.entries=[],this.executing.clear(),u.info(`BSH watchdog stopped`))}setTransport(e){e!==this.transport&&(this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.transport=e,this.running&&this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),u.info(`BSH watchdog transport swapped`))}async discover(){try{this.entries=await n(this.fs),u.debug(`BSH discovery complete`,{count:this.entries.length})}catch(e){u.error(`BSH discovery failed`,{error:e instanceof Error?e.message:String(e)})}}getEntries(){return this.entries}onFrameNavigated=e=>{let t=e.frame;if(t?.parentId||!t?.url)return;let n=t.url,r=e.sessionId;if(!n.startsWith(`http://`)&&!n.startsWith(`https://`))return;if(!r){u.warn(`BSH watchdog: no sessionId in Page.frameNavigated params, skipping`,{url:n});return}if(this.entries.length===0)return;let i=l(this.entries,n);if(i.length!==0)for(let e of i){let t=`${e.path}::${n}`;this.executing.has(t)||(this.executing.add(t),u.info(`BSH watchdog executing script`,{script:e.path,url:n}),this.executeInTargetPage(e.path,n,r).then(()=>{u.info(`BSH script completed`,{script:e.path,url:n})}).catch(t=>{u.error(`BSH script execution error`,{script:e.path,url:n,error:t instanceof Error?t.message:String(t)})}).finally(()=>{this.executing.delete(t)}))}};async executeInTargetPage(e,t,n){let r=await this.fs.readFile(e),i
|
|
2
|
+
`).slice(0,10),n=[];for(let e of t){let t=e.match(/^\s*\/\/\s*@match\s+(.+)$/);t&&n.push(t[1].trim())}return n}function o(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e===t.slice(2)||e.endsWith(n)&&e.length>n.length}return e===t}function s(e,t){try{let n=new URL(e),r=t.match(/^(\*|https?):\/\/([^/]+)(\/.*)?$/);if(!r)return!1;let[,i,a,s]=r;return i!==`*`&&n.protocol.slice(0,-1)!==i||!o(n.hostname,a)?!1:s?c(n.pathname+n.search,s):!0}catch{return!1}}function c(e,t){let n=`^`+t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)+`$`;return new RegExp(n).test(e)}function l(e,t){try{let n=new URL(t);return e.filter(e=>o(n.hostname,e.hostnamePattern)?e.matchPatterns.length>0?e.matchPatterns.some(e=>s(t,e)):!0:!1)}catch{return[]}}var u=e(`bsh-watchdog`),d=class{transport;browserAPI;fs;discoveryIntervalMs;entries=[];discoveryTimer=null;running=!1;executing=new Set;constructor(e){if(!e.transport&&!e.browserAPI)throw Error(`BshWatchdog requires either transport or browserAPI`);this.browserAPI=e.browserAPI,this.transport=e.transport??e.browserAPI.getTransport(),this.fs=e.fs,this.discoveryIntervalMs=e.discoveryIntervalMs??1e4}async start(){this.running||(this.running=!0,await this.discover(),this.discoveryTimer=setInterval(()=>{this.discover()},this.discoveryIntervalMs),this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),this.browserAPI&&this.browserAPI.setSessionChangeCallback((e,t)=>{t!==this.transport&&this.setTransport(t)}),u.info(`BSH watchdog started`,{scriptCount:this.entries.length}))}stop(){this.running&&(this.running=!1,this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.discoveryTimer&&=(clearInterval(this.discoveryTimer),null),this.browserAPI&&this.browserAPI.setSessionChangeCallback(void 0),this.entries=[],this.executing.clear(),u.info(`BSH watchdog stopped`))}setTransport(e){e!==this.transport&&(this.transport.off(`Page.frameNavigated`,this.onFrameNavigated),this.transport=e,this.running&&this.transport.on(`Page.frameNavigated`,this.onFrameNavigated),u.info(`BSH watchdog transport swapped`))}async discover(){try{this.entries=await n(this.fs),u.debug(`BSH discovery complete`,{count:this.entries.length})}catch(e){u.error(`BSH discovery failed`,{error:e instanceof Error?e.message:String(e)})}}getEntries(){return this.entries}onFrameNavigated=e=>{let t=e.frame;if(t?.parentId||!t?.url)return;let n=t.url,r=e.sessionId;if(!n.startsWith(`http://`)&&!n.startsWith(`https://`))return;if(!r){u.warn(`BSH watchdog: no sessionId in Page.frameNavigated params, skipping`,{url:n});return}if(this.entries.length===0)return;let i=l(this.entries,n);if(i.length!==0)for(let e of i){let t=`${e.path}::${n}`;this.executing.has(t)||(this.executing.add(t),u.info(`BSH watchdog executing script`,{script:e.path,url:n}),this.executeInTargetPage(e.path,n,r).then(()=>{u.info(`BSH script completed`,{script:e.path,url:n})}).catch(t=>{u.error(`BSH script execution error`,{script:e.path,url:n,error:t instanceof Error?t.message:String(t)})}).finally(()=>{this.executing.delete(t)}))}};async executeInTargetPage(e,t,n){let r=await this.fs.readFile(e),i=typeof r==`string`?r:new TextDecoder().decode(r),a=`(async () => {
|
|
3
|
+
const __requireSpecifiers = (function() {
|
|
4
|
+
const re = /require\\s*\\(\\s*['"]([^'"]+)['"]\\s*\\)/g;
|
|
5
|
+
const code = ${JSON.stringify(i)};
|
|
6
|
+
const specs = [];
|
|
7
|
+
let m;
|
|
8
|
+
while ((m = re.exec(code)) !== null) specs.push(m[1]);
|
|
9
|
+
return [...new Set(specs)];
|
|
10
|
+
})();
|
|
11
|
+
const __NODE_BUILTINS_UNAVAILABLE = new Set([
|
|
12
|
+
'http', 'https', 'net', 'tls', 'dgram', 'dns', 'cluster',
|
|
13
|
+
'worker_threads', 'child_process', 'crypto', 'os', 'stream',
|
|
14
|
+
'zlib', 'vm', 'v8', 'perf_hooks', 'readline', 'repl', 'tty', 'inspector',
|
|
15
|
+
'fs'
|
|
16
|
+
]);
|
|
17
|
+
const __requireCache = Object.create(null);
|
|
18
|
+
const __uncached = __requireSpecifiers.filter(id => {
|
|
19
|
+
const bare = id.startsWith('node:') ? id.slice(5) : id;
|
|
20
|
+
return !__NODE_BUILTINS_UNAVAILABLE.has(bare) && bare !== 'buffer';
|
|
21
|
+
});
|
|
22
|
+
await Promise.allSettled(__uncached.map(async (id) => {
|
|
23
|
+
try {
|
|
24
|
+
const mod = await import('https://esm.sh/' + id);
|
|
25
|
+
__requireCache[id] = mod.default !== undefined ? mod.default : mod;
|
|
26
|
+
} catch(e) { /* will throw at require() call time */ }
|
|
27
|
+
}));
|
|
28
|
+
const require = (id) => {
|
|
29
|
+
const bareId = id.startsWith('node:') ? id.slice(5) : id;
|
|
30
|
+
if (bareId === 'buffer' && typeof Buffer !== 'undefined') return { Buffer };
|
|
31
|
+
if (__NODE_BUILTINS_UNAVAILABLE.has(bareId)) {
|
|
32
|
+
const __suggestions = { http: ' Use fetch() instead.', https: ' Use fetch() instead.', crypto: ' Use globalThis.crypto (Web Crypto API) instead.' };
|
|
33
|
+
const __hint = __suggestions[bareId] || '';
|
|
34
|
+
throw new Error("require('" + id + "'): Node built-in '" + bareId + "' is not available in the browser environment." + __hint);
|
|
35
|
+
}
|
|
36
|
+
if (bareId in __requireCache) return __requireCache[bareId];
|
|
37
|
+
if (id in __requireCache) return __requireCache[id];
|
|
38
|
+
throw new Error("require('" + id + "'): module not pre-loaded. Use a string literal or await import('https://esm.sh/" + id + "') directly.");
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
${i}
|
|
42
|
+
} catch(e) { console.error('[bsh]', e); }
|
|
43
|
+
})()`;await this.transport.send(`Runtime.enable`,{},n);let o=(await this.transport.send(`Runtime.evaluate`,{expression:a,awaitPromise:!0,returnByValue:!0},n)).exceptionDetails;if(o){let n=o.exception?.description??o.text;u.warn(`BSH script evaluation error`,{script:e,url:t,error:n})}}};export{d as BshWatchdog};
|
|
@@ -708,6 +708,18 @@ import{r as e}from"./chunk-zsgVPwQN.js";import{t}from"./logger-B-No_qN_.js";impo
|
|
|
708
708
|
// If not visible for aria, skip entirely (including children)
|
|
709
709
|
if (!visible) return;
|
|
710
710
|
|
|
711
|
+
// Emit placeholder for iframes/frames — don't recurse into their document
|
|
712
|
+
if (element.nodeName === 'IFRAME' || element.nodeName === 'FRAME') {
|
|
713
|
+
var iframeNode = {
|
|
714
|
+
role: 'iframe',
|
|
715
|
+
name: element.getAttribute('title') || element.getAttribute('name') || '',
|
|
716
|
+
children: [],
|
|
717
|
+
value: element.getAttribute('src') || ''
|
|
718
|
+
};
|
|
719
|
+
ariaNode.children.push(iframeNode);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
|
|
711
723
|
var ariaChildren = [];
|
|
712
724
|
if (element.hasAttribute('aria-owns')) {
|
|
713
725
|
var ids = element.getAttribute('aria-owns').split(/\\s+/);
|
|
@@ -857,11 +869,11 @@ import{r as e}from"./chunk-zsgVPwQN.js";import{t}from"./logger-B-No_qN_.js";impo
|
|
|
857
869
|
} catch(e) {
|
|
858
870
|
return { role: 'RootWebArea', name: '', description: 'Error: ' + (e.message || String(e)) };
|
|
859
871
|
}
|
|
860
|
-
})()`,s=`ws://localhost:5710/cdp`,c=t(`browser-api`);function l(e=typeof window<`u`?window.location:null){return e?.host?`${e.protocol===`https:`?`wss:`:`ws:`}//${e.host}/cdp`:s}var u=class{client;localClient;sessionId=null;attachedTargetId=null;trayTargetProvider=null;remoteTargetInfo=null;_tabLock=Promise.resolve();_onSessionChange;handleJavaScriptDialogOpening=async e=>{let t=typeof e.sessionId==`string`?e.sessionId:this.sessionId;if(t)try{await this.client.send(`Page.handleJavaScriptDialog`,{accept:!1},t,5e3),c.warn(`Auto-dismissed unexpected JavaScript dialog`,{sessionId:t,type:e.type,message:e.message,url:e.url})}catch(e){c.warn(`Failed to auto-dismiss JavaScript dialog`,{sessionId:t,error:e instanceof Error?e.message:String(e)})}};constructor(e){this.client=e??new i,this.localClient=this.client,this.addDialogListener(this.client)}getTransport(){return this.client}setSessionChangeCallback(e){this._onSessionChange=e}getSessionId(){return this.sessionId}getAttachedTargetId(){return this.attachedTargetId}async withTab(e,t){let n,r=new Promise(e=>{n=e}),i=this._tabLock;this._tabLock=r,await i;try{return await t(await this.attachToPage(e))}finally{n()}}setTrayTargetProvider(e){this.trayTargetProvider=e}async listAllTargets(){let e=await this.listPages();if(!this.trayTargetProvider)return e;let t=!this.remoteTargetInfo,n=new Set(e.map(e=>e.targetId)),r=this.trayTargetProvider.getTargets().filter(e=>!t||!(e.runtimeId===`leader`&&n.has(e.localTargetId))).map(e=>({targetId:e.targetId,title:e.title,url:e.url}));return[...e,...r]}async connect(e){await this.client.connect({url:e?.url??l(),timeout:e?.timeout})}async createPage(e){return await this.ensureConnected(),await this.ensureLocalConnected(),(await this.localClient.send(`Target.createTarget`,{url:e??`about:blank`,background:!0})).targetId}async createRemotePage(e,t){if(!this.trayTargetProvider?.openRemoteTab)throw Error(`Remote tab opening not available (no tray target provider)`);return this.trayTargetProvider.openRemoteTab(e,t??`about:blank`)}async closePage(e){if(await this.ensureConnected(),this.trayTargetProvider?.createRemoteTransport&&e.includes(`:`)){let t=e.indexOf(`:`),n=e.substring(0,t),r=e.substring(t+1);{let t=this.trayTargetProvider.createRemoteTransport(n,r);try{await t.send(`Target.closeTarget`,{targetId:r})}finally{this.trayTargetProvider.removeRemoteTransport&&this.trayTargetProvider.removeRemoteTransport(n,r)}this.attachedTargetId===e&&(this.remoteTargetInfo&&=(this.setClient(this.localClient),null),this.sessionId=null,this.attachedTargetId=null);return}}await this.localClient.send(`Target.closeTarget`,{targetId:e}),this.attachedTargetId===e&&(this.sessionId=null,this.attachedTargetId=null)}disconnect(){this.sessionId=null,this.attachedTargetId=null,this.client.disconnect()}async listPages(){return await this.ensureConnected(),await this.ensureLocalConnected(),((await this.localClient.send(`Target.getTargets`)).targetInfos??[]).filter(e=>e.type===`page`).map(e=>({targetId:e.targetId,title:e.title,url:e.url,...e.active?{active:!0}:{}}))}async attachToPage(e){if(await this.ensureConnected(),this.sessionId&&this.attachedTargetId===e)return this.sessionId;if(this.trayTargetProvider?.createRemoteTransport&&e.includes(`:`)){let t=e.indexOf(`:`),n=e.substring(0,t),r=e.substring(t+1);{let t=this.trayTargetProvider.createRemoteTransport(n,r);return this.setClient(t),this.remoteTargetInfo={runtimeId:n,localTargetId:r},this.sessionId=(await this.client.send(`Target.attachToTarget`,{targetId:r,flatten:!0})).sessionId,this.attachedTargetId=e,await this.client.send(`Page.enable`,{},this.sessionId),this._onSessionChange?.(this.sessionId,this.client),this.sessionId}}return this.remoteTargetInfo&&=(this.trayTargetProvider?.removeRemoteTransport&&this.trayTargetProvider.removeRemoteTransport(this.remoteTargetInfo.runtimeId,this.remoteTargetInfo.localTargetId),this.setClient(this.localClient),null),await this.ensureLocalConnected(),this.sessionId=(await this.localClient.send(`Target.attachToTarget`,{targetId:e,flatten:!0})).sessionId,this.attachedTargetId=e,await this.localClient.send(`Page.enable`,{},this.sessionId),this._onSessionChange?.(this.sessionId,this.localClient),this.sessionId}async detach(){if(this.sessionId){try{await this.client.send(`Target.detachFromTarget`,{sessionId:this.sessionId})}catch{}this.remoteTargetInfo&&this.trayTargetProvider?.removeRemoteTransport&&(this.trayTargetProvider.removeRemoteTransport(this.remoteTargetInfo.runtimeId,this.remoteTargetInfo.localTargetId),this.setClient(this.localClient),this.remoteTargetInfo=null),this.sessionId=null,this.attachedTargetId=null}}async navigate(e){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`Page.enable`,{},this.sessionId);let t=this.client.once(`Page.loadEventFired`);await this.client.send(`Page.navigate`,{url:e},this.sessionId),await t}async screenshot(e){await this.ensureConnected(),this.ensureAttached();try{let t={format:e?.format??`png`,captureBeyondViewport:!0};if(e?.quality!==void 0&&(t.quality=e.quality),e?.clip||e?.fullPage){let n=0,r=0;try{await this.client.send(`Runtime.enable`,{},this.sessionId);let e=await this.client.send(`Runtime.evaluate`,{expression:`JSON.stringify({ w: window.innerWidth, h: document.documentElement.scrollHeight })`,returnByValue:!0},this.sessionId),t=JSON.parse(e.result?.value??`{}`);n=t.w??0,r=t.h??0}catch{}e?.clip?t.clip={...e.clip,scale:e.clip.scale??1}:t.clip={x:0,y:0,width:n||1280,height:r||800,scale:1}}let r;try{r=await this.client.send(`Page.captureScreenshot`,t,this.sessionId)}catch{await this.client.send(`Page.bringToFront`,{},this.sessionId),r=await this.client.send(`Page.captureScreenshot`,t,this.sessionId)}let i=r.data;if(e?.maxWidth)try{let{getMagick:t}=await n(async()=>{let{getMagick:e}=await import(`./magick-wasm-D_mriary.js`).then(e=>e.n);return{getMagick:e}},__vite__mapDeps([0,1,2])),r=await t(),a=atob(i),o=new Uint8Array(a.length);for(let e=0;e<a.length;e++)o[e]=a.charCodeAt(e);let s=8e3,c=!1;await r.ImageMagick.read(o,async t=>{let n=Math.min(e.maxWidth,s),r=Math.max(t.width,t.height);if(t.width>n||r>s){let e=Math.min(n/t.width,s/r);t.resize(Math.round(t.width*e),Math.round(t.height*e)),c=!0}c&&t.write(`PNG`,e=>{let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);i=btoa(t)})})}catch(e){console.warn(`[browser-api] Screenshot maxWidth resize failed, returning original`,e)}return i}finally{}}async evaluate(e,t){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`Runtime.enable`,{},this.sessionId);let n=await this.client.send(`Runtime.evaluate`,{expression:e,awaitPromise:t?.awaitPromise??!0,returnByValue:t?.returnByValue??!0},this.sessionId),r=n.exceptionDetails;if(r){let e=r.exception?.description??r.text;throw Error(`Evaluation failed: ${e}`)}return n.result.value}async click(e){await this.ensureConnected(),this.ensureAttached();let t=await this.boundingBox(e);if(!t)throw Error(`Element not found: ${e}`);let n=t.x+t.width/2,r=t.y+t.height/2;await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n,y:r,button:`left`,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:n,y:r,button:`left`,clickCount:1},this.sessionId)}async type(e){await this.ensureConnected(),this.ensureAttached();for(let t of e)await this.client.send(`Input.dispatchKeyEvent`,{type:`keyDown`,text:t},this.sessionId),await this.client.send(`Input.dispatchKeyEvent`,{type:`keyUp`,text:t},this.sessionId)}async waitForSelector(e,t){await this.ensureConnected(),this.ensureAttached();let n=t?.timeout??3e4,r=t?.interval??100,i=Date.now();for(;Date.now()-i<n;){if(await this.evaluate(`!!document.querySelector(${JSON.stringify(e)})`))return;await new Promise(e=>setTimeout(e,r))}throw Error(`waitForSelector timed out after ${n}ms: ${e}`)}async getAccessibilityTree(){await this.ensureConnected(),this.ensureAttached();let e=await this.evaluate(o,{awaitPromise:!1,returnByValue:!0});return!e||typeof e!=`object`?{role:`RootWebArea`,name:``}:d(e)}async clickByBackendNodeId(e){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`DOM.enable`,{},this.sessionId),await this.client.send(`Runtime.enable`,{},this.sessionId);let t=(await this.client.send(`DOM.resolveNode`,{backendNodeId:e},this.sessionId)).object;if(!t?.objectId)throw Error(`Could not resolve backend node ${e} to a DOM element`);let n=(await this.client.send(`Runtime.callFunctionOn`,{objectId:t.objectId,functionDeclaration:`function() {
|
|
872
|
+
})()`,s=`ws://localhost:5710/cdp`,c=t(`browser-api`);function l(e=typeof window<`u`?window.location:null){return e?.host?`${e.protocol===`https:`?`wss:`:`ws:`}//${e.host}/cdp`:s}var u=class{client;localClient;sessionId=null;attachedTargetId=null;trayTargetProvider=null;remoteTargetInfo=null;_frameContextCache=new Map;_tabLock=Promise.resolve();_onSessionChange;handleJavaScriptDialogOpening=async e=>{let t=typeof e.sessionId==`string`?e.sessionId:this.sessionId;if(t)try{await this.client.send(`Page.handleJavaScriptDialog`,{accept:!1},t,5e3),c.warn(`Auto-dismissed unexpected JavaScript dialog`,{sessionId:t,type:e.type,message:e.message,url:e.url})}catch(e){c.warn(`Failed to auto-dismiss JavaScript dialog`,{sessionId:t,error:e instanceof Error?e.message:String(e)})}};constructor(e){this.client=e??new i,this.localClient=this.client,this.addDialogListener(this.client)}getTransport(){return this.client}setSessionChangeCallback(e){this._onSessionChange=e}getSessionId(){return this.sessionId}getAttachedTargetId(){return this.attachedTargetId}async withTab(e,t){let n,r=new Promise(e=>{n=e}),i=this._tabLock;this._tabLock=r,await i;try{return await t(await this.attachToPage(e))}finally{n()}}setTrayTargetProvider(e){this.trayTargetProvider=e}async listAllTargets(){let e=await this.listPages();if(!this.trayTargetProvider)return e;let t=!this.remoteTargetInfo,n=new Set(e.map(e=>e.targetId)),r=this.trayTargetProvider.getTargets().filter(e=>!t||!(e.runtimeId===`leader`&&n.has(e.localTargetId))).map(e=>({targetId:e.targetId,title:e.title,url:e.url}));return[...e,...r]}async connect(e){await this.client.connect({url:e?.url??l(),timeout:e?.timeout})}async createPage(e){return await this.ensureConnected(),await this.ensureLocalConnected(),(await this.localClient.send(`Target.createTarget`,{url:e??`about:blank`,background:!0})).targetId}async createRemotePage(e,t){if(!this.trayTargetProvider?.openRemoteTab)throw Error(`Remote tab opening not available (no tray target provider)`);return this.trayTargetProvider.openRemoteTab(e,t??`about:blank`)}async closePage(e){if(await this.ensureConnected(),this.trayTargetProvider?.createRemoteTransport&&e.includes(`:`)){let t=e.indexOf(`:`),n=e.substring(0,t),r=e.substring(t+1);{let t=this.trayTargetProvider.createRemoteTransport(n,r);try{await t.send(`Target.closeTarget`,{targetId:r})}finally{this.trayTargetProvider.removeRemoteTransport&&this.trayTargetProvider.removeRemoteTransport(n,r)}this.attachedTargetId===e&&(this.remoteTargetInfo&&=(this.setClient(this.localClient),null),this.sessionId=null,this.attachedTargetId=null);return}}await this.localClient.send(`Target.closeTarget`,{targetId:e}),this.attachedTargetId===e&&(this.sessionId=null,this.attachedTargetId=null)}disconnect(){this.sessionId=null,this.attachedTargetId=null,this.client.disconnect()}async listPages(){return await this.ensureConnected(),await this.ensureLocalConnected(),((await this.localClient.send(`Target.getTargets`)).targetInfos??[]).filter(e=>e.type===`page`).map(e=>({targetId:e.targetId,title:e.title,url:e.url,...e.active?{active:!0}:{}}))}async attachToPage(e){if(await this.ensureConnected(),this.sessionId&&this.attachedTargetId===e)return this.sessionId;if(this._frameContextCache.clear(),this.trayTargetProvider?.createRemoteTransport&&e.includes(`:`)){let t=e.indexOf(`:`),n=e.substring(0,t),r=e.substring(t+1);{let t=this.trayTargetProvider.createRemoteTransport(n,r);return this.setClient(t),this.remoteTargetInfo={runtimeId:n,localTargetId:r},this.sessionId=(await this.client.send(`Target.attachToTarget`,{targetId:r,flatten:!0})).sessionId,this.attachedTargetId=e,await this.client.send(`Page.enable`,{},this.sessionId),this._onSessionChange?.(this.sessionId,this.client),this.sessionId}}return this.remoteTargetInfo&&=(this.trayTargetProvider?.removeRemoteTransport&&this.trayTargetProvider.removeRemoteTransport(this.remoteTargetInfo.runtimeId,this.remoteTargetInfo.localTargetId),this.setClient(this.localClient),null),await this.ensureLocalConnected(),this.sessionId=(await this.localClient.send(`Target.attachToTarget`,{targetId:e,flatten:!0})).sessionId,this.attachedTargetId=e,await this.localClient.send(`Page.enable`,{},this.sessionId),this._onSessionChange?.(this.sessionId,this.localClient),this.sessionId}async detach(){if(this.sessionId){try{await this.client.send(`Target.detachFromTarget`,{sessionId:this.sessionId})}catch{}this.remoteTargetInfo&&this.trayTargetProvider?.removeRemoteTransport&&(this.trayTargetProvider.removeRemoteTransport(this.remoteTargetInfo.runtimeId,this.remoteTargetInfo.localTargetId),this.setClient(this.localClient),this.remoteTargetInfo=null),this.sessionId=null,this.attachedTargetId=null}}async navigate(e){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`Page.enable`,{},this.sessionId);let t=this.client.once(`Page.loadEventFired`);await this.client.send(`Page.navigate`,{url:e},this.sessionId),await t}async screenshot(e){await this.ensureConnected(),this.ensureAttached();try{let t={format:e?.format??`png`,captureBeyondViewport:!0};if(e?.quality!==void 0&&(t.quality=e.quality),e?.clip||e?.fullPage){let n=0,r=0;try{await this.client.send(`Runtime.enable`,{},this.sessionId);let e=await this.client.send(`Runtime.evaluate`,{expression:`JSON.stringify({ w: window.innerWidth, h: document.documentElement.scrollHeight })`,returnByValue:!0},this.sessionId),t=JSON.parse(e.result?.value??`{}`);n=t.w??0,r=t.h??0}catch{}e?.clip?t.clip={...e.clip,scale:e.clip.scale??1}:t.clip={x:0,y:0,width:n||1280,height:r||800,scale:1}}let r;try{r=await this.client.send(`Page.captureScreenshot`,t,this.sessionId)}catch{await this.client.send(`Page.bringToFront`,{},this.sessionId),r=await this.client.send(`Page.captureScreenshot`,t,this.sessionId)}let i=r.data;if(e?.maxWidth)try{let{getMagick:t}=await n(async()=>{let{getMagick:e}=await import(`./magick-wasm-D_mriary.js`).then(e=>e.n);return{getMagick:e}},__vite__mapDeps([0,1,2])),r=await t(),a=atob(i),o=new Uint8Array(a.length);for(let e=0;e<a.length;e++)o[e]=a.charCodeAt(e);let s=8e3,c=!1;await r.ImageMagick.read(o,async t=>{let n=Math.min(e.maxWidth,s),r=Math.max(t.width,t.height);if(t.width>n||r>s){let e=Math.min(n/t.width,s/r);t.resize(Math.round(t.width*e),Math.round(t.height*e)),c=!0}c&&t.write(`PNG`,e=>{let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);i=btoa(t)})})}catch(e){console.warn(`[browser-api] Screenshot maxWidth resize failed, returning original`,e)}return i}finally{}}async evaluate(e,t){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`Runtime.enable`,{},this.sessionId);let n=await this.client.send(`Runtime.evaluate`,{expression:e,awaitPromise:t?.awaitPromise??!0,returnByValue:t?.returnByValue??!0},this.sessionId),r=n.exceptionDetails;if(r){let e=r.exception?.description??r.text;throw Error(`Evaluation failed: ${e}`)}return n.result.value}async click(e){await this.ensureConnected(),this.ensureAttached();let t=await this.boundingBox(e);if(!t)throw Error(`Element not found: ${e}`);let n=t.x+t.width/2,r=t.y+t.height/2;await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n,y:r,button:`left`,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:n,y:r,button:`left`,clickCount:1},this.sessionId)}async type(e){await this.ensureConnected(),this.ensureAttached();for(let t of e)await this.client.send(`Input.dispatchKeyEvent`,{type:`keyDown`,text:t},this.sessionId),await this.client.send(`Input.dispatchKeyEvent`,{type:`keyUp`,text:t},this.sessionId)}async waitForSelector(e,t){await this.ensureConnected(),this.ensureAttached();let n=t?.timeout??3e4,r=t?.interval??100,i=Date.now();for(;Date.now()-i<n;){if(await this.evaluate(`!!document.querySelector(${JSON.stringify(e)})`))return;await new Promise(e=>setTimeout(e,r))}throw Error(`waitForSelector timed out after ${n}ms: ${e}`)}async getAccessibilityTree(){await this.ensureConnected(),this.ensureAttached();let e=await this.evaluate(o,{awaitPromise:!1,returnByValue:!0});return!e||typeof e!=`object`?{role:`RootWebArea`,name:``}:d(e)}async clickByBackendNodeId(e){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`DOM.enable`,{},this.sessionId),await this.client.send(`Runtime.enable`,{},this.sessionId);let t=(await this.client.send(`DOM.resolveNode`,{backendNodeId:e},this.sessionId)).object;if(!t?.objectId)throw Error(`Could not resolve backend node ${e} to a DOM element`);let n=(await this.client.send(`Runtime.callFunctionOn`,{objectId:t.objectId,functionDeclaration:`function() {
|
|
861
873
|
this.scrollIntoView({ block: 'center', inline: 'center' });
|
|
862
874
|
const r = this.getBoundingClientRect();
|
|
863
875
|
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
|
864
|
-
}`,returnByValue:!0},this.sessionId)).result?.value;if(!n||n.width===0||n.height===0){await this.client.send(`Runtime.callFunctionOn`,{objectId:t.objectId,functionDeclaration:`function() { this.click(); }`},this.sessionId);return}let r=n.x+n.width/2,i=n.y+n.height/2;await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:r,y:i,button:`left`,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:r,y:i,button:`left`,clickCount:1},this.sessionId)}async dblclickByBackendNodeId(e,t=`left`){await this.ensureConnected(),this.ensureAttached();let{x:n,y:r}=await this.resolveNodeCenter(e);await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n,y:r,button:t,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:n,y:r,button:t,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n,y:r,button:t,clickCount:2},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:n,y:r,button:t,clickCount:2},this.sessionId)}async hoverByBackendNodeId(e){await this.ensureConnected(),this.ensureAttached();let{x:t,y:n}=await this.resolveNodeCenter(e);await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseMoved`,x:t,y:n},this.sessionId)}async selectByBackendNodeId(e,t){await this.ensureConnected(),this.ensureAttached();let n=await this.resolveNodeObjectId(e);await this.client.send(`Runtime.callFunctionOn`,{objectId:n,functionDeclaration:`function(val) { this.value = val; this.dispatchEvent(new Event('change', { bubbles: true })); }`,arguments:[{value:t}],returnByValue:!0},this.sessionId)}async setCheckedByBackendNodeId(e,t){await this.ensureConnected(),this.ensureAttached();let n=await this.resolveNodeObjectId(e);return(await this.client.send(`Runtime.callFunctionOn`,{objectId:n,functionDeclaration:`function() { return this.checked; }`,returnByValue:!0},this.sessionId)).result?.value===t?`already`:(await this.clickByBackendNodeId(e),`toggled`)}async dragByBackendNodeIds(e,t){await this.ensureConnected(),this.ensureAttached();let n=await this.resolveNodeCenter(e),r=await this.resolveNodeCenter(t);await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n.x,y:n.y,button:`left`,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseMoved`,x:r.x,y:r.y},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:r.x,y:r.y,button:`left`,clickCount:1},this.sessionId)}async sendCDP(e,t={}){return await this.ensureConnected(),this.ensureAttached(),await this.client.send(e,t,this.sessionId)}async resolveNodeObjectId(e){await this.client.send(`DOM.enable`,{},this.sessionId),await this.client.send(`Runtime.enable`,{},this.sessionId);let t=(await this.client.send(`DOM.resolveNode`,{backendNodeId:e},this.sessionId)).object;if(!t?.objectId)throw Error(`Could not resolve backend node ${e} to a DOM element`);return t.objectId}async resolveNodeCenter(e){let t=await this.resolveNodeObjectId(e),n=(await this.client.send(`Runtime.callFunctionOn`,{objectId:t,functionDeclaration:`function() {
|
|
876
|
+
}`,returnByValue:!0},this.sessionId)).result?.value;if(!n||n.width===0||n.height===0){await this.client.send(`Runtime.callFunctionOn`,{objectId:t.objectId,functionDeclaration:`function() { this.click(); }`},this.sessionId);return}let r=n.x+n.width/2,i=n.y+n.height/2;await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:r,y:i,button:`left`,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:r,y:i,button:`left`,clickCount:1},this.sessionId)}async dblclickByBackendNodeId(e,t=`left`){await this.ensureConnected(),this.ensureAttached();let{x:n,y:r}=await this.resolveNodeCenter(e);await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n,y:r,button:t,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:n,y:r,button:t,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n,y:r,button:t,clickCount:2},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:n,y:r,button:t,clickCount:2},this.sessionId)}async hoverByBackendNodeId(e){await this.ensureConnected(),this.ensureAttached();let{x:t,y:n}=await this.resolveNodeCenter(e);await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseMoved`,x:t,y:n},this.sessionId)}async selectByBackendNodeId(e,t){await this.ensureConnected(),this.ensureAttached();let n=await this.resolveNodeObjectId(e);await this.client.send(`Runtime.callFunctionOn`,{objectId:n,functionDeclaration:`function(val) { this.value = val; this.dispatchEvent(new Event('change', { bubbles: true })); }`,arguments:[{value:t}],returnByValue:!0},this.sessionId)}async setCheckedByBackendNodeId(e,t){await this.ensureConnected(),this.ensureAttached();let n=await this.resolveNodeObjectId(e);return(await this.client.send(`Runtime.callFunctionOn`,{objectId:n,functionDeclaration:`function() { return this.checked; }`,returnByValue:!0},this.sessionId)).result?.value===t?`already`:(await this.clickByBackendNodeId(e),`toggled`)}async dragByBackendNodeIds(e,t){await this.ensureConnected(),this.ensureAttached();let n=await this.resolveNodeCenter(e),r=await this.resolveNodeCenter(t);await this.client.send(`Input.dispatchMouseEvent`,{type:`mousePressed`,x:n.x,y:n.y,button:`left`,clickCount:1},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseMoved`,x:r.x,y:r.y},this.sessionId),await this.client.send(`Input.dispatchMouseEvent`,{type:`mouseReleased`,x:r.x,y:r.y,button:`left`,clickCount:1},this.sessionId)}async getFrameTree(){await this.ensureConnected(),this.ensureAttached(),await this.client.send(`Page.enable`,{},this.sessionId);let e=(await this.client.send(`Page.getFrameTree`,{},this.sessionId)).frameTree,t=[],n=e=>{if(t.push({frameId:e.frame.id,parentFrameId:e.frame.parentId,url:e.frame.url,name:e.frame.name??``,securityOrigin:e.frame.securityOrigin}),Array.isArray(e.childFrames))for(let t of e.childFrames)n(t)};return n(e),t}async evaluateInFrame(e,t,n){await this.ensureConnected(),this.ensureAttached();let r=e=>{let t=e instanceof Error?e.message:String(e);return t.includes(`Cannot find context with specified id`)||t.includes(`Execution context was destroyed`)},i=async()=>{let t=(await this.client.send(`Page.createIsolatedWorld`,{frameId:e,worldName:`__slicc_iframe`},this.sessionId)).executionContextId;return this._frameContextCache.set(e,t),t},a=this._frameContextCache.get(e);if(a===void 0)try{a=await i()}catch(t){throw Error(`Failed to create isolated world for frame ${e}: ${t instanceof Error?t.message:String(t)}`)}await this.client.send(`Runtime.enable`,{},this.sessionId);let o={expression:t,contextId:a,awaitPromise:n?.awaitPromise??!0,returnByValue:n?.returnByValue??!0},s;try{s=await this.client.send(`Runtime.evaluate`,o,this.sessionId)}catch(t){if(r(t))this._frameContextCache.delete(e),a=await i(),s=await this.client.send(`Runtime.evaluate`,{...o,contextId:a},this.sessionId);else throw t}let c=s.exceptionDetails;if(c){let t=c.exception?.description??c.text;if(r(Error(t))){this._frameContextCache.delete(e),a=await i();let t=await this.client.send(`Runtime.evaluate`,{...o,contextId:a},this.sessionId),n=t.exceptionDetails;if(n){let t=n.exception?.description??n.text;throw Error(`Evaluation in frame ${e} failed: ${t}`)}return t.result.value}throw this._frameContextCache.delete(e),Error(`Evaluation in frame ${e} failed: ${t}`)}return s.result.value}async getAccessibilityTreeForFrame(e){if(!e)return this.getAccessibilityTree();await this.ensureConnected(),this.ensureAttached();let t=await this.evaluateInFrame(e,o,{awaitPromise:!1,returnByValue:!0});return!t||typeof t!=`object`?{role:`RootWebArea`,name:``}:d(t)}async sendCDP(e,t={}){return await this.ensureConnected(),this.ensureAttached(),await this.client.send(e,t,this.sessionId)}async resolveNodeObjectId(e){await this.client.send(`DOM.enable`,{},this.sessionId),await this.client.send(`Runtime.enable`,{},this.sessionId);let t=(await this.client.send(`DOM.resolveNode`,{backendNodeId:e},this.sessionId)).object;if(!t?.objectId)throw Error(`Could not resolve backend node ${e} to a DOM element`);return t.objectId}async resolveNodeCenter(e){let t=await this.resolveNodeObjectId(e),n=(await this.client.send(`Runtime.callFunctionOn`,{objectId:t,functionDeclaration:`function() {
|
|
865
877
|
this.scrollIntoView({ block: 'center', inline: 'center' });
|
|
866
878
|
const r = this.getBoundingClientRect();
|
|
867
879
|
return { x: r.x, y: r.y, width: r.width, height: r.height };
|