Skip to content

Commit 29d6fd7

Browse files
committed
add index
1 parent cfd4127 commit 29d6fd7

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

apps/extension/src/utils/browser-integration.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ import type { Tab } from "@mcp-browser-kit/server/services/tab-service";
33
import { addDevTool } from "./add-dev-tool";
44

55
export 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

2221
export 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()};

apps/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mcp-browser-kit/server",
3-
"version": "1.0.7",
3+
"version": "1.0.9",
44
"packageManager": "yarn@4.8.0",
55
"homepage": "https://github.com/ndthanhdev/mcp-browser-kit",
66
"bin": {

apps/server/src/helpers/mcp-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ server.tool(
4141
"getReadableElements",
4242
[
4343
combinationDescription,
44-
"- Use this tool to get a list of [tag,accessible-text] pairs",
44+
"- Use this tool to get a list of [index,tag,accessible-text] of all readable elements in the current tab.",
4545
"- Usually being called after `getTabs` to read or identify element to interact with.",
4646
].join("\n"),
4747
{

0 commit comments

Comments
 (0)