@@ -3,20 +3,19 @@ import type { Tab } from "@mcp-browser-kit/server/services/tab-service";
33import { addDevTool } from "./add-dev-tool" ;
44
55export const toIIFE = ( fn : Function | string ) => {
6-
7- if ( typeof fn === "function" ) {
6+ if ( typeof fn === "function" ) {
87 return `(${ fn . toString ( ) } )()` ;
98 }
109
1110 return `(()=>{${ fn } })()` ;
1211} ;
1312
14- export const getExecuteScriptResult = async ( results : any [ ] ) => {
13+ export const getExecuteScriptResult = async < T = any > ( results : any [ ] ) => {
1514 if ( ! Array . isArray ( results ) ) {
1615 return undefined ;
1716 }
1817
19- return results [ 0 ] ;
18+ return results [ 0 ] as T ;
2019} ;
2120
2221export const getTabs = async ( ) => {
@@ -70,7 +69,7 @@ function _elementsToTable(elements: HTMLElement[]) {
7069 el . getAttribute ( "placeholder" ) ??
7170 el . innerText ??
7271 "" ;
73- return [ tag , label ] as [ number , string , string ] ;
72+ return [ index , tag , label ] as [ number , string , string ] ;
7473 } ) ;
7574 return table ;
7675}
@@ -84,13 +83,10 @@ export const getReadableElements = async (tabId: string) => {
8483 const results = await browser . tabs . executeScript ( + tabId , {
8584 code,
8685 } ) ;
87- return getExecuteScriptResult ( results ) ;
86+ return getExecuteScriptResult < [ number , string , string ] [ ] > ( results ) ;
8887} ;
8988
90- export const clickOnIndex = async (
91- tabId : string ,
92- index : number
93- ) => {
89+ export const clickOnIndex = async ( tabId : string , index : number ) => {
9490 const results = await browser . tabs . executeScript ( + tabId , {
9591 code : toIIFE ( `
9692 ${ _getReadableElements . toString ( ) } ;
0 commit comments