@ejazullah/browser-mcp 0.0.57 → 0.0.58
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/README.md +2 -0
- package/lib/auth.js +82 -1
- package/lib/browserContextFactory.js +205 -1
- package/lib/browserServerBackend.js +125 -1
- package/lib/config.js +266 -1
- package/lib/context.js +232 -1
- package/lib/databaseLogger.js +264 -1
- package/lib/extension/cdpRelay.js +346 -1
- package/lib/extension/extensionContextFactory.js +56 -1
- package/lib/extension/main.js +26 -1
- package/lib/fileUtils.js +32 -1
- package/lib/httpServer.js +39 -1
- package/lib/index.js +39 -1
- package/lib/javascript.js +49 -1
- package/lib/log.js +21 -1
- package/lib/loop/loop.js +69 -1
- package/lib/loop/loopClaude.js +152 -1
- package/lib/loop/loopOpenAI.js +143 -1
- package/lib/loop/main.js +60 -1
- package/lib/loopTools/context.js +66 -1
- package/lib/loopTools/main.js +49 -1
- package/lib/loopTools/perform.js +32 -1
- package/lib/loopTools/snapshot.js +29 -1
- package/lib/loopTools/tool.js +18 -1
- package/lib/manualPromise.js +111 -1
- package/lib/mcp/inProcessTransport.js +72 -1
- package/lib/mcp/server.js +93 -1
- package/lib/mcp/transport.js +223 -1
- package/lib/mongoDBLogger.js +252 -1
- package/lib/package.js +20 -1
- package/lib/program.js +113 -1
- package/lib/response.js +172 -1
- package/lib/sessionLog.js +156 -1
- package/lib/tab.js +266 -1
- package/lib/tools/cdp.js +169 -1
- package/lib/tools/common.js +55 -1
- package/lib/tools/console.js +33 -1
- package/lib/tools/dialogs.js +47 -1
- package/lib/tools/evaluate.js +53 -1
- package/lib/tools/extraction.js +217 -1
- package/lib/tools/files.js +44 -1
- package/lib/tools/forms.js +180 -1
- package/lib/tools/getext.js +99 -1
- package/lib/tools/install.js +53 -1
- package/lib/tools/interactions.js +191 -1
- package/lib/tools/keyboard.js +86 -1
- package/lib/tools/mouse.js +99 -1
- package/lib/tools/navigate.js +70 -1
- package/lib/tools/network.js +41 -1
- package/lib/tools/pdf.js +40 -1
- package/lib/tools/screenshot.js +75 -1
- package/lib/tools/selectors.js +233 -1
- package/lib/tools/snapshot.js +169 -1
- package/lib/tools/states.js +147 -1
- package/lib/tools/tabs.js +87 -1
- package/lib/tools/tool.js +33 -1
- package/lib/tools/utils.js +74 -1
- package/lib/tools/wait.js +56 -1
- package/lib/tools.js +64 -1
- package/lib/utils.js +26 -1
- package/package.json +2 -2
package/lib/tools/dialogs.js
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
|
+
const handleDialog = defineTabTool({
|
|
19
|
+
capability: 'core',
|
|
20
|
+
schema: {
|
|
21
|
+
name: 'browser_handle_dialog',
|
|
22
|
+
title: 'Handle a dialog',
|
|
23
|
+
description: 'Handle a dialog',
|
|
24
|
+
inputSchema: z.object({
|
|
25
|
+
accept: z.boolean().describe('Whether to accept the dialog.'),
|
|
26
|
+
promptText: z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
|
|
27
|
+
}),
|
|
28
|
+
type: 'destructive',
|
|
29
|
+
},
|
|
30
|
+
handle: async (tab, params, response) => {
|
|
31
|
+
response.setIncludeSnapshot();
|
|
32
|
+
const dialogState = tab.modalStates().find(state => state.type === 'dialog');
|
|
33
|
+
if (!dialogState)
|
|
34
|
+
throw new Error('No dialog visible');
|
|
35
|
+
tab.clearModalState(dialogState);
|
|
36
|
+
await tab.waitForCompletion(async () => {
|
|
37
|
+
if (params.accept)
|
|
38
|
+
await dialogState.dialog.accept(params.promptText);
|
|
39
|
+
else
|
|
40
|
+
await dialogState.dialog.dismiss();
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
clearsModalState: 'dialog',
|
|
44
|
+
});
|
|
45
|
+
export default [
|
|
46
|
+
handleDialog,
|
|
47
|
+
];
|
package/lib/tools/evaluate.js
CHANGED
|
@@ -1 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
|
+
import * as javascript from '../javascript.js';
|
|
19
|
+
import { generateLocator } from './utils.js';
|
|
20
|
+
const evaluateSchema = z.object({
|
|
21
|
+
function: z.string().describe('() => { /* code */ } or (element) => { /* code */ } when element is provided'),
|
|
22
|
+
element: z.string().optional().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
23
|
+
ref: z.string().optional().describe('Exact target element reference from the page snapshot'),
|
|
24
|
+
});
|
|
25
|
+
const evaluate = defineTabTool({
|
|
26
|
+
capability: 'core',
|
|
27
|
+
schema: {
|
|
28
|
+
name: 'browser_evaluate',
|
|
29
|
+
title: 'Evaluate JavaScript',
|
|
30
|
+
description: 'Evaluate JavaScript expression on page or element',
|
|
31
|
+
inputSchema: evaluateSchema,
|
|
32
|
+
type: 'destructive',
|
|
33
|
+
},
|
|
34
|
+
handle: async (tab, params, response) => {
|
|
35
|
+
response.setIncludeSnapshot();
|
|
36
|
+
let locator;
|
|
37
|
+
if (params.ref && params.element) {
|
|
38
|
+
locator = await tab.refLocator({ ref: params.ref, element: params.element });
|
|
39
|
+
response.addCode(`await page.${await generateLocator(locator)}.evaluate(${javascript.quote(params.function)});`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
response.addCode(`await page.evaluate(${javascript.quote(params.function)});`);
|
|
43
|
+
}
|
|
44
|
+
await tab.waitForCompletion(async () => {
|
|
45
|
+
const receiver = locator ?? tab.page;
|
|
46
|
+
const result = await receiver._evaluateFunction(params.function);
|
|
47
|
+
response.addResult(JSON.stringify(result, null, 2) || 'undefined');
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
export default [
|
|
52
|
+
evaluate,
|
|
53
|
+
];
|
package/lib/tools/extraction.js
CHANGED
|
@@ -1 +1,217 @@
|
|
|
1
|
-
const _0x2b904c=_0x5fa0;(function(_0x1ac0f0,_0xa25c49){const _0x252f36=_0x5fa0,_0x527c57=_0x1ac0f0();while(!![]){try{const _0x14103e=parseInt(_0x252f36(0x16e))/0x1+parseInt(_0x252f36(0x169))/0x2+parseInt(_0x252f36(0x157))/0x3*(-parseInt(_0x252f36(0x10d))/0x4)+-parseInt(_0x252f36(0x133))/0x5*(parseInt(_0x252f36(0x105))/0x6)+parseInt(_0x252f36(0x100))/0x7+parseInt(_0x252f36(0x109))/0x8+-parseInt(_0x252f36(0x116))/0x9;if(_0x14103e===_0xa25c49)break;else _0x527c57['push'](_0x527c57['shift']());}catch(_0x462d4c){_0x527c57['push'](_0x527c57['shift']());}}}(_0x3afc,0x48d6b));const _0x45bdf1=(function(){let _0x116f1c=!![];return function(_0x5cef70,_0x53a1d1){const _0x2895f7=_0x116f1c?function(){const _0x3b8d7c=_0x5fa0;if(_0x53a1d1){const _0x43ea04=_0x53a1d1[_0x3b8d7c(0x168)](_0x5cef70,arguments);return _0x53a1d1=null,_0x43ea04;}}:function(){};return _0x116f1c=![],_0x2895f7;};}()),_0x19812b=_0x45bdf1(this,function(){const _0x137563=_0x5fa0,_0x22eaa5={};_0x22eaa5[_0x137563(0x178)]=_0x137563(0x114);const _0x56477c=_0x22eaa5;return _0x19812b['toString']()[_0x137563(0x171)](_0x56477c[_0x137563(0x178)])[_0x137563(0x130)]()[_0x137563(0x102)](_0x19812b)[_0x137563(0x171)](_0x56477c[_0x137563(0x178)]);});_0x19812b();function _0x5fa0(_0x5cc534,_0x4b53e0){_0x5cc534=_0x5cc534-0xec;const _0x43a978=_0x3afc();let _0x19812b=_0x43a978[_0x5cc534];if(_0x5fa0['xiNNFr']===undefined){var _0x45bdf1=function(_0x2d1243){const _0x98f31='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5a18de='',_0x47939b='',_0x4b62b3=_0x5a18de+_0x45bdf1;for(let _0x1d3b8e=0x0,_0x3755e8,_0x2f9579,_0x33c722=0x0;_0x2f9579=_0x2d1243['charAt'](_0x33c722++);~_0x2f9579&&(_0x3755e8=_0x1d3b8e%0x4?_0x3755e8*0x40+_0x2f9579:_0x2f9579,_0x1d3b8e++%0x4)?_0x5a18de+=_0x4b62b3['charCodeAt'](_0x33c722+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x3755e8>>(-0x2*_0x1d3b8e&0x6)):_0x1d3b8e:0x0){_0x2f9579=_0x98f31['indexOf'](_0x2f9579);}for(let _0x220842=0x0,_0x148370=_0x5a18de['length'];_0x220842<_0x148370;_0x220842++){_0x47939b+='%'+('00'+_0x5a18de['charCodeAt'](_0x220842)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x47939b);};_0x5fa0['uIoyEi']=_0x45bdf1,_0x5fa0['ahTQLx']={},_0x5fa0['xiNNFr']=!![];}const _0x3afc78=_0x43a978[0x0],_0x5fa022=_0x5cc534+_0x3afc78,_0x2ce96a=_0x5fa0['ahTQLx'][_0x5fa022];if(!_0x2ce96a){const _0x44e19e=function(_0xc44779){this['eWHePj']=_0xc44779,this['RBfXfH']=[0x1,0x0,0x0],this['ONJouG']=function(){return'newState';},this['bSNlQh']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['qOQzwS']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x44e19e['prototype']['VpiXDZ']=function(){const _0x463398=new RegExp(this['bSNlQh']+this['qOQzwS']),_0x2815df=_0x463398['test'](this['ONJouG']['toString']())?--this['RBfXfH'][0x1]:--this['RBfXfH'][0x0];return this['TqzsMd'](_0x2815df);},_0x44e19e['prototype']['TqzsMd']=function(_0x56f223){if(!Boolean(~_0x56f223))return _0x56f223;return this['EYKBDd'](this['eWHePj']);},_0x44e19e['prototype']['EYKBDd']=function(_0x293c1c){for(let _0x1b29c3=0x0,_0x3897a1=this['RBfXfH']['length'];_0x1b29c3<_0x3897a1;_0x1b29c3++){this['RBfXfH']['push'](Math['round'](Math['random']())),_0x3897a1=this['RBfXfH']['length'];}return _0x293c1c(this['RBfXfH'][0x0]);},new _0x44e19e(_0x5fa0)['VpiXDZ'](),_0x19812b=_0x5fa0['uIoyEi'](_0x19812b),_0x5fa0['ahTQLx'][_0x5fa022]=_0x19812b;}else _0x19812b=_0x2ce96a;return _0x19812b;}import{z}from'zod';import{defineTabTool}from'./tool.js';function _0x3afc(){const _0x4f237e=['twf4Aw11BsbUDw1IzxiGB2yGBgLUA3mGDg8GCMv0DxjU','q1ntihnLBgvJDg9YigzVCIb0AguGDgfIBgu','yxbWBhK','odCZmteYBgPAAMPp','thLvtwy','sw5JBhvKzsb0ywjSzsbOzwfKzxjZ','s3HJs0S','Aw5JBhvKzufSDa','otmXntbXrwHYv2W','y29UC3qGDgfIBgveyxrHid0GyxDHAxqGCgfNzs5LDMfSDwf0zsGOksa9pIbbCNjHEs5MCM9TkgrVy3vTzw50lNf1zxj5u2vSzwn0B3iOjW','yNjVD3nLCL9NzxrFzwXLBwvUDf9ZDhLSzq','C2vHCMnO','Dgv4DenVBNrLBNq','yNjVD3nLCL9NzxrFDgfIBgvFzgf0yq','sevbrevs','BMf0DxjHBeHLAwDODa','y29Yzq','zNjVBq','zMzMrfy','B2jQzwn0','u3bLy2LMAwmGq1ntihbYB3bLCNrPzxmGDg8Gz2v0icHPzIbUB3qGChjVDMLKzwqSigDLDhmGy29TBw9Uig9UzxmP','AhjLzG','BgvUz3rO','yM9YzgvY','z2v0uhjVCgvYDhLwywX1zq','DgfIBgu','sw5JBhvKzsbHBhqGDgv4Da','CxvLCNLtzwXLy3rVCKfSBa','rMfPBgvKihrVigv4DhjHy3qGDgfIBguGzgf0ytOG','zgvZy3jPyMu','zxzHBhvHDgu','B3bHy2L0Eq','C3jJ','BgLTAxq','BwfW','C29Tzq','y29UC3qGC3r5BgvZid0GyxDHAxqGCgfNzs5LDMfSDwf0zsGOksa9pIb7ignVBNn0igvSid0Gzg9JDw1LBNqUCxvLCNLtzwXLy3rVCIGN','AM9PBG','sw5JBhvKzsbSAw5RihrLEhq','tg1fB0C','mZK2ndu2mKXQzhbYta','BMf0DxjHBfDPzhrO','y29UC3rYDwn0B3i','yNjVD3nLCL9NzxrFywXSx2XPBMTZ','Aw5KzxG','mtH2AhHXAfy','Dgv4Da','jYKUCxvLCNLtzwXLy3rVCKfSBcGNDhiNksKUBwfWkhjVDYa9pIbbCNjHEs5MCM9TkhjVDY5JzwXSCYKUBwfWkgnLBgWGpt4Gy2vSBc50zxH0q29UDgvUDcKPktS','CgfNzq','mtaZoti3mMnqCMPlCW','CxvLCNLtzwXLy3rVCG','rwXLBwvUDcbZDhLSzxm6cG','ihWG','nZi0mtaWruXzqLrz','ywX0','ywrKq29Kzq','BgvMDa','DhjPBq','Aw5JBhvKzuHYzwy','y29SB3i','kcGOlISPkYKRksSK','z0T5B1m','mZiZmde5ovnyExz4BW','rMfPBgvKihrVigDLDcbSAw5RCZOG','ywrKuMvZDwX0','CMvHze9UBhK','DMLZseO','rMfPBgvKihrVigDLDcbLBgvTzw50ihn0EwXLCZOG','twf4Aw11BsbUDw1IzxiGB2yGCM93CYb0BYbLEhrYywn0','igLTywDLCYaOC2HVD2LUzYbMAxjZDca','z2v0qxr0CMLIDxrL','DNzIswS','rxH0CMfJDcbKyxrHigzYB20Gsfrntcb0ywjSzxm','r2v0igfSBcbSAw5RCW','igXPBMTZicHZAg93Aw5NigzPCNn0ia','AgvPz2H0','BM9Uzq','y29UC3qGBgLUA3mGpsbHD2fPDcbWywDLlMv2ywX1yxrLkcGPid0+iefYCMf5lMzYB20Ozg9JDw1LBNqUCxvLCNLtzwXLy3rVCKfSBcGNyvTOCMvMxsCPks5TyxaOBgLUAYa9pIaOEYb0zxH0oIbSAw5RlNrLEhrdB250zw50lcbOCMvMoIbSAw5RlMHYzwyGFsKPktS','zvnHBfC','twf4Aw11BsbUDw1IzxiGB2yGAw1Hz2vZihrVihjLDhvYBG','C2vSzwn0B3i','y29UC3qGAw1Hz2vZid0GyxDHAxqGCgfNzs5LDMfSDwf0zsGOksa9pIbbCNjHEs5MCM9TkgrVy3vTzw50lNf1zxj5u2vSzwn0B3jbBgWOj2LTzYCPks5TyxaOAw1Nid0+icH7ihnYyZOGAw1NlNnYyYWGywX0oIbPBwCUywX0ih0PksK7','zgvMyxvSDa','yM9VBgvHBG','jYK7ihjLDhvYBIb3Aw5KB3CUz2v0q29TChv0zwrtDhLSzsHLBcK7ih0PoW','r2v0ignVBxb1DgvKientuYbZDhLSzxmGzM9YigfUigvSzw1LBNq','rxH0CMfJDcbHBgWGAw1Hz2vZigfUzcb0AgvPCIbZB3vYy2vZigzYB20GDgHLign1CNjLBNqGCgfNzq','rxH0CMfJDcb0ywjSzsbKyxrH','Dg9tDhjPBMC','yxzvv1e','z2v0q29TChv0zwrtDhLSzq','mZq0ndu1q09pqvPI','vgfIBguGzgf0ysaO','q1ntihnLBgvJDg9YigzVCIb0AguGzwXLBwvUDa','DKv1wxC','EKfxB0S','ihjVD3mPoGO','Be5IC2y','yxv0BW','BNvTyMvY','yxjYyxK','B3b0Aw9UywW','C2z4vfC','Dg9W','uK9xia','DgL0Bgu','yNjVD3nLCL9NzxrFywXSx2LTywDLCW','qLLpv1O','r2v0igvSzw1LBNqGC3r5BgvZ','CgfKzgLUzW','Bwf4uM93CW','D2LKDgG','DgjRtfO','ywrKrxjYB3i','Cg9ZAxrPB24','zw50CMLLCW','AeryveC','rMfPBgvKihrVigDLDcbPBwfNzxm6ia','rM91BMqG','zM9YrwfJAa','ChvZAa','zM9UDc1ZAxPL','rxH0CMfJDcbHBgWGBgLUA3mGzNjVBsb0AguGy3vYCMvUDcbWywDL','r2v0igfSBcbPBwfNzxm','sw5JBhvKzsbOCMvMigf0DhjPyNv0zq','Aw5JBhvKzuHLywrLCNm','yvTOCMvMxq','nLzHrKPvqq','C3rYAw5N','BwfYz2LU','quL5tfe','zgLZCgXHEq','yMfJA2DYB3vUzc1JB2XVCG','DgqSihrO','zM9UDc1Myw1PBhK','C2XPy2u','ChjVCgvYDgLLCW','tM8GzwXLBwvUDcbMB3vUzcb3AxrOihnLBgvJDg9Yici','BxftyKO','Aw5JBhvKzvnYyW','DMLZAwjPBgL0Eq','tM8GDgfIBguGzM91BMqGD2L0AcbZzwXLy3rVCIaI'];_0x3afc=function(){return _0x4f237e;};return _0x3afc();}const getAllLinks=defineTabTool({'capability':'core','schema':{'name':_0x2b904c(0x103),'title':_0x2b904c(0x121),'description':_0x2b904c(0x152),'inputSchema':z[_0x2b904c(0x179)]({'includeText':z[_0x2b904c(0x12b)]()[_0x2b904c(0x13d)]()['default'](!![])[_0x2b904c(0xf5)](_0x2b904c(0xfe)),'includeHref':z[_0x2b904c(0x12b)]()['optional']()[_0x2b904c(0x12a)](!![])[_0x2b904c(0xf5)](_0x2b904c(0x154)),'limit':z[_0x2b904c(0x13b)]()[_0x2b904c(0x13d)]()[_0x2b904c(0x12a)](0x14)[_0x2b904c(0xf5)](_0x2b904c(0x166))}),'type':_0x2b904c(0x119)},'handle':async(_0x9d81e6,_0x3ff2f5,_0xf5c3f3)=>{const _0x3cac29=_0x2b904c,_0x352f4a={};_0x352f4a[_0x3cac29(0x139)]=_0x3cac29(0x156);const _0x28e3fe=_0x352f4a;try{const _0x1a9d32=await _0x9d81e6[_0x3cac29(0x108)][_0x3cac29(0xf6)](()=>{const _0x26ca31=_0x3cac29,_0x470023=Array[_0x26ca31(0x177)](document['querySelectorAll'](_0x28e3fe[_0x26ca31(0x139)]));return _0x470023[_0x26ca31(0xfa)]((_0x4a8e4c,_0x3c1d01)=>({'index':_0x3c1d01,'text':_0x4a8e4c['textContent']?.[_0x26ca31(0x111)]()||'','href':_0x4a8e4c[_0x26ca31(0x11e)](_0x26ca31(0xed))||'','title':_0x4a8e4c[_0x26ca31(0x11e)](_0x26ca31(0x141))||''}));}),_0x13bf72=_0x1a9d32[_0x3cac29(0x15f)](0x0,_0x3ff2f5[_0x3cac29(0xf9)]),_0x33f365=[];_0x13bf72[_0x3cac29(0x14f)](_0x593e68=>{const _0x3decde=_0x3cac29,_0x256267=['['+_0x593e68['index']+']'];_0x3ff2f5['includeText']&&_0x593e68['text']&&_0x256267[_0x3decde(0x150)]('\x22'+_0x593e68[_0x3decde(0x106)]+'\x22'),_0x3ff2f5[_0x3decde(0x112)]&&_0x256267[_0x3decde(0x150)]('→\x20'+_0x593e68[_0x3decde(0xed)]),_0x593e68[_0x3decde(0x141)]&&_0x256267[_0x3decde(0x150)]('('+_0x593e68[_0x3decde(0x141)]+')'),_0x33f365[_0x3decde(0x150)](_0x256267[_0x3decde(0xfd)]('\x20'));}),_0xf5c3f3[_0x3cac29(0x10f)](_0x3cac29(0x125)),_0xf5c3f3[_0x3cac29(0x118)](_0x3cac29(0x14e)+_0x1a9d32[_0x3cac29(0xee)]+_0x3cac29(0x122)+_0x13bf72[_0x3cac29(0xee)]+'):\x0a'+_0x33f365[_0x3cac29(0xfd)]('\x0a'));}catch(_0x44ccb1){_0xf5c3f3[_0x3cac29(0x149)](_0x3cac29(0x117)+_0x44ccb1);}}}),getAllImages=defineTabTool({'capability':_0x2b904c(0x176),'schema':{'name':_0x2b904c(0x142),'title':_0x2b904c(0x153),'description':_0x2b904c(0x12e),'inputSchema':z[_0x2b904c(0x179)]({'includeAlt':z[_0x2b904c(0x12b)]()[_0x2b904c(0x13d)]()['default'](!![])[_0x2b904c(0xf5)](_0x2b904c(0xf2)),'includeSrc':z[_0x2b904c(0x12b)]()['optional']()[_0x2b904c(0x12a)](!![])[_0x2b904c(0xf5)]('Include\x20src\x20attribute'),'limit':z[_0x2b904c(0x13b)]()[_0x2b904c(0x13d)]()[_0x2b904c(0x12a)](0x14)['describe'](_0x2b904c(0x127))}),'type':_0x2b904c(0x119)},'handle':async(_0x56a2b6,_0x1d6af6,_0x180289)=>{const _0x38476a=_0x2b904c,_0x223075={};_0x223075[_0x38476a(0x16a)]='img';const _0xebcd02=_0x223075;try{const _0x132b01=await _0x56a2b6[_0x38476a(0x108)][_0x38476a(0xf6)](()=>{const _0x54a302=_0x38476a,_0x29a2d9=Array[_0x54a302(0x177)](document[_0x54a302(0xf3)](_0xebcd02[_0x54a302(0x16a)]));return _0x29a2d9[_0x54a302(0xfa)]((_0x4e12df,_0x46cbcf)=>({'index':_0x46cbcf,'src':_0x4e12df[_0x54a302(0xf8)]||'','alt':_0x4e12df[_0x54a302(0x10e)]||'','title':_0x4e12df[_0x54a302(0x141)]||'','width':_0x4e12df[_0x54a302(0x101)]||_0x4e12df[_0x54a302(0x147)],'height':_0x4e12df[_0x54a302(0x175)]||_0x4e12df[_0x54a302(0x123)]}));}),_0x3f1c56=_0x132b01[_0x38476a(0x15f)](0x0,_0x1d6af6[_0x38476a(0xf9)]),_0x251e33=[];_0x3f1c56['forEach'](_0x4b40f8=>{const _0x51ec74=_0x38476a,_0x389ba3=['['+_0x4b40f8[_0x51ec74(0x104)]+']'];_0x1d6af6[_0x51ec74(0x16d)]&&_0x4b40f8[_0x51ec74(0x10e)]&&_0x389ba3[_0x51ec74(0x150)]('\x22'+_0x4b40f8[_0x51ec74(0x10e)]+'\x22'),_0x1d6af6[_0x51ec74(0x163)]&&_0x389ba3[_0x51ec74(0x150)]('→\x20'+_0x4b40f8['src']),_0x4b40f8[_0x51ec74(0x147)]&&_0x4b40f8[_0x51ec74(0x123)]&&_0x389ba3[_0x51ec74(0x150)]('('+_0x4b40f8[_0x51ec74(0x147)]+'x'+_0x4b40f8[_0x51ec74(0x123)]+')'),_0x251e33['push'](_0x389ba3[_0x51ec74(0xfd)]('\x20'));}),_0x180289[_0x38476a(0x10f)](_0x38476a(0x129)),_0x180289[_0x38476a(0x118)](_0x38476a(0x14e)+_0x132b01[_0x38476a(0xee)]+_0x38476a(0x11d)+_0x3f1c56[_0x38476a(0xee)]+'):\x0a'+_0x251e33[_0x38476a(0xfd)]('\x0a'));}catch(_0x2b6851){_0x180289[_0x38476a(0x149)](_0x38476a(0x14d)+_0x2b6851);}}}),getTableData=defineTabTool({'capability':_0x2b904c(0x176),'schema':{'name':_0x2b904c(0x173),'title':_0x2b904c(0x12f),'description':_0x2b904c(0x120),'inputSchema':z[_0x2b904c(0x179)]({'selector':z[_0x2b904c(0x158)]()[_0x2b904c(0x13d)]()[_0x2b904c(0x12a)](_0x2b904c(0xf1))[_0x2b904c(0xf5)](_0x2b904c(0x167)),'includeHeaders':z[_0x2b904c(0x12b)]()[_0x2b904c(0x13d)]()['default'](!![])[_0x2b904c(0xf5)](_0x2b904c(0x16b)),'maxRows':z[_0x2b904c(0x13b)]()[_0x2b904c(0x13d)]()[_0x2b904c(0x12a)](0xa)['describe'](_0x2b904c(0x11c))}),'type':_0x2b904c(0x119)},'handle':async(_0x47ff29,_0x5cf26b,_0x5e6454)=>{const _0x369918=_0x2b904c,_0xaec436={};_0xaec436[_0x369918(0x11a)]=_0x369918(0x15d),_0xaec436['AIyLQ']=function(_0x3671bc,_0x416c99){return _0x3671bc===_0x416c99;},_0xaec436[_0x369918(0x148)]=_0x369918(0x174),_0xaec436[_0x369918(0x126)]=_0x369918(0x10c);const _0x13dbd8=_0xaec436;try{const _0x5660c7={};_0x5660c7[_0x369918(0x128)]=_0x5cf26b['selector'],_0x5660c7[_0x369918(0x155)]=_0x5cf26b[_0x369918(0x155)],_0x5660c7['maxRows']=_0x5cf26b[_0x369918(0x146)];const _0x57593a=await _0x47ff29['page'][_0x369918(0xf6)](({selector:_0x555bb7,includeHeaders:_0x12c964,maxRows:_0x23d6f})=>{const _0x4598fc=_0x369918,_0x49a06e=document[_0x4598fc(0x10a)](_0x555bb7);if(!_0x49a06e)return null;const _0x43d6b4=Array['from'](_0x49a06e[_0x4598fc(0xf3)]('tr')),_0x3db25b=[];return _0x43d6b4[_0x4598fc(0x15f)](0x0,_0x23d6f)[_0x4598fc(0x14f)](_0x13c5af=>{const _0x1ff43c=_0x4598fc,_0x1130cc=Array[_0x1ff43c(0x177)](_0x13c5af[_0x1ff43c(0xf3)](_0x13dbd8[_0x1ff43c(0x11a)])),_0x3dfb16=_0x1130cc[_0x1ff43c(0xfa)](_0x58b1ba=>_0x58b1ba[_0x1ff43c(0x172)]?.[_0x1ff43c(0x111)]()||'');_0x3dfb16[_0x1ff43c(0xfb)](_0x2db2ce=>_0x2db2ce)&&_0x3db25b[_0x1ff43c(0x150)](_0x3dfb16);}),_0x3db25b;},_0x5660c7);if(!_0x57593a){_0x5e6454[_0x369918(0x149)](_0x369918(0x165)+_0x5cf26b[_0x369918(0x128)]+'\x22');return;}const _0x11fa60=[];_0x57593a[_0x369918(0x14f)]((_0x11b01b,_0x391635)=>{const _0x188c99=_0x369918,_0x43e162=_0x13dbd8[_0x188c99(0x15a)](_0x391635,0x0)&&_0x5cf26b[_0x188c99(0x155)],_0x3fa360=_0x43e162?_0x13dbd8[_0x188c99(0x148)]:_0x188c99(0x140)+_0x391635;_0x11fa60[_0x188c99(0x150)](_0x3fa360+':\x20'+_0x11b01b[_0x188c99(0xfd)](_0x13dbd8[_0x188c99(0x126)]));}),_0x5e6454[_0x369918(0x10f)](_0x369918(0x16f)+_0x5cf26b[_0x369918(0x128)]+_0x369918(0x107)),_0x5e6454['addResult'](_0x369918(0x134)+_0x57593a[_0x369918(0xee)]+_0x369918(0x138)+_0x11fa60['join']('\x0a'));}catch(_0x3d6a4a){_0x5e6454[_0x369918(0x149)](_0x369918(0xf4)+_0x3d6a4a);}}}),getElementStyle=defineTabTool({'capability':'core','schema':{'name':_0x2b904c(0x170),'title':_0x2b904c(0x144),'description':_0x2b904c(0x12d),'inputSchema':z[_0x2b904c(0x179)]({'selector':z[_0x2b904c(0x158)]()[_0x2b904c(0xf5)](_0x2b904c(0x135)),'properties':z[_0x2b904c(0x13c)](z['string']())[_0x2b904c(0x13d)]()[_0x2b904c(0xf5)](_0x2b904c(0xec))}),'type':_0x2b904c(0x119)},'handle':async(_0x5f2d1a,_0x5afaa9,_0xa05629)=>{const _0x1c6844=_0x2b904c,_0x336f62={};_0x336f62[_0x1c6844(0x162)]=_0x1c6844(0x15b),_0x336f62['KxcKK']=_0x1c6844(0x164),_0x336f62[_0x1c6844(0x136)]=_0x1c6844(0x14a),_0x336f62[_0x1c6844(0x115)]=_0x1c6844(0x13f),_0x336f62[_0x1c6844(0x11f)]=_0x1c6844(0x123),_0x336f62[_0x1c6844(0x137)]=_0x1c6844(0x159),_0x336f62[_0x1c6844(0x143)]=_0x1c6844(0x145),_0x336f62[_0x1c6844(0x131)]=_0x1c6844(0xef),_0x336f62[_0x1c6844(0x13e)]=_0x1c6844(0x15c),_0x336f62['LmEoG']=_0x1c6844(0x151),_0x336f62[_0x1c6844(0x14c)]=_0x1c6844(0x15e);const _0x74d895=_0x336f62;try{const _0x5d7550=[_0x74d895[_0x1c6844(0x162)],_0x74d895[_0x1c6844(0x16c)],_0x1c6844(0xf7),_0x74d895[_0x1c6844(0x136)],_0x74d895[_0x1c6844(0x115)],_0x1c6844(0x110),_0x1c6844(0x147),_0x74d895[_0x1c6844(0x11f)],_0x74d895[_0x1c6844(0x137)],_0x74d895[_0x1c6844(0x143)],_0x74d895[_0x1c6844(0x131)],_0x74d895[_0x1c6844(0x13e)],_0x1c6844(0x113),_0x74d895[_0x1c6844(0xff)],_0x74d895[_0x1c6844(0x14c)]],_0x20c60c=_0x5afaa9[_0x1c6844(0x160)]||_0x5d7550,_0x871976={};_0x871976[_0x1c6844(0x128)]=_0x5afaa9['selector'],_0x871976['properties']=_0x20c60c;const _0x51c022=await _0x5f2d1a[_0x1c6844(0x108)][_0x1c6844(0xf6)](({selector:_0x4730e2,properties:_0x44f33a})=>{const _0xee3a71=_0x1c6844,_0x4e4c34=document[_0xee3a71(0x10a)](_0x4730e2);if(!_0x4e4c34)return null;const _0x1be373=window[_0xee3a71(0x132)](_0x4e4c34),_0x1b0b2e={};return _0x44f33a[_0xee3a71(0x14f)](_0x342eaf=>{const _0x4eba00=_0xee3a71;_0x1b0b2e[_0x342eaf]=_0x1be373[_0x4eba00(0xf0)](_0x342eaf);}),_0x1b0b2e;},_0x871976);if(!_0x51c022){_0xa05629[_0x1c6844(0x149)](_0x1c6844(0x161)+_0x5afaa9[_0x1c6844(0x128)]+'\x22');return;}const _0x3b4ada=Object[_0x1c6844(0x14b)](_0x51c022)['filter'](([_0x2eaa9a,_0x41bb77])=>_0x41bb77&&_0x41bb77!==_0x1c6844(0x13a)&&_0x41bb77!==_0x1c6844(0x124))[_0x1c6844(0xfa)](([_0x3ba8a8,_0x457992])=>_0x3ba8a8+':\x20'+_0x457992)[_0x1c6844(0xfd)]('\x0a');_0xa05629[_0x1c6844(0x10f)](_0x1c6844(0xfc)+_0x5afaa9['selector']+_0x1c6844(0x12c)),_0xa05629[_0x1c6844(0x118)](_0x1c6844(0x10b)+_0x3b4ada);}catch(_0x3982ec){_0xa05629[_0x1c6844(0x149)](_0x1c6844(0x11b)+_0x3982ec);}}});export default[getAllLinks,getAllImages,getTableData,getElementStyle];
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
|
+
// Get all links from page
|
|
19
|
+
const getAllLinks = defineTabTool({
|
|
20
|
+
capability: 'core',
|
|
21
|
+
schema: {
|
|
22
|
+
name: 'browser_get_all_links',
|
|
23
|
+
title: 'Get all links',
|
|
24
|
+
description: 'Extract all links from the current page',
|
|
25
|
+
inputSchema: z.object({
|
|
26
|
+
includeText: z.boolean().optional().default(true).describe('Include link text'),
|
|
27
|
+
includeHref: z.boolean().optional().default(true).describe('Include href attribute'),
|
|
28
|
+
limit: z.number().optional().default(20).describe('Maximum number of links to return'),
|
|
29
|
+
}),
|
|
30
|
+
type: 'readOnly',
|
|
31
|
+
},
|
|
32
|
+
handle: async (tab, params, response) => {
|
|
33
|
+
try {
|
|
34
|
+
const links = await tab.page.evaluate(() => {
|
|
35
|
+
const linkElements = Array.from(document.querySelectorAll('a[href]'));
|
|
36
|
+
return linkElements.map((link, index) => ({
|
|
37
|
+
index,
|
|
38
|
+
text: link.textContent?.trim() || '',
|
|
39
|
+
href: link.getAttribute('href') || '',
|
|
40
|
+
title: link.getAttribute('title') || '',
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
43
|
+
const limitedLinks = links.slice(0, params.limit);
|
|
44
|
+
const results = [];
|
|
45
|
+
limitedLinks.forEach((link) => {
|
|
46
|
+
const parts = [`[${link.index}]`];
|
|
47
|
+
if (params.includeText && link.text) {
|
|
48
|
+
parts.push(`"${link.text}"`);
|
|
49
|
+
}
|
|
50
|
+
if (params.includeHref) {
|
|
51
|
+
parts.push(`→ ${link.href}`);
|
|
52
|
+
}
|
|
53
|
+
if (link.title) {
|
|
54
|
+
parts.push(`(${link.title})`);
|
|
55
|
+
}
|
|
56
|
+
results.push(parts.join(' '));
|
|
57
|
+
});
|
|
58
|
+
response.addCode(`const links = await page.evaluate(() => Array.from(document.querySelectorAll('a[href]')).map(link => ({ text: link.textContent, href: link.href })));`);
|
|
59
|
+
response.addResult(`Found ${links.length} links (showing first ${limitedLinks.length}):\n${results.join('\n')}`);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
response.addError(`Failed to get links: ${error}`);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
// Get all images from page
|
|
67
|
+
const getAllImages = defineTabTool({
|
|
68
|
+
capability: 'core',
|
|
69
|
+
schema: {
|
|
70
|
+
name: 'browser_get_all_images',
|
|
71
|
+
title: 'Get all images',
|
|
72
|
+
description: 'Extract all images and their sources from the current page',
|
|
73
|
+
inputSchema: z.object({
|
|
74
|
+
includeAlt: z.boolean().optional().default(true).describe('Include alt text'),
|
|
75
|
+
includeSrc: z.boolean().optional().default(true).describe('Include src attribute'),
|
|
76
|
+
limit: z.number().optional().default(20).describe('Maximum number of images to return'),
|
|
77
|
+
}),
|
|
78
|
+
type: 'readOnly',
|
|
79
|
+
},
|
|
80
|
+
handle: async (tab, params, response) => {
|
|
81
|
+
try {
|
|
82
|
+
const images = await tab.page.evaluate(() => {
|
|
83
|
+
const imgElements = Array.from(document.querySelectorAll('img'));
|
|
84
|
+
return imgElements.map((img, index) => ({
|
|
85
|
+
index,
|
|
86
|
+
src: img.src || '',
|
|
87
|
+
alt: img.alt || '',
|
|
88
|
+
title: img.title || '',
|
|
89
|
+
width: img.naturalWidth || img.width,
|
|
90
|
+
height: img.naturalHeight || img.height,
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
const limitedImages = images.slice(0, params.limit);
|
|
94
|
+
const results = [];
|
|
95
|
+
limitedImages.forEach((img) => {
|
|
96
|
+
const parts = [`[${img.index}]`];
|
|
97
|
+
if (params.includeAlt && img.alt) {
|
|
98
|
+
parts.push(`"${img.alt}"`);
|
|
99
|
+
}
|
|
100
|
+
if (params.includeSrc) {
|
|
101
|
+
parts.push(`→ ${img.src}`);
|
|
102
|
+
}
|
|
103
|
+
if (img.width && img.height) {
|
|
104
|
+
parts.push(`(${img.width}x${img.height})`);
|
|
105
|
+
}
|
|
106
|
+
results.push(parts.join(' '));
|
|
107
|
+
});
|
|
108
|
+
response.addCode(`const images = await page.evaluate(() => Array.from(document.querySelectorAll('img')).map(img => ({ src: img.src, alt: img.alt })));`);
|
|
109
|
+
response.addResult(`Found ${images.length} images (showing first ${limitedImages.length}):\n${results.join('\n')}`);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
response.addError(`Failed to get images: ${error}`);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
// Get table data
|
|
117
|
+
const getTableData = defineTabTool({
|
|
118
|
+
capability: 'core',
|
|
119
|
+
schema: {
|
|
120
|
+
name: 'browser_get_table_data',
|
|
121
|
+
title: 'Extract table data',
|
|
122
|
+
description: 'Extract data from HTML tables',
|
|
123
|
+
inputSchema: z.object({
|
|
124
|
+
selector: z.string().optional().default('table').describe('CSS selector for the table'),
|
|
125
|
+
includeHeaders: z.boolean().optional().default(true).describe('Include table headers'),
|
|
126
|
+
maxRows: z.number().optional().default(10).describe('Maximum number of rows to extract'),
|
|
127
|
+
}),
|
|
128
|
+
type: 'readOnly',
|
|
129
|
+
},
|
|
130
|
+
handle: async (tab, params, response) => {
|
|
131
|
+
try {
|
|
132
|
+
const tableData = await tab.page.evaluate(({ selector, includeHeaders, maxRows }) => {
|
|
133
|
+
const table = document.querySelector(selector);
|
|
134
|
+
if (!table)
|
|
135
|
+
return null;
|
|
136
|
+
const rows = Array.from(table.querySelectorAll('tr'));
|
|
137
|
+
const data = [];
|
|
138
|
+
rows.slice(0, maxRows).forEach((row) => {
|
|
139
|
+
const cells = Array.from(row.querySelectorAll('td, th'));
|
|
140
|
+
const rowData = cells.map(cell => cell.textContent?.trim() || '');
|
|
141
|
+
if (rowData.some(cell => cell)) { // Only include non-empty rows
|
|
142
|
+
data.push(rowData);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return data;
|
|
146
|
+
}, { selector: params.selector, includeHeaders: params.includeHeaders, maxRows: params.maxRows });
|
|
147
|
+
if (!tableData) {
|
|
148
|
+
response.addError(`No table found with selector "${params.selector}"`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const results = [];
|
|
152
|
+
tableData.forEach((row, index) => {
|
|
153
|
+
const isHeader = index === 0 && params.includeHeaders;
|
|
154
|
+
const prefix = isHeader ? 'HEADER' : `ROW ${index}`;
|
|
155
|
+
results.push(`${prefix}: ${row.join(' | ')}`);
|
|
156
|
+
});
|
|
157
|
+
response.addCode(`const tableData = await page.evaluate(() => Array.from(document.querySelector('${params.selector}').querySelectorAll('tr')).map(row => Array.from(row.cells).map(cell => cell.textContent)));`);
|
|
158
|
+
response.addResult(`Table data (${tableData.length} rows):\n${results.join('\n')}`);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
response.addError(`Failed to extract table data: ${error}`);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
// Get computed styles
|
|
166
|
+
const getElementStyle = defineTabTool({
|
|
167
|
+
capability: 'core',
|
|
168
|
+
schema: {
|
|
169
|
+
name: 'browser_get_element_style',
|
|
170
|
+
title: 'Get element styles',
|
|
171
|
+
description: 'Get computed CSS styles for an element',
|
|
172
|
+
inputSchema: z.object({
|
|
173
|
+
selector: z.string().describe('CSS selector for the element'),
|
|
174
|
+
properties: z.array(z.string()).optional().describe('Specific CSS properties to get (if not provided, gets common ones)'),
|
|
175
|
+
}),
|
|
176
|
+
type: 'readOnly',
|
|
177
|
+
},
|
|
178
|
+
handle: async (tab, params, response) => {
|
|
179
|
+
try {
|
|
180
|
+
const defaultProperties = [
|
|
181
|
+
'display', 'visibility', 'opacity', 'position', 'top', 'left', 'width', 'height',
|
|
182
|
+
'margin', 'padding', 'border', 'background-color', 'color', 'font-size', 'font-family'
|
|
183
|
+
];
|
|
184
|
+
const propertiesToGet = params.properties || defaultProperties;
|
|
185
|
+
const styles = await tab.page.evaluate(({ selector, properties }) => {
|
|
186
|
+
const element = document.querySelector(selector);
|
|
187
|
+
if (!element)
|
|
188
|
+
return null;
|
|
189
|
+
const computedStyle = window.getComputedStyle(element);
|
|
190
|
+
const result = {};
|
|
191
|
+
properties.forEach((prop) => {
|
|
192
|
+
result[prop] = computedStyle.getPropertyValue(prop);
|
|
193
|
+
});
|
|
194
|
+
return result;
|
|
195
|
+
}, { selector: params.selector, properties: propertiesToGet });
|
|
196
|
+
if (!styles) {
|
|
197
|
+
response.addError(`No element found with selector "${params.selector}"`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const results = Object.entries(styles)
|
|
201
|
+
.filter(([_, value]) => value && value !== 'auto' && value !== 'none')
|
|
202
|
+
.map(([prop, value]) => `${prop}: ${value}`)
|
|
203
|
+
.join('\n');
|
|
204
|
+
response.addCode(`const styles = await page.evaluate(() => { const el = document.querySelector('${params.selector}'); return window.getComputedStyle(el); });`);
|
|
205
|
+
response.addResult(`Element styles:\n${results}`);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
response.addError(`Failed to get element styles: ${error}`);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
export default [
|
|
213
|
+
getAllLinks,
|
|
214
|
+
getAllImages,
|
|
215
|
+
getTableData,
|
|
216
|
+
getElementStyle,
|
|
217
|
+
];
|
package/lib/tools/files.js
CHANGED
|
@@ -1 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { defineTabTool } from './tool.js';
|
|
18
|
+
const uploadFile = defineTabTool({
|
|
19
|
+
capability: 'core',
|
|
20
|
+
schema: {
|
|
21
|
+
name: 'browser_file_upload',
|
|
22
|
+
title: 'Upload files',
|
|
23
|
+
description: 'Upload one or multiple files',
|
|
24
|
+
inputSchema: z.object({
|
|
25
|
+
paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
|
|
26
|
+
}),
|
|
27
|
+
type: 'destructive',
|
|
28
|
+
},
|
|
29
|
+
handle: async (tab, params, response) => {
|
|
30
|
+
response.setIncludeSnapshot();
|
|
31
|
+
const modalState = tab.modalStates().find(state => state.type === 'fileChooser');
|
|
32
|
+
if (!modalState)
|
|
33
|
+
throw new Error('No file chooser visible');
|
|
34
|
+
response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`);
|
|
35
|
+
tab.clearModalState(modalState);
|
|
36
|
+
await tab.waitForCompletion(async () => {
|
|
37
|
+
await modalState.fileChooser.setFiles(params.paths);
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
clearsModalState: 'fileChooser',
|
|
41
|
+
});
|
|
42
|
+
export default [
|
|
43
|
+
uploadFile,
|
|
44
|
+
];
|