@ejazullah/browser-mcp 0.0.57 → 0.0.59
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/cli.js +18 -1
- package/index.js +18 -1
- 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 -4
package/lib/tools/selectors.js
CHANGED
|
@@ -1 +1,233 @@
|
|
|
1
|
-
const _0x361b18=_0x1814;(function(_0x82c565,_0x30cfe0){const _0x5171dd=_0x1814,_0x127dd4=_0x82c565();while(!![]){try{const _0x33237e=-parseInt(_0x5171dd(0x141))/0x1*(-parseInt(_0x5171dd(0x117))/0x2)+parseInt(_0x5171dd(0x101))/0x3*(parseInt(_0x5171dd(0xf8))/0x4)+-parseInt(_0x5171dd(0x11b))/0x5*(-parseInt(_0x5171dd(0xe7))/0x6)+parseInt(_0x5171dd(0xc9))/0x7+-parseInt(_0x5171dd(0xf2))/0x8+parseInt(_0x5171dd(0xcf))/0x9*(-parseInt(_0x5171dd(0x139))/0xa)+-parseInt(_0x5171dd(0xdf))/0xb;if(_0x33237e===_0x30cfe0)break;else _0x127dd4['push'](_0x127dd4['shift']());}catch(_0x81b75c){_0x127dd4['push'](_0x127dd4['shift']());}}}(_0x2e89,0xe2627));function _0x2e89(){const _0x40eb11=['mtaWmtC3otfIueXHBxC','BNvTyMvY','rMfPBgvKihrVigDLDca','C3rYAw5N','z3D6twO','v0LRruC','mtqXntDuDu9yvMO','ywrKrxjYB3i','AxnYvKy','ihvZAw5NifHqyxrOici','y29UC3qGDgv4DenVBNrLBNqGpsbHD2fPDcbWywDLlMDLDej5uM9SzsGN','wfbHDgGGzxHWCMvZC2LVBIb0BYb0yxjNzxqGDgHLigvSzw1LBNqGkguUzY4SiciVl2j1DhrVBLTaAwq9j3n1yM1PDcDDiIWGiI8VzgL2w2nVBNrHAw5ZkebJBgfZCYWGj2nVBNrLBNqNkv0Ikq','zxHHy3q','Bgv2zwW','z2v0qxr0CMLIDxrLkcC','igvSzw1LBNrZlcbZAg93Aw5NigzPCNn0ia','tgv2zwWGzM9YigHLywrPBMDZicGXltyP','vgv4DcbJB250zw50ihrVihnLyxjJAcbMB3iGAw4GzwXLBwvUDhm','v2HLDgHLCIb0BYbTyxrJAcb0zxH0igv4ywn0BhKGB3iGDxnLignVBNrHAw5Z','r2v0ihrLEhqGyNKGq1ntihnLBgvJDg9Y','lcb7igv4ywn0oIb0CNvLih0','xcqM','mZi2odmZodD6t2zJAMe','Dgv4DenVBNrLBNq','Cvf4CeO','B3b0Aw9UywW','vgv4DcbJB250zw50','DgL0Bgu','yxbWBhK','lM50AcG','odGYnJKWuLbprM95','CMvHze9UBhK','Dgv4DcbJB250zw50','EhbHDgG9','yNjVD3nLCL9NzxrFDgv4Df9IEv94Cgf0Aa','txvgte0','ChvZAa','Aw5WDxrty2HLBwe','B2jQzwn0','twf4Aw11BsbUDw1IzxiGB2yGzwXLBwvUDhmGDg8GChjVy2vZCW','jYb9kq','mJaXotq4offvzM1qvq','jYKUywXSkcK7cMnVBNn0ihjLC3vSDhmGpsbHD2fPDcbqCM9TAxnLlMfSBcHLBgvTzw50CY5ZBgLJzsGWlca','qvjjqsbYB2XLig9MihrOzsbLBgvTzw50icHLlMCUlcaIyNv0Dg9UiIWGiMXPBMSIlcaIDgv4DgjVEciSicjOzwfKAw5NiIK','y29UC3qGyxr0CMLIDxrLvMfSDwuGpsbHD2fPDcbWywDLlMXVy2f0B3iOjW','yNjVD3nLCL9NzxrFDgv4Df9IEv90zxH0','y29UC3qGyxr0CMLIDxrLvMfSDwuGpsbHD2fPDcbWywDLlMXVy2f0B3iOj3HWyxrOpq','mZKZmLjzqLHcqW','r2v0ihrLEhqGyNKGqvjjqsbYB2XL','r2v0igfSBcb0zxH0igzYB20GBxvSDgLWBguGzwXLBwvUDhm','ywrKq29Kzq','q1ntihnLBgvJDg9YihrVihrHCMDLDcb0AguGzwXLBwvUDcaOzs5NlIWGiInPzciSiciUy2XHC3mIlcaIyNv0Dg9UiIWGiLTKyxrHlxrLC3q9j3zHBhvLj10Ikq','C2vSzwn0B3i','zgvZy3jPyMu','Dgv4DenVBNrLBNqOkq','y29UC3rYDwn0B3i','mZmWoxjVv2Dlta','jYK7','y29UC3qGDgv4DenVBNrLBNqGpsbHD2fPDcbWywDLlMXVy2f0B3iOj3HWyxrOpq','CM9Szq','y29UC3qGyxr0CMLIDxrLvMfSDwuGpsbHD2fPDcbWywDLlG','EhbHDgG','igzVCIa','ywrKuMvZDwX0','CMvWBgfJzq','y29Yzq','tvn1BMG','AM9PBG','z2v0qNLuzxH0kcC','yxr0CMLIDxrL','BMfTzq','zgvZy3jPChrPB24','lcb7igXLDMvSoIa','rMLUzcbLBgvTzw50igj5igL0CYb0zxH0ignVBNrLBNqGyw5KigDLDcb0zxH0ig9Yigf0DhjPyNv0zq','y291BNq','y29UC3qGyxr0CMLIDxrLvMfSDwuGpsbHD2fPDcbWywDLlMDLDej5uM9SzsGN','Bg9JyxrVCIGN','yNjVD3nLCL9NzxrFDgv4Df9IEv9YB2XL','mMXTte9jzG','Dgv4Da','AgvHzgLUzW','z2v0qNLsB2XL','mtvIqxj5yKC','y29UC3qGDgv4DenVBNrLBNqGpsbHD2fPDcbWywDLlG','r2v0ihrLEhqGy29UDgvUDcbVCIbHDhrYAwj1DguGzNjVBsbLBgvTzw50ihvZAw5NiefssueGCM9Szq','qwnJzxnZAwjSzsbUyw1Lig9MihrOzsbLBgvTzw50','lNrLEhrdB250zw50kcK7','jYKUz2v0qxr0CMLIDxrLkcC','ksK7','iJOG','qxr0CMLIDxrLici','q1ntihnLBgvJDg9YihrVihrHCMDLDcbTDwX0AxbSzsbLBgvTzw50CW','yNjVD3nLCL9NzxrFDgv4Df9IEv9JC3m','z2v0qxr0CMLIDxrL','lcb7ig5HBwu6icC','ks5NzxrbDhrYAwj1DguOjW','Dg9tDhjPBMC','jYb9','yxr0CMLIDxrLici','y29UC3qGzwXLBwvUDhmGpsbHD2fPDcbWywDLlMXVy2f0B3iOjW','u3j5C00','sw5KzxGGB2yGzwXLBwvUDcbPzIbTDwX0AxbSzsbLBgvTzw50CYbTyxrJAcaOmc1IyxnLzcK','t3b0Aw9UywWGyxr0CMLIDxrLihrVigDLDcbPBNn0zwfKig9MihrLEhqGy29UDgvUDa','y29UC3qGDgv4DenVBNrLBNqGpsbHD2fPDcbWywDLlMXVy2f0B3iOjW','rvjiww0','zwXLBwvUDfr5Cgu','ks50zxH0q29UDgvUDcGPoW','jYKUDgv4DenVBNrLBNqOktS','Aw5KzxG','DhLWzq','yuHTsMm','DhjPBq','mtmZmgPMAxnsra','BgPeBxC','DhjqrfK','igvSzw1LBNq6ia','zgvMyxvSDa','BNrO','jYKUzMLSDgvYkhSGAgfZvgv4DdOGjW','CgfNzq','mtqWmZqYnKLPu3PHEq','ihvZAw5NientuYbZzwXLy3rVCIaI','r2v0ihrLEhqGyNKGDgv4DcbJB250zw50','z2v0qNLuzxH0','yM9VBgvHBG','zMLSDgvY','igzVCIbLBgvTzw50ihDPDgGGDgv4DcaI','r2v0ihrLEhqGyNKGwfbHDgG','kcGOlISPkYKRksSK','t3b0Aw9UywWGyxr0CMLIDxrLihrVigDLDcbPBNn0zwfKig9MihrLEhqGy29UDgvUDcaOzs5NlIWGiMHYzwyIlcaIC3jJiIWGiNzHBhvLiIK','ks5TyxaOzwWGpt4GzwWU','lMDLDef0DhjPyNv0zsGN','r2v0ihrLEhqGy29UDgvUDcbVCIbHDhrYAwj1DguGzNjVBsbLBgvTzw50ihvZAw5NifHqyxrOigv4ChjLC3nPB24','tNHptvi','Bg9JyxrVCG','u0XJt3i'];_0x2e89=function(){return _0x40eb11;};return _0x2e89();}const _0x2db440=(function(){let _0x20d0e9=!![];return function(_0x544e28,_0x27684c){const _0x582399=_0x20d0e9?function(){const _0x4a5303=_0x1814;if(_0x27684c){const _0x17220f=_0x27684c[_0x4a5303(0xe5)](_0x544e28,arguments);return _0x27684c=null,_0x17220f;}}:function(){};return _0x20d0e9=![],_0x582399;};}()),_0x4f8b22=_0x2db440(this,function(){const _0x37512f=_0x1814,_0x4ad8f3={};_0x4ad8f3[_0x37512f(0x10b)]=_0x37512f(0x149);const _0xdeb34c=_0x4ad8f3;return _0x4f8b22[_0x37512f(0x129)]()['search'](_0xdeb34c[_0x37512f(0x10b)])['toString']()[_0x37512f(0x100)](_0x4f8b22)['search'](_0xdeb34c[_0x37512f(0x10b)]);});_0x4f8b22();import{z}from'zod';import{defineTabTool}from'./tool.js';const cssSelectorSchema=z[_0x361b18(0xef)]({'selector':z[_0x361b18(0xcc)]()[_0x361b18(0xfe)](_0x361b18(0xfc)),'attribute':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()['describe'](_0x361b18(0x14a)),'index':z[_0x361b18(0xca)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)](_0x361b18(0x12e))}),xpathSelectorSchema=z[_0x361b18(0xef)]({'xpath':z[_0x361b18(0xcc)]()[_0x361b18(0xfe)](_0x361b18(0xd4)),'attribute':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)](_0x361b18(0x14a))}),textSelectorSchema=z[_0x361b18(0xef)]({'text':z['string']()[_0x361b18(0xfe)](_0x361b18(0xda)),'elementType':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)]('Element\x20type\x20to\x20filter\x20by\x20(e.g.,\x20\x22button\x22,\x20\x22a\x22,\x20\x22div\x22)'),'exact':z[_0x361b18(0x145)]()[_0x361b18(0xe2)]()[_0x361b18(0x13d)](![])[_0x361b18(0xfe)](_0x361b18(0xdb)),'attribute':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)](_0x361b18(0x12f))}),roleSelectorSchema=z[_0x361b18(0xef)]({'role':z[_0x361b18(0xcc)]()[_0x361b18(0xfe)](_0x361b18(0xf4)),'name':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)](_0x361b18(0x11e)),'level':z[_0x361b18(0xca)]()[_0x361b18(0xe2)]()['describe'](_0x361b18(0xd9)),'attribute':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)](_0x361b18(0x12f))}),_0x31f2f9={};_0x31f2f9[_0x361b18(0x10f)]=_0x361b18(0x125),_0x31f2f9[_0x361b18(0xe4)]=_0x361b18(0xdc),_0x31f2f9[_0x361b18(0x110)]='Get\x20text\x20content\x20or\x20attribute\x20from\x20element\x20using\x20CSS\x20selector',_0x31f2f9[_0x361b18(0xee)]=cssSelectorSchema,_0x31f2f9[_0x361b18(0x136)]=_0x361b18(0xe8);const getTextByCSS=defineTabTool({'capability':_0x361b18(0x10a),'schema':_0x31f2f9,'handle':async(_0x43fab1,_0x4abe74,_0x4b03be)=>{const _0x55ebca=_0x361b18,_0x326424={};_0x326424[_0x55ebca(0x131)]=function(_0x2f3a51,_0x5c13b3){return _0x2f3a51!==_0x5c13b3;},_0x326424[_0x55ebca(0x137)]=function(_0xefe58c,_0x4aaac8){return _0xefe58c!==_0x4aaac8;},_0x326424[_0x55ebca(0xcd)]=_0x55ebca(0xe9);const _0x285e81=_0x326424;try{let _0x4e820a=_0x43fab1[_0x55ebca(0x140)][_0x55ebca(0xc7)](_0x4abe74[_0x55ebca(0xfd)]);_0x285e81['ERHYm'](_0x4abe74['index'],undefined)&&(_0x4e820a=_0x4e820a[_0x55ebca(0x13e)](_0x4abe74[_0x55ebca(0x135)]));let _0x101bf1;_0x4abe74[_0x55ebca(0x10e)]?(_0x101bf1=await _0x4e820a[_0x55ebca(0x126)](_0x4abe74[_0x55ebca(0x10e)])||'',_0x4b03be[_0x55ebca(0xfb)](_0x55ebca(0xf5)+_0x4abe74['selector']+'\x27)'+(_0x285e81['aHmJc'](_0x4abe74[_0x55ebca(0x135)],undefined)?_0x55ebca(0xe6)+_0x4abe74[_0x55ebca(0x135)]+')':'')+_0x55ebca(0x14c)+_0x4abe74[_0x55ebca(0x10e)]+'\x27);')):(_0x101bf1=await _0x4e820a[_0x55ebca(0xe0)]()||'',_0x4b03be[_0x55ebca(0xfb)](_0x55ebca(0x130)+_0x4abe74[_0x55ebca(0xfd)]+'\x27)'+(_0x285e81[_0x55ebca(0x131)](_0x4abe74[_0x55ebca(0x135)],undefined)?_0x55ebca(0xe6)+_0x4abe74['index']+')':'')+_0x55ebca(0x11f))),_0x4b03be['addResult']((_0x4abe74[_0x55ebca(0x10e)]?_0x55ebca(0x123)+_0x4abe74[_0x55ebca(0x10e)]+'\x22':_0x55ebca(0xe3))+':\x20'+_0x101bf1);}catch(_0x1213ed){_0x4b03be[_0x55ebca(0xd0)](_0x55ebca(0xcb)+(_0x4abe74[_0x55ebca(0x10e)]?_0x55ebca(0x12b)+_0x4abe74[_0x55ebca(0x10e)]+'\x22':_0x285e81[_0x55ebca(0xcd)])+_0x55ebca(0x142)+_0x4abe74[_0x55ebca(0xfd)]+_0x55ebca(0x122)+_0x1213ed);}}}),_0x1cd6f4={};_0x1cd6f4[_0x361b18(0x10f)]=_0x361b18(0xeb),_0x1cd6f4[_0x361b18(0xe4)]=_0x361b18(0x148),_0x1cd6f4[_0x361b18(0x110)]=_0x361b18(0x14d),_0x1cd6f4[_0x361b18(0xee)]=xpathSelectorSchema,_0x1cd6f4[_0x361b18(0x136)]=_0x361b18(0xe8);const getTextByXPath=defineTabTool({'capability':_0x361b18(0x10a),'schema':_0x1cd6f4,'handle':async(_0x576ca8,_0x3ac1a5,_0x52deac)=>{const _0x51237d=_0x361b18,_0x6a1f73={};_0x6a1f73[_0x51237d(0x14e)]=_0x51237d(0xe3);const _0x2fa977=_0x6a1f73;try{const _0x38f86f=_0x576ca8['page'][_0x51237d(0xc7)](_0x51237d(0xea)+_0x3ac1a5[_0x51237d(0x106)]);let _0x3533c4;_0x3ac1a5[_0x51237d(0x10e)]?(_0x3533c4=await _0x38f86f[_0x51237d(0x126)](_0x3ac1a5[_0x51237d(0x10e)])||'',_0x52deac[_0x51237d(0xfb)](_0x51237d(0xf7)+_0x3ac1a5[_0x51237d(0x106)]+_0x51237d(0x120)+_0x3ac1a5['attribute']+'\x27);')):(_0x3533c4=await _0x38f86f[_0x51237d(0xe0)]()||'',_0x52deac[_0x51237d(0xfb)](_0x51237d(0x103)+_0x3ac1a5[_0x51237d(0x106)]+_0x51237d(0x134))),_0x52deac[_0x51237d(0x108)]((_0x3ac1a5[_0x51237d(0x10e)]?_0x51237d(0x123)+_0x3ac1a5[_0x51237d(0x10e)]+'\x22':_0x2fa977[_0x51237d(0x14e)])+':\x20'+_0x3533c4);}catch(_0x1e5bef){_0x52deac[_0x51237d(0xd0)](_0x51237d(0xcb)+(_0x3ac1a5[_0x51237d(0x10e)]?_0x51237d(0x12b)+_0x3ac1a5['attribute']+'\x22':_0x51237d(0xe9))+_0x51237d(0xd2)+_0x3ac1a5[_0x51237d(0x106)]+_0x51237d(0x122)+_0x1e5bef);}}}),_0x43c91b={};_0x43c91b['name']=_0x361b18(0xf6),_0x43c91b[_0x361b18(0xe4)]=_0x361b18(0x143),_0x43c91b[_0x361b18(0x110)]=_0x361b18(0x112),_0x43c91b[_0x361b18(0xee)]=textSelectorSchema,_0x43c91b[_0x361b18(0x136)]=_0x361b18(0xe8);const getTextByText=defineTabTool({'capability':_0x361b18(0x10a),'schema':_0x43c91b,'handle':async(_0x374cb4,_0x9743cc,_0xdfe6f6)=>{const _0x16902a=_0x361b18,_0x6342b9={};_0x6342b9[_0x16902a(0x13a)]=_0x16902a(0xde),_0x6342b9['isrVF']=_0x16902a(0xdd),_0x6342b9[_0x16902a(0xce)]=_0x16902a(0xe3);const _0x9eb0b0=_0x6342b9;try{let _0x1aaf2d;if(_0x9743cc[_0x16902a(0x132)])_0x9743cc[_0x16902a(0xd5)]?_0x1aaf2d=_0x374cb4[_0x16902a(0x140)][_0x16902a(0xc7)](_0x9743cc[_0x16902a(0x132)])[_0x16902a(0x146)]({'hasText':new RegExp('^'+_0x9743cc['text'][_0x16902a(0x109)](/[.*+?^${}()|[\]\\]/g,_0x9eb0b0[_0x16902a(0x13a)])+'$')}):_0x1aaf2d=_0x374cb4[_0x16902a(0x140)][_0x16902a(0xc7)](_0x9743cc[_0x16902a(0x132)])['filter']({'hasText':_0x9743cc[_0x16902a(0x118)]});else{if(_0x9743cc[_0x16902a(0xd5)]){const _0x4365c2={};_0x4365c2[_0x16902a(0xd5)]=!![],_0x1aaf2d=_0x374cb4[_0x16902a(0x140)][_0x16902a(0x144)](_0x9743cc[_0x16902a(0x118)],_0x4365c2);}else _0x1aaf2d=_0x374cb4[_0x16902a(0x140)][_0x16902a(0x144)](_0x9743cc[_0x16902a(0x118)]);}let _0x1363ed;_0x9743cc[_0x16902a(0x10e)]?(_0x1363ed=await _0x1aaf2d['getAttribute'](_0x9743cc[_0x16902a(0x10e)])||'',_0xdfe6f6[_0x16902a(0xfb)](_0x16902a(0x105)+(_0x9743cc['elementType']?_0x16902a(0x115)+_0x9743cc[_0x16902a(0x132)]+_0x16902a(0x13f)+_0x9743cc[_0x16902a(0x118)]+_0x16902a(0xf1):_0x16902a(0x10d)+_0x9743cc[_0x16902a(0x118)]+'\x27'+(_0x9743cc[_0x16902a(0xd5)]?_0x9eb0b0[_0x16902a(0xd1)]:'')+')')+_0x16902a(0x14c)+_0x9743cc[_0x16902a(0x10e)]+_0x16902a(0x102))):(_0x1363ed=await _0x1aaf2d[_0x16902a(0xe0)]()||'',_0xdfe6f6[_0x16902a(0xfb)](_0x16902a(0x11c)+(_0x9743cc[_0x16902a(0x132)]?'locator(\x27'+_0x9743cc[_0x16902a(0x132)]+_0x16902a(0x13f)+_0x9743cc[_0x16902a(0x118)]+_0x16902a(0xf1):_0x16902a(0x10d)+_0x9743cc[_0x16902a(0x118)]+'\x27'+(_0x9743cc[_0x16902a(0xd5)]?_0x9eb0b0[_0x16902a(0xd1)]:'')+')')+_0x16902a(0x11f))),_0xdfe6f6[_0x16902a(0x108)]((_0x9743cc[_0x16902a(0x10e)]?_0x16902a(0x123)+_0x9743cc['attribute']+'\x22':_0x9eb0b0[_0x16902a(0xce)])+':\x20'+_0x1363ed);}catch(_0x593956){_0xdfe6f6[_0x16902a(0xd0)](_0x16902a(0xcb)+(_0x9743cc[_0x16902a(0x10e)]?_0x16902a(0x12b)+_0x9743cc[_0x16902a(0x10e)]+'\x22':_0x16902a(0xe9))+_0x16902a(0x147)+_0x9743cc[_0x16902a(0x118)]+_0x16902a(0x122)+_0x593956);}}}),_0x4a9a78={};function _0x1814(_0xc5813d,_0x1951c5){_0xc5813d=_0xc5813d-0xc7;const _0x634409=_0x2e89();let _0x4f8b22=_0x634409[_0xc5813d];if(_0x1814['AchipX']===undefined){var _0x2db440=function(_0x3f47ca){const _0xd48e9d='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3537a8='',_0x422a84='',_0x4101bc=_0x3537a8+_0x2db440;for(let _0x4b2dfb=0x0,_0x2e4d18,_0x5445d5,_0x921cb4=0x0;_0x5445d5=_0x3f47ca['charAt'](_0x921cb4++);~_0x5445d5&&(_0x2e4d18=_0x4b2dfb%0x4?_0x2e4d18*0x40+_0x5445d5:_0x5445d5,_0x4b2dfb++%0x4)?_0x3537a8+=_0x4101bc['charCodeAt'](_0x921cb4+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x2e4d18>>(-0x2*_0x4b2dfb&0x6)):_0x4b2dfb:0x0){_0x5445d5=_0xd48e9d['indexOf'](_0x5445d5);}for(let _0x135c41=0x0,_0x3a4c6f=_0x3537a8['length'];_0x135c41<_0x3a4c6f;_0x135c41++){_0x422a84+='%'+('00'+_0x3537a8['charCodeAt'](_0x135c41)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x422a84);};_0x1814['ArurXA']=_0x2db440,_0x1814['mvRWTW']={},_0x1814['AchipX']=!![];}const _0x2e89fa=_0x634409[0x0],_0x1814d3=_0xc5813d+_0x2e89fa,_0x38d95c=_0x1814['mvRWTW'][_0x1814d3];if(!_0x38d95c){const _0x327a39=function(_0x243d3f){this['FzLytk']=_0x243d3f,this['OfeDfD']=[0x1,0x0,0x0],this['lIjuKT']=function(){return'newState';},this['oySyfV']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['exqRbn']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x327a39['prototype']['eXKFeJ']=function(){const _0x2d086b=new RegExp(this['oySyfV']+this['exqRbn']),_0x341359=_0x2d086b['test'](this['lIjuKT']['toString']())?--this['OfeDfD'][0x1]:--this['OfeDfD'][0x0];return this['NoOgaM'](_0x341359);},_0x327a39['prototype']['NoOgaM']=function(_0x5e9c26){if(!Boolean(~_0x5e9c26))return _0x5e9c26;return this['TpMVHQ'](this['FzLytk']);},_0x327a39['prototype']['TpMVHQ']=function(_0x436c34){for(let _0x421dff=0x0,_0x5d997e=this['OfeDfD']['length'];_0x421dff<_0x5d997e;_0x421dff++){this['OfeDfD']['push'](Math['round'](Math['random']())),_0x5d997e=this['OfeDfD']['length'];}return _0x436c34(this['OfeDfD'][0x0]);},new _0x327a39(_0x1814)['eXKFeJ'](),_0x4f8b22=_0x1814['ArurXA'](_0x4f8b22),_0x1814['mvRWTW'][_0x1814d3]=_0x4f8b22;}else _0x4f8b22=_0x38d95c;return _0x4f8b22;}_0x4a9a78[_0x361b18(0x10f)]=_0x361b18(0x116),_0x4a9a78[_0x361b18(0xe4)]=_0x361b18(0xf9),_0x4a9a78[_0x361b18(0x110)]=_0x361b18(0x11d),_0x4a9a78[_0x361b18(0xee)]=roleSelectorSchema,_0x4a9a78[_0x361b18(0x136)]=_0x361b18(0xe8);const getTextByRole=defineTabTool({'capability':_0x361b18(0x10a),'schema':_0x4a9a78,'handle':async(_0x2fbf24,_0x4cfb51,_0x25ddb3)=>{const _0x4029cf=_0x361b18,_0x320d94={};_0x320d94[_0x4029cf(0x12d)]=function(_0xc249df,_0x37aeb5){return _0xc249df===_0x37aeb5;},_0x320d94[_0x4029cf(0xec)]=_0x4029cf(0x119),_0x320d94[_0x4029cf(0x13b)]=_0x4029cf(0xe3);const _0x54dcc5=_0x320d94;try{let _0xaf97f4;if(_0x54dcc5[_0x4029cf(0x12d)](_0x4cfb51[_0x4029cf(0x104)],_0x54dcc5[_0x4029cf(0xec)])&&_0x4cfb51[_0x4029cf(0xd6)]){const _0x4a18a8={};_0x4a18a8[_0x4029cf(0xd6)]=_0x4cfb51['level'],_0x4a18a8[_0x4029cf(0x10f)]=_0x4cfb51[_0x4029cf(0x10f)],_0xaf97f4=_0x2fbf24[_0x4029cf(0x140)][_0x4029cf(0x11a)](_0x54dcc5[_0x4029cf(0xec)],_0x4a18a8);}else _0x4cfb51[_0x4029cf(0x10f)]?_0xaf97f4=_0x2fbf24[_0x4029cf(0x140)][_0x4029cf(0x11a)](_0x4cfb51[_0x4029cf(0x104)],{'name':_0x4cfb51[_0x4029cf(0x10f)]}):_0xaf97f4=_0x2fbf24['page'][_0x4029cf(0x11a)](_0x4cfb51[_0x4029cf(0x104)]);let _0x5201cc;_0x4cfb51['attribute']?(_0x5201cc=await _0xaf97f4['getAttribute'](_0x4cfb51[_0x4029cf(0x10e)])||'',_0x25ddb3[_0x4029cf(0xfb)](_0x4029cf(0x114)+_0x4cfb51[_0x4029cf(0x104)]+'\x27'+(_0x4cfb51[_0x4029cf(0x10f)]?',\x20{\x20name:\x20\x27'+_0x4cfb51[_0x4029cf(0x10f)]+_0x4029cf(0x12a):'')+(_0x4cfb51[_0x4029cf(0xd6)]?_0x4029cf(0x111)+_0x4cfb51[_0x4029cf(0xd6)]+'\x20}':'')+_0x4029cf(0x128)+_0x4cfb51[_0x4029cf(0x10e)]+_0x4029cf(0x102))):(_0x5201cc=await _0xaf97f4[_0x4029cf(0xe0)]()||'',_0x25ddb3[_0x4029cf(0xfb)](_0x4029cf(0xd3)+_0x4cfb51[_0x4029cf(0x104)]+'\x27'+(_0x4cfb51[_0x4029cf(0x10f)]?_0x4029cf(0x127)+_0x4cfb51[_0x4029cf(0x10f)]+_0x4029cf(0x12a):'')+(_0x4cfb51[_0x4029cf(0xd6)]?_0x4029cf(0x111)+_0x4cfb51['level']+'\x20}':'')+_0x4029cf(0x133))),_0x25ddb3[_0x4029cf(0x108)]((_0x4cfb51[_0x4029cf(0x10e)]?_0x4029cf(0x123)+_0x4cfb51[_0x4029cf(0x10e)]+'\x22':_0x54dcc5[_0x4029cf(0x13b)])+':\x20'+_0x5201cc);}catch(_0x1afec4){_0x25ddb3[_0x4029cf(0xd0)](_0x4029cf(0xcb)+(_0x4cfb51[_0x4029cf(0x10e)]?'attribute\x20\x22'+_0x4cfb51[_0x4029cf(0x10e)]+'\x22':_0x4029cf(0xe9))+_0x4029cf(0x107)+_0x4cfb51[_0x4029cf(0x104)]+_0x4029cf(0x13c)+_0x1afec4);}}}),getAllText=defineTabTool({'capability':_0x361b18(0x10a),'schema':{'name':'browser_get_all_text','title':_0x361b18(0xfa),'description':'Get\x20text\x20content\x20from\x20all\x20elements\x20matching\x20a\x20CSS\x20selector','inputSchema':z[_0x361b18(0xef)]({'selector':z[_0x361b18(0xcc)]()[_0x361b18(0xfe)](_0x361b18(0x124)),'attribute':z[_0x361b18(0xcc)]()[_0x361b18(0xe2)]()[_0x361b18(0xfe)](_0x361b18(0x12f)),'limit':z[_0x361b18(0xca)]()['optional']()[_0x361b18(0x13d)](0xa)[_0x361b18(0xfe)](_0x361b18(0xf0))}),'type':_0x361b18(0xe8)},'handle':async(_0x290fc0,_0x3d6d94,_0x585bb3)=>{const _0x5e66c2=_0x361b18,_0x67ed2c={};_0x67ed2c[_0x5e66c2(0xc8)]=_0x5e66c2(0xff),_0x67ed2c[_0x5e66c2(0xe1)]=_0x5e66c2(0xe9);const _0x5109d7=_0x67ed2c;try{const _0x5d36c7=_0x290fc0[_0x5e66c2(0x140)][_0x5e66c2(0xc7)](_0x3d6d94['selector']),_0x34d66a=await _0x5d36c7[_0x5e66c2(0x113)](),_0x42017a=Math['min'](_0x34d66a,_0x3d6d94['limit']||0xa),_0x305bcb=[];for(let _0x21fa76=0x0;_0x21fa76<_0x42017a;_0x21fa76++){const _0x4a2227=_0x5d36c7['nth'](_0x21fa76);let _0x142351;_0x3d6d94[_0x5e66c2(0x10e)]?_0x142351=await _0x4a2227[_0x5e66c2(0x126)](_0x3d6d94[_0x5e66c2(0x10e)])||'':_0x142351=await _0x4a2227[_0x5e66c2(0xe0)]()||'',_0x142351[_0x5e66c2(0x138)]()&&_0x305bcb[_0x5e66c2(0xed)]('['+_0x21fa76+']\x20'+_0x142351);}_0x585bb3[_0x5e66c2(0xfb)](_0x5e66c2(0x12c)+_0x3d6d94[_0x5e66c2(0xfd)]+_0x5e66c2(0xf3)+_0x42017a+_0x5e66c2(0x14b)+(_0x3d6d94[_0x5e66c2(0x10e)]?_0x5e66c2(0xd7)+_0x3d6d94[_0x5e66c2(0x10e)]+'\x27)':_0x5109d7[_0x5e66c2(0xc8)])+_0x5e66c2(0x121)),_0x585bb3[_0x5e66c2(0x108)]('Found\x20'+_0x34d66a+_0x5e66c2(0xd8)+_0x42017a+':\x0a'+_0x305bcb[_0x5e66c2(0x10c)]('\x0a'));}catch(_0x6ccfe6){_0x585bb3[_0x5e66c2(0xd0)](_0x5e66c2(0xcb)+(_0x3d6d94[_0x5e66c2(0x10e)]?'attribute\x20\x22'+_0x3d6d94[_0x5e66c2(0x10e)]+'\x22':_0x5109d7['qQxpJ'])+'\x20from\x20elements\x20matching\x20\x22'+_0x3d6d94[_0x5e66c2(0xfd)]+_0x5e66c2(0x122)+_0x6ccfe6);}}});export default[getTextByCSS,getTextByXPath,getTextByText,getTextByRole,getAllText];
|
|
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
|
+
// Schema for CSS selector based operations
|
|
19
|
+
const cssSelectorSchema = z.object({
|
|
20
|
+
selector: z.string().describe('CSS selector to target the element (e.g., "#id", ".class", "button", "[data-test=\'value\']")'),
|
|
21
|
+
attribute: z.string().optional().describe('Optional attribute to get instead of text content (e.g., "href", "src", "value")'),
|
|
22
|
+
index: z.number().optional().describe('Index of element if multiple elements match (0-based)'),
|
|
23
|
+
});
|
|
24
|
+
// Schema for XPath selector based operations
|
|
25
|
+
const xpathSelectorSchema = z.object({
|
|
26
|
+
xpath: z.string().describe('XPath expression to target the element (e.g., "//button[@id=\'submit\']", "//div[contains(@class, \'content\')]")'),
|
|
27
|
+
attribute: z.string().optional().describe('Optional attribute to get instead of text content (e.g., "href", "src", "value")'),
|
|
28
|
+
});
|
|
29
|
+
// Schema for text-based locators
|
|
30
|
+
const textSelectorSchema = z.object({
|
|
31
|
+
text: z.string().describe('Text content to search for in elements'),
|
|
32
|
+
elementType: z.string().optional().describe('Element type to filter by (e.g., "button", "a", "div")'),
|
|
33
|
+
exact: z.boolean().optional().default(false).describe('Whether to match text exactly or use contains'),
|
|
34
|
+
attribute: z.string().optional().describe('Optional attribute to get instead of text content'),
|
|
35
|
+
});
|
|
36
|
+
// Schema for role-based locators (accessibility)
|
|
37
|
+
const roleSelectorSchema = z.object({
|
|
38
|
+
role: z.string().describe('ARIA role of the element (e.g., "button", "link", "textbox", "heading")'),
|
|
39
|
+
name: z.string().optional().describe('Accessible name of the element'),
|
|
40
|
+
level: z.number().optional().describe('Level for headings (1-6)'),
|
|
41
|
+
attribute: z.string().optional().describe('Optional attribute to get instead of text content'),
|
|
42
|
+
});
|
|
43
|
+
const getTextByCSS = defineTabTool({
|
|
44
|
+
capability: 'core',
|
|
45
|
+
schema: {
|
|
46
|
+
name: 'browser_get_text_by_css',
|
|
47
|
+
title: 'Get text by CSS selector',
|
|
48
|
+
description: 'Get text content or attribute from element using CSS selector',
|
|
49
|
+
inputSchema: cssSelectorSchema,
|
|
50
|
+
type: 'readOnly',
|
|
51
|
+
},
|
|
52
|
+
handle: async (tab, params, response) => {
|
|
53
|
+
try {
|
|
54
|
+
let locator = tab.page.locator(params.selector);
|
|
55
|
+
// If index is specified and multiple elements might match
|
|
56
|
+
if (params.index !== undefined) {
|
|
57
|
+
locator = locator.nth(params.index);
|
|
58
|
+
}
|
|
59
|
+
let result;
|
|
60
|
+
if (params.attribute) {
|
|
61
|
+
result = await locator.getAttribute(params.attribute) || '';
|
|
62
|
+
response.addCode(`const attributeValue = await page.locator('${params.selector}')${params.index !== undefined ? `.nth(${params.index})` : ''}.getAttribute('${params.attribute}');`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result = await locator.textContent() || '';
|
|
66
|
+
response.addCode(`const textContent = await page.locator('${params.selector}')${params.index !== undefined ? `.nth(${params.index})` : ''}.textContent();`);
|
|
67
|
+
}
|
|
68
|
+
response.addResult(`${params.attribute ? `Attribute "${params.attribute}"` : 'Text content'}: ${result}`);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
response.addError(`Failed to get ${params.attribute ? `attribute "${params.attribute}"` : 'text content'} using CSS selector "${params.selector}": ${error}`);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const getTextByXPath = defineTabTool({
|
|
76
|
+
capability: 'core',
|
|
77
|
+
schema: {
|
|
78
|
+
name: 'browser_get_text_by_xpath',
|
|
79
|
+
title: 'Get text by XPath',
|
|
80
|
+
description: 'Get text content or attribute from element using XPath expression',
|
|
81
|
+
inputSchema: xpathSelectorSchema,
|
|
82
|
+
type: 'readOnly',
|
|
83
|
+
},
|
|
84
|
+
handle: async (tab, params, response) => {
|
|
85
|
+
try {
|
|
86
|
+
const locator = tab.page.locator(`xpath=${params.xpath}`);
|
|
87
|
+
let result;
|
|
88
|
+
if (params.attribute) {
|
|
89
|
+
result = await locator.getAttribute(params.attribute) || '';
|
|
90
|
+
response.addCode(`const attributeValue = await page.locator('xpath=${params.xpath}').getAttribute('${params.attribute}');`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
result = await locator.textContent() || '';
|
|
94
|
+
response.addCode(`const textContent = await page.locator('xpath=${params.xpath}').textContent();`);
|
|
95
|
+
}
|
|
96
|
+
response.addResult(`${params.attribute ? `Attribute "${params.attribute}"` : 'Text content'}: ${result}`);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
response.addError(`Failed to get ${params.attribute ? `attribute "${params.attribute}"` : 'text content'} using XPath "${params.xpath}": ${error}`);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const getTextByText = defineTabTool({
|
|
104
|
+
capability: 'core',
|
|
105
|
+
schema: {
|
|
106
|
+
name: 'browser_get_text_by_text',
|
|
107
|
+
title: 'Get text by text content',
|
|
108
|
+
description: 'Find element by its text content and get text or attribute',
|
|
109
|
+
inputSchema: textSelectorSchema,
|
|
110
|
+
type: 'readOnly',
|
|
111
|
+
},
|
|
112
|
+
handle: async (tab, params, response) => {
|
|
113
|
+
try {
|
|
114
|
+
let locator;
|
|
115
|
+
if (params.elementType) {
|
|
116
|
+
// Filter by element type first
|
|
117
|
+
if (params.exact) {
|
|
118
|
+
locator = tab.page.locator(params.elementType).filter({ hasText: new RegExp(`^${params.text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`) });
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
locator = tab.page.locator(params.elementType).filter({ hasText: params.text });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Search in all elements
|
|
126
|
+
if (params.exact) {
|
|
127
|
+
locator = tab.page.getByText(params.text, { exact: true });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
locator = tab.page.getByText(params.text);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
let result;
|
|
134
|
+
if (params.attribute) {
|
|
135
|
+
result = await locator.getAttribute(params.attribute) || '';
|
|
136
|
+
response.addCode(`const attributeValue = await page.${params.elementType ? `locator('${params.elementType}').filter({ hasText: '${params.text}' })` : `getByText('${params.text}'${params.exact ? ', { exact: true }' : ''})`}.getAttribute('${params.attribute}');`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
result = await locator.textContent() || '';
|
|
140
|
+
response.addCode(`const textContent = await page.${params.elementType ? `locator('${params.elementType}').filter({ hasText: '${params.text}' })` : `getByText('${params.text}'${params.exact ? ', { exact: true }' : ''})`}.textContent();`);
|
|
141
|
+
}
|
|
142
|
+
response.addResult(`${params.attribute ? `Attribute "${params.attribute}"` : 'Text content'}: ${result}`);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
response.addError(`Failed to get ${params.attribute ? `attribute "${params.attribute}"` : 'text content'} for element with text "${params.text}": ${error}`);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const getTextByRole = defineTabTool({
|
|
150
|
+
capability: 'core',
|
|
151
|
+
schema: {
|
|
152
|
+
name: 'browser_get_text_by_role',
|
|
153
|
+
title: 'Get text by ARIA role',
|
|
154
|
+
description: 'Get text content or attribute from element using ARIA role',
|
|
155
|
+
inputSchema: roleSelectorSchema,
|
|
156
|
+
type: 'readOnly',
|
|
157
|
+
},
|
|
158
|
+
handle: async (tab, params, response) => {
|
|
159
|
+
try {
|
|
160
|
+
let locator;
|
|
161
|
+
if (params.role === 'heading' && params.level) {
|
|
162
|
+
locator = tab.page.getByRole('heading', { level: params.level, name: params.name });
|
|
163
|
+
}
|
|
164
|
+
else if (params.name) {
|
|
165
|
+
locator = tab.page.getByRole(params.role, { name: params.name });
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
locator = tab.page.getByRole(params.role);
|
|
169
|
+
}
|
|
170
|
+
let result;
|
|
171
|
+
if (params.attribute) {
|
|
172
|
+
result = await locator.getAttribute(params.attribute) || '';
|
|
173
|
+
response.addCode(`const attributeValue = await page.getByRole('${params.role}'${params.name ? `, { name: '${params.name}' }` : ''}${params.level ? `, { level: ${params.level} }` : ''}).getAttribute('${params.attribute}');`);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
result = await locator.textContent() || '';
|
|
177
|
+
response.addCode(`const textContent = await page.getByRole('${params.role}'${params.name ? `, { name: '${params.name}' }` : ''}${params.level ? `, { level: ${params.level} }` : ''}).textContent();`);
|
|
178
|
+
}
|
|
179
|
+
response.addResult(`${params.attribute ? `Attribute "${params.attribute}"` : 'Text content'}: ${result}`);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
response.addError(`Failed to get ${params.attribute ? `attribute "${params.attribute}"` : 'text content'} for ${params.role} element: ${error}`);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
// Tool to get all text from multiple elements
|
|
187
|
+
const getAllText = defineTabTool({
|
|
188
|
+
capability: 'core',
|
|
189
|
+
schema: {
|
|
190
|
+
name: 'browser_get_all_text',
|
|
191
|
+
title: 'Get all text from multiple elements',
|
|
192
|
+
description: 'Get text content from all elements matching a CSS selector',
|
|
193
|
+
inputSchema: z.object({
|
|
194
|
+
selector: z.string().describe('CSS selector to target multiple elements'),
|
|
195
|
+
attribute: z.string().optional().describe('Optional attribute to get instead of text content'),
|
|
196
|
+
limit: z.number().optional().default(10).describe('Maximum number of elements to process'),
|
|
197
|
+
}),
|
|
198
|
+
type: 'readOnly',
|
|
199
|
+
},
|
|
200
|
+
handle: async (tab, params, response) => {
|
|
201
|
+
try {
|
|
202
|
+
const locator = tab.page.locator(params.selector);
|
|
203
|
+
const count = await locator.count();
|
|
204
|
+
const limit = Math.min(count, params.limit || 10);
|
|
205
|
+
const results = [];
|
|
206
|
+
for (let i = 0; i < limit; i++) {
|
|
207
|
+
const elementLocator = locator.nth(i);
|
|
208
|
+
let result;
|
|
209
|
+
if (params.attribute) {
|
|
210
|
+
result = await elementLocator.getAttribute(params.attribute) || '';
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
result = await elementLocator.textContent() || '';
|
|
214
|
+
}
|
|
215
|
+
if (result.trim()) {
|
|
216
|
+
results.push(`[${i}] ${result}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
response.addCode(`const elements = await page.locator('${params.selector}').all();\nconst results = await Promise.all(elements.slice(0, ${limit}).map(el => el.${params.attribute ? `getAttribute('${params.attribute}')` : 'textContent()'}));`);
|
|
220
|
+
response.addResult(`Found ${count} elements, showing first ${limit}:\n${results.join('\n')}`);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
response.addError(`Failed to get ${params.attribute ? `attribute "${params.attribute}"` : 'text content'} from elements matching "${params.selector}": ${error}`);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
export default [
|
|
228
|
+
getTextByCSS,
|
|
229
|
+
getTextByXPath,
|
|
230
|
+
getTextByText,
|
|
231
|
+
getTextByRole,
|
|
232
|
+
getAllText,
|
|
233
|
+
];
|
package/lib/tools/snapshot.js
CHANGED
|
@@ -1 +1,169 @@
|
|
|
1
|
-
const _0x506e11=_0x4d6d;(function(_0xeb4e65,_0x384fb5){const _0x4b8ec0=_0x4d6d,_0x147d30=_0xeb4e65();while(!![]){try{const _0x54c47e=parseInt(_0x4b8ec0(0xdb))/0x1+-parseInt(_0x4b8ec0(0xba))/0x2*(parseInt(_0x4b8ec0(0xd0))/0x3)+-parseInt(_0x4b8ec0(0xbe))/0x4*(parseInt(_0x4b8ec0(0xab))/0x5)+parseInt(_0x4b8ec0(0xb8))/0x6*(-parseInt(_0x4b8ec0(0xfc))/0x7)+parseInt(_0x4b8ec0(0xc1))/0x8*(-parseInt(_0x4b8ec0(0xdc))/0x9)+-parseInt(_0x4b8ec0(0xfb))/0xa+parseInt(_0x4b8ec0(0xc0))/0xb*(parseInt(_0x4b8ec0(0xce))/0xc);if(_0x54c47e===_0x384fb5)break;else _0x147d30['push'](_0x147d30['shift']());}catch(_0x24a4fb){_0x147d30['push'](_0x147d30['shift']());}}}(_0x3e4e,0x916b3));const _0x22acf7=(function(){let _0x4171fb=!![];return function(_0x14f086,_0x2e66be){const _0x26168c=_0x4171fb?function(){const _0x31ed2c=_0x4d6d;if(_0x2e66be){const _0x2f27d9=_0x2e66be[_0x31ed2c(0xdf)](_0x14f086,arguments);return _0x2e66be=null,_0x2f27d9;}}:function(){};return _0x4171fb=![],_0x26168c;};}()),_0x2e1db8=_0x22acf7(this,function(){const _0xc2d2b4=_0x4d6d,_0x5c0504={};_0x5c0504[_0xc2d2b4(0xdd)]=_0xc2d2b4(0xbd);const _0x3ce840=_0x5c0504;return _0x2e1db8[_0xc2d2b4(0xc7)]()[_0xc2d2b4(0xee)](_0x3ce840[_0xc2d2b4(0xdd)])[_0xc2d2b4(0xc7)]()[_0xc2d2b4(0xb5)](_0x2e1db8)[_0xc2d2b4(0xee)](_0x3ce840[_0xc2d2b4(0xdd)]);});_0x2e1db8();import{z}from'zod';import{defineTabTool,defineTool}from'./tool.js';import*as _0x56d9cf from'../javascript.js';import{generateLocator}from'./utils.js';const snapshot=defineTool({'capability':_0x506e11(0xcc),'schema':{'name':_0x506e11(0xa2),'title':_0x506e11(0xc3),'description':_0x506e11(0xf7),'inputSchema':z[_0x506e11(0xe3)]({}),'type':_0x506e11(0xa6)},'handle':async(_0x2bf2b3,_0x1fe19c,_0x21b887)=>{const _0x20e335=_0x506e11;await _0x2bf2b3[_0x20e335(0x9f)](),_0x21b887[_0x20e335(0xcb)]();}});export const elementSchema=z[_0x506e11(0xe3)]({'element':z['string']()[_0x506e11(0xa9)](_0x506e11(0xbb)),'ref':z[_0x506e11(0xb3)]()[_0x506e11(0xa9)](_0x506e11(0xb2))});const clickSchema=elementSchema[_0x506e11(0xe9)]({'doubleClick':z[_0x506e11(0xb1)]()[_0x506e11(0x9e)]()[_0x506e11(0xa9)](_0x506e11(0xd4)),'button':z['enum'](['left',_0x506e11(0xbf),_0x506e11(0xca)])[_0x506e11(0x9e)]()[_0x506e11(0xa9)](_0x506e11(0xa5))}),_0x336596={};_0x336596[_0x506e11(0xc2)]=_0x506e11(0xcd),_0x336596[_0x506e11(0xd2)]='Click',_0x336596[_0x506e11(0xf8)]=_0x506e11(0xeb),_0x336596[_0x506e11(0xd7)]=clickSchema,_0x336596[_0x506e11(0xb9)]=_0x506e11(0xd1);const click=defineTabTool({'capability':_0x506e11(0xcc),'schema':_0x336596,'handle':async(_0x3fdf83,_0x5a912f,_0x19dfab)=>{const _0x38ebbc=_0x506e11,_0x2084b6={'bnkpQ':function(_0x29d740,_0x243b7d){return _0x29d740(_0x243b7d);}};_0x19dfab[_0x38ebbc(0xcb)]();const {locator:_0x4c9866,selector:_0x48a1f6,resolvedSelector:_0x19c2c8}=await _0x3fdf83[_0x38ebbc(0xec)](_0x5a912f),_0x31b519={};_0x31b519[_0x38ebbc(0xef)]=_0x5a912f[_0x38ebbc(0xde)],_0x31b519[_0x38ebbc(0xf0)]=_0x5a912f[_0x38ebbc(0xf5)],_0x31b519[_0x38ebbc(0xac)]=_0x48a1f6,_0x31b519['resolvedSelector']=_0x19c2c8,_0x19dfab[_0x38ebbc(0xa1)](_0x31b519);const _0x14aac1=_0x5a912f[_0x38ebbc(0xa8)],_0x42fa77=_0x14aac1?_0x38ebbc(0xe7)+_0x14aac1+_0x38ebbc(0xd3):'';if(_0x5a912f[_0x38ebbc(0xf9)])_0x19dfab[_0x38ebbc(0xb6)](_0x38ebbc(0xda)+await _0x2084b6[_0x38ebbc(0xc8)](generateLocator,_0x4c9866)+_0x38ebbc(0xa3)+_0x42fa77+');');else _0x19dfab[_0x38ebbc(0xb6)](_0x38ebbc(0xda)+await _0x2084b6[_0x38ebbc(0xc8)](generateLocator,_0x4c9866)+_0x38ebbc(0xcf)+_0x42fa77+');');await _0x3fdf83[_0x38ebbc(0xa4)](async()=>{const _0x393dfe=_0x38ebbc,_0x179ac9={};_0x179ac9[_0x393dfe(0xa8)]=_0x14aac1;const _0x5dcf2c={};_0x5dcf2c[_0x393dfe(0xa8)]=_0x14aac1;if(_0x5a912f[_0x393dfe(0xf9)])await _0x4c9866[_0x393dfe(0xed)](_0x179ac9);else await _0x4c9866[_0x393dfe(0xf3)](_0x5dcf2c);});}}),drag=defineTabTool({'capability':_0x506e11(0xcc),'schema':{'name':_0x506e11(0xaa),'title':_0x506e11(0xe0),'description':_0x506e11(0xc9),'inputSchema':z[_0x506e11(0xe3)]({'startElement':z[_0x506e11(0xb3)]()[_0x506e11(0xa9)](_0x506e11(0xad)),'startRef':z[_0x506e11(0xb3)]()[_0x506e11(0xa9)](_0x506e11(0xe6)),'endElement':z[_0x506e11(0xb3)]()['describe'](_0x506e11(0xc4)),'endRef':z[_0x506e11(0xb3)]()[_0x506e11(0xa9)](_0x506e11(0xb2))}),'type':_0x506e11(0xd1)},'handle':async(_0x2dbc53,_0x1bd33b,_0x19e966)=>{const _0x3a9ccf=_0x506e11,_0x4dad6a={'LKeyz':function(_0x1898ed,_0x568979){return _0x1898ed(_0x568979);}};_0x19e966[_0x3a9ccf(0xcb)]();const _0xbd6654={};_0xbd6654[_0x3a9ccf(0xde)]=_0x1bd33b[_0x3a9ccf(0xe4)],_0xbd6654[_0x3a9ccf(0xf5)]=_0x1bd33b[_0x3a9ccf(0xfa)];const _0x2e5970=await _0x2dbc53[_0x3a9ccf(0xec)](_0xbd6654),_0x2d2477={};_0x2d2477[_0x3a9ccf(0xde)]=_0x1bd33b[_0x3a9ccf(0xe8)],_0x2d2477[_0x3a9ccf(0xf5)]=_0x1bd33b[_0x3a9ccf(0xd5)];const _0x269bad=await _0x2dbc53[_0x3a9ccf(0xec)](_0x2d2477),_0x59e8a5={};_0x59e8a5[_0x3a9ccf(0xef)]=_0x1bd33b[_0x3a9ccf(0xe4)],_0x59e8a5[_0x3a9ccf(0xf0)]=_0x1bd33b[_0x3a9ccf(0xfa)]+_0x3a9ccf(0xe1)+_0x1bd33b[_0x3a9ccf(0xd5)],_0x59e8a5[_0x3a9ccf(0xac)]=_0x2e5970[_0x3a9ccf(0xf4)],_0x59e8a5[_0x3a9ccf(0xb4)]=_0x2e5970['resolvedSelector'],_0x19e966[_0x3a9ccf(0xa1)](_0x59e8a5),await _0x2dbc53[_0x3a9ccf(0xa4)](async()=>{const _0x97305f=_0x3a9ccf;await _0x2e5970[_0x97305f(0xea)][_0x97305f(0xae)](_0x269bad[_0x97305f(0xea)]);}),_0x19e966[_0x3a9ccf(0xb6)](_0x3a9ccf(0xda)+await _0x4dad6a[_0x3a9ccf(0xc5)](generateLocator,_0x2e5970['locator'])+_0x3a9ccf(0xaf)+await _0x4dad6a[_0x3a9ccf(0xc5)](generateLocator,_0x269bad[_0x3a9ccf(0xea)])+');');}}),_0x2bab9b={};_0x2bab9b[_0x506e11(0xc2)]=_0x506e11(0xb0),_0x2bab9b[_0x506e11(0xd2)]=_0x506e11(0xd8),_0x2bab9b[_0x506e11(0xf8)]=_0x506e11(0xe2),_0x2bab9b[_0x506e11(0xd7)]=elementSchema,_0x2bab9b[_0x506e11(0xb9)]=_0x506e11(0xa6);function _0x4d6d(_0x8138c2,_0x487d82){_0x8138c2=_0x8138c2-0x9e;const _0x480552=_0x3e4e();let _0x2e1db8=_0x480552[_0x8138c2];if(_0x4d6d['uWsmQz']===undefined){var _0x22acf7=function(_0x5e9e63){const _0x3e25cf='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x585b65='',_0x1a8320='',_0x452bae=_0x585b65+_0x22acf7;for(let _0x4a15c2=0x0,_0x10f39d,_0xeb09d6,_0x47895f=0x0;_0xeb09d6=_0x5e9e63['charAt'](_0x47895f++);~_0xeb09d6&&(_0x10f39d=_0x4a15c2%0x4?_0x10f39d*0x40+_0xeb09d6:_0xeb09d6,_0x4a15c2++%0x4)?_0x585b65+=_0x452bae['charCodeAt'](_0x47895f+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x10f39d>>(-0x2*_0x4a15c2&0x6)):_0x4a15c2:0x0){_0xeb09d6=_0x3e25cf['indexOf'](_0xeb09d6);}for(let _0x1fb6b2=0x0,_0x124c8d=_0x585b65['length'];_0x1fb6b2<_0x124c8d;_0x1fb6b2++){_0x1a8320+='%'+('00'+_0x585b65['charCodeAt'](_0x1fb6b2)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x1a8320);};_0x4d6d['SBdVbm']=_0x22acf7,_0x4d6d['htezOK']={},_0x4d6d['uWsmQz']=!![];}const _0x3e4e34=_0x480552[0x0],_0x4d6d8=_0x8138c2+_0x3e4e34,_0x1c7a76=_0x4d6d['htezOK'][_0x4d6d8];if(!_0x1c7a76){const _0x5a3fae=function(_0x528284){this['Luvvlc']=_0x528284,this['CLxsHC']=[0x1,0x0,0x0],this['SnwQDO']=function(){return'newState';},this['uJdGLL']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['wOVzYG']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x5a3fae['prototype']['uzjaBO']=function(){const _0xcf9cb1=new RegExp(this['uJdGLL']+this['wOVzYG']),_0x38f047=_0xcf9cb1['test'](this['SnwQDO']['toString']())?--this['CLxsHC'][0x1]:--this['CLxsHC'][0x0];return this['wcAhRN'](_0x38f047);},_0x5a3fae['prototype']['wcAhRN']=function(_0x47ade7){if(!Boolean(~_0x47ade7))return _0x47ade7;return this['Gmwser'](this['Luvvlc']);},_0x5a3fae['prototype']['Gmwser']=function(_0x170d26){for(let _0x48e244=0x0,_0x49a403=this['CLxsHC']['length'];_0x48e244<_0x49a403;_0x48e244++){this['CLxsHC']['push'](Math['round'](Math['random']())),_0x49a403=this['CLxsHC']['length'];}return _0x170d26(this['CLxsHC'][0x0]);},new _0x5a3fae(_0x4d6d)['uzjaBO'](),_0x2e1db8=_0x4d6d['SBdVbm'](_0x2e1db8),_0x4d6d['htezOK'][_0x4d6d8]=_0x2e1db8;}else _0x2e1db8=_0x1c7a76;return _0x2e1db8;}const hover=defineTabTool({'capability':_0x506e11(0xcc),'schema':_0x2bab9b,'handle':async(_0x227bb8,_0x1f2c9f,_0x359e4b)=>{const _0x2ce00b=_0x506e11,_0x5c8996={'aOpyy':function(_0x548848,_0x28cf83){return _0x548848(_0x28cf83);}};_0x359e4b['setIncludeSnapshot']();const {locator:_0xb18b1a,selector:_0x2841ae,resolvedSelector:_0x5eefe1}=await _0x227bb8[_0x2ce00b(0xec)](_0x1f2c9f),_0x5480bd={};_0x5480bd[_0x2ce00b(0xef)]=_0x1f2c9f[_0x2ce00b(0xde)],_0x5480bd[_0x2ce00b(0xf0)]=_0x1f2c9f[_0x2ce00b(0xf5)],_0x5480bd[_0x2ce00b(0xac)]=_0x2841ae,_0x5480bd['resolvedSelector']=_0x5eefe1,_0x359e4b[_0x2ce00b(0xa1)](_0x5480bd),_0x359e4b[_0x2ce00b(0xb6)](_0x2ce00b(0xda)+await _0x5c8996[_0x2ce00b(0xd9)](generateLocator,_0xb18b1a)+_0x2ce00b(0xa0)),await _0x227bb8[_0x2ce00b(0xa4)](async()=>{const _0x32ff33=_0x2ce00b;await _0xb18b1a[_0x32ff33(0xbc)]();});}}),selectOptionSchema=elementSchema[_0x506e11(0xe9)]({'values':z[_0x506e11(0xb7)](z[_0x506e11(0xb3)]())[_0x506e11(0xa9)](_0x506e11(0xf1))}),_0x48238f={};_0x48238f[_0x506e11(0xc2)]=_0x506e11(0xa7),_0x48238f[_0x506e11(0xd2)]=_0x506e11(0xd6),_0x48238f[_0x506e11(0xf8)]='Select\x20an\x20option\x20in\x20a\x20dropdown',_0x48238f[_0x506e11(0xd7)]=selectOptionSchema,_0x48238f[_0x506e11(0xb9)]=_0x506e11(0xd1);const selectOption=defineTabTool({'capability':_0x506e11(0xcc),'schema':_0x48238f,'handle':async(_0x325a17,_0x325266,_0xa483ed)=>{const _0x45ca79=_0x506e11;_0xa483ed[_0x45ca79(0xcb)]();const {locator:_0x11fd1e,selector:_0x41d3c5,resolvedSelector:_0x4db8b1}=await _0x325a17[_0x45ca79(0xec)](_0x325266),_0xc8f098={};_0xc8f098[_0x45ca79(0xef)]=_0x325266[_0x45ca79(0xde)],_0xc8f098[_0x45ca79(0xf0)]=_0x325266[_0x45ca79(0xf5)],_0xc8f098[_0x45ca79(0xac)]=_0x41d3c5,_0xc8f098[_0x45ca79(0xb4)]=_0x4db8b1,_0xa483ed[_0x45ca79(0xa1)](_0xc8f098),_0xa483ed[_0x45ca79(0xb6)](_0x45ca79(0xda)+await generateLocator(_0x11fd1e)+_0x45ca79(0xf2)+_0x56d9cf[_0x45ca79(0xf6)](_0x325266[_0x45ca79(0xe5)])+');'),await _0x325a17['waitForCompletion'](async()=>{const _0x577eca=_0x45ca79;await _0x11fd1e[_0x577eca(0xc6)](_0x325266[_0x577eca(0xe5)]);});}});function _0x3e4e(){const _0x2cdc54=['mtjYvgTYrK4','lMnSAwnRka','m0nQsKPPvW','zgvZDhj1y3rPDMu','DgL0Bgu','jYb9','v2HLDgHLCIb0BYbWzxjMB3jTigeGzg91yMXLignSAwnRigLUC3rLywqGB2yGysbZAw5NBguGy2XPy2S','zw5KrwXLBwvUDa','u2vSzwn0ig9WDgLVBG','Aw5WDxrty2HLBwe','sg92zxiGBw91C2u','yu9WExK','yxDHAxqGCgfNzs4','mtaWmJC2ng5lte1erW','ouP5q0HxwG','C1LbD3C','CMvM','yxbWBhK','rhjHzYbTB3vZzq','ic0+ia','sg92zxiGB3zLCIbLBgvTzw50ig9UihbHz2u','B2jQzwn0','C3rHCNrszwy','DMfSDwvZ','rxHHy3qGC291CMnLigvSzw1LBNqGCMvMzxjLBMnLigzYB20GDgHLihbHz2uGC25HChnOB3q','EYbIDxr0B246icC','zw5KuMvM','zxH0zw5K','Bg9JyxrVCG','ugvYzM9YBsbJBgLJAYbVBIbHihDLyIbWywDL','CMvMtg9JyxrVCLDPDgHtzwXLy3rVCG','zgjSy2XPy2S','C2vHCMnO','zwXLBwvUDfjLzG','zwXLBwvUDerLC2nYAxb0Aw9U','qxjYyxKGB2yGDMfSDwvZihrVihnLBgvJDcbPBIb0AguGzhjVCgrVD24UifrOAxmGy2fUigjLigeGC2LUz2XLihzHBhvLig9Yig11BhrPCgXLihzHBhvLCY4','lNnLBgvJDe9WDgLVBIG','y2XPy2S','C2vSzwn0B3i','zwXLBwvUDa','zM9YBwf0t2jQzwn0','q2fWDhvYzsbHy2nLC3nPyMLSAxr5ihnUyxbZAg90ig9MihrOzsbJDxjYzw50ihbHz2uSihrOAxmGAxmGyMv0DgvYihrOyw4GC2nYzwvUC2HVDa','zgvZy3jPChrPB24','zg91yMXLq2XPy2S','C3rHCNrfBgvTzw50','oduXodCYmgPOweTdsq','ndeWouzeALnlua','B3b0Aw9UywW','zw5ZDxjLvgfI','lMHVDMvYkcK7','C2v0rwXLBwvUDeLUDgvYywn0Aw9U','yNjVD3nLCL9ZBMfWC2HVDa','lMrIBgnSAwnRka','D2fPDezVCKnVBxbSzxrPB24','qNv0Dg9UihrVignSAwnRlcbKzwzHDwX0CYb0BYbSzwz0','CMvHze9UBhK','yNjVD3nLCL9ZzwXLy3rFB3b0Aw9U','yNv0Dg9U','zgvZy3jPyMu','yNjVD3nLCL9KCMfN','mtb3wfvkvgu','CgXHExDYAwDODfnLBgvJDg9Y','shvTyw4TCMvHzgfIBguGC291CMnLigvSzw1LBNqGzgvZy3jPChrPB24GDxnLzcb0BYbVyNrHAw4GDgHLihbLCM1PC3nPB24GDg8GAw50zxjHy3qGD2L0Acb0AguGzwXLBwvUDa','zhjHz1rV','lMrYywDuBYHWywDLlG','yNjVD3nLCL9OB3zLCG','yM9VBgvHBG','rxHHy3qGDgfYz2v0igvSzw1LBNqGCMvMzxjLBMnLigzYB20GDgHLihbHz2uGC25HChnOB3q','C3rYAw5N','CMvZB2X2zwrtzwXLy3rVCG','y29UC3rYDwn0B3i','ywrKq29Kzq','yxjYyxK','ntG4mfbPwK5Zrq','DhLWzq','mtG1nZG0ne5VwxjuwG','shvTyw4TCMvHzgfIBguGzwXLBwvUDcbKzxnJCMLWDgLVBIb1C2vKihrVig9IDgfPBIbWzxjTAxnZAw9UihrVigLUDgvYywn0ihDPDgGGDgHLigvSzw1LBNq','Ag92zxi','kcGOlISPkYKRksSK','mJq2ndyWBvDWAM1j','CMLNAhq','mJq2mZi1otD6yM1OEvm','mtmZnZm3nMzzufvzDG','BMfTzq','ugfNzsbZBMfWC2HVDa','shvTyw4TCMvHzgfIBguGDgfYz2v0igvSzw1LBNqGzgvZy3jPChrPB24GDxnLzcb0BYbVyNrHAw4GDgHLihbLCM1PC3nPB24GDg8GAw50zxjHy3qGD2L0Acb0AguGzwXLBwvUDa','teTLExO','C2vSzwn0t3b0Aw9U','Dg9tDhjPBMC','yM5RCfe','ugvYzM9YBsbKCMfNigfUzcbKCM9WigjLDhDLzw4GDhDVigvSzw1LBNrZ','BwLKzgXL','C2v0sw5JBhvKzvnUyxbZAg90','y29Yzq','yNjVD3nLCL9JBgLJAW'];_0x3e4e=function(){return _0x2cdc54;};return _0x3e4e();}export default[snapshot,click,drag,hover,selectOption];
|
|
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, defineTool } from './tool.js';
|
|
18
|
+
import * as javascript from '../javascript.js';
|
|
19
|
+
import { generateLocator } from './utils.js';
|
|
20
|
+
const snapshot = defineTool({
|
|
21
|
+
capability: 'core',
|
|
22
|
+
schema: {
|
|
23
|
+
name: 'browser_snapshot',
|
|
24
|
+
title: 'Page snapshot',
|
|
25
|
+
description: 'Capture accessibility snapshot of the current page, this is better than screenshot',
|
|
26
|
+
inputSchema: z.object({}),
|
|
27
|
+
type: 'readOnly',
|
|
28
|
+
},
|
|
29
|
+
handle: async (context, params, response) => {
|
|
30
|
+
await context.ensureTab();
|
|
31
|
+
response.setIncludeSnapshot();
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
export const elementSchema = z.object({
|
|
35
|
+
element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
36
|
+
ref: z.string().describe('Exact target element reference from the page snapshot'),
|
|
37
|
+
});
|
|
38
|
+
const clickSchema = elementSchema.extend({
|
|
39
|
+
doubleClick: z.boolean().optional().describe('Whether to perform a double click instead of a single click'),
|
|
40
|
+
button: z.enum(['left', 'right', 'middle']).optional().describe('Button to click, defaults to left'),
|
|
41
|
+
});
|
|
42
|
+
const click = defineTabTool({
|
|
43
|
+
capability: 'core',
|
|
44
|
+
schema: {
|
|
45
|
+
name: 'browser_click',
|
|
46
|
+
title: 'Click',
|
|
47
|
+
description: 'Perform click on a web page',
|
|
48
|
+
inputSchema: clickSchema,
|
|
49
|
+
type: 'destructive',
|
|
50
|
+
},
|
|
51
|
+
handle: async (tab, params, response) => {
|
|
52
|
+
response.setIncludeSnapshot();
|
|
53
|
+
// Get locator with selector information for database logging
|
|
54
|
+
const { locator, selector, resolvedSelector } = await tab.refLocatorWithSelector(params);
|
|
55
|
+
// Store element interaction data for database logging
|
|
56
|
+
response.setElementInteraction({
|
|
57
|
+
elementRef: params.ref,
|
|
58
|
+
elementDescription: params.element,
|
|
59
|
+
playwrightSelector: selector,
|
|
60
|
+
resolvedSelector: resolvedSelector,
|
|
61
|
+
});
|
|
62
|
+
const button = params.button;
|
|
63
|
+
const buttonAttr = button ? `{ button: '${button}' }` : '';
|
|
64
|
+
if (params.doubleClick)
|
|
65
|
+
response.addCode(`await page.${await generateLocator(locator)}.dblclick(${buttonAttr});`);
|
|
66
|
+
else
|
|
67
|
+
response.addCode(`await page.${await generateLocator(locator)}.click(${buttonAttr});`);
|
|
68
|
+
await tab.waitForCompletion(async () => {
|
|
69
|
+
if (params.doubleClick)
|
|
70
|
+
await locator.dblclick({ button });
|
|
71
|
+
else
|
|
72
|
+
await locator.click({ button });
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const drag = defineTabTool({
|
|
77
|
+
capability: 'core',
|
|
78
|
+
schema: {
|
|
79
|
+
name: 'browser_drag',
|
|
80
|
+
title: 'Drag mouse',
|
|
81
|
+
description: 'Perform drag and drop between two elements',
|
|
82
|
+
inputSchema: z.object({
|
|
83
|
+
startElement: z.string().describe('Human-readable source element description used to obtain the permission to interact with the element'),
|
|
84
|
+
startRef: z.string().describe('Exact source element reference from the page snapshot'),
|
|
85
|
+
endElement: z.string().describe('Human-readable target element description used to obtain the permission to interact with the element'),
|
|
86
|
+
endRef: z.string().describe('Exact target element reference from the page snapshot'),
|
|
87
|
+
}),
|
|
88
|
+
type: 'destructive',
|
|
89
|
+
},
|
|
90
|
+
handle: async (tab, params, response) => {
|
|
91
|
+
response.setIncludeSnapshot();
|
|
92
|
+
// Get locators with selector information for database logging
|
|
93
|
+
const startInfo = await tab.refLocatorWithSelector({ ref: params.startRef, element: params.startElement });
|
|
94
|
+
const endInfo = await tab.refLocatorWithSelector({ ref: params.endRef, element: params.endElement });
|
|
95
|
+
// Store element interaction data for database logging (log start element primarily)
|
|
96
|
+
response.setElementInteraction({
|
|
97
|
+
elementRef: params.startRef,
|
|
98
|
+
elementDescription: `${params.startElement} -> ${params.endElement}`,
|
|
99
|
+
playwrightSelector: startInfo.selector,
|
|
100
|
+
resolvedSelector: startInfo.resolvedSelector,
|
|
101
|
+
});
|
|
102
|
+
await tab.waitForCompletion(async () => {
|
|
103
|
+
await startInfo.locator.dragTo(endInfo.locator);
|
|
104
|
+
});
|
|
105
|
+
response.addCode(`await page.${await generateLocator(startInfo.locator)}.dragTo(page.${await generateLocator(endInfo.locator)});`);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
const hover = defineTabTool({
|
|
109
|
+
capability: 'core',
|
|
110
|
+
schema: {
|
|
111
|
+
name: 'browser_hover',
|
|
112
|
+
title: 'Hover mouse',
|
|
113
|
+
description: 'Hover over element on page',
|
|
114
|
+
inputSchema: elementSchema,
|
|
115
|
+
type: 'readOnly',
|
|
116
|
+
},
|
|
117
|
+
handle: async (tab, params, response) => {
|
|
118
|
+
response.setIncludeSnapshot();
|
|
119
|
+
// Get locator with selector information for database logging
|
|
120
|
+
const { locator, selector, resolvedSelector } = await tab.refLocatorWithSelector(params);
|
|
121
|
+
// Store element interaction data for database logging
|
|
122
|
+
response.setElementInteraction({
|
|
123
|
+
elementRef: params.ref,
|
|
124
|
+
elementDescription: params.element,
|
|
125
|
+
playwrightSelector: selector,
|
|
126
|
+
resolvedSelector: resolvedSelector,
|
|
127
|
+
});
|
|
128
|
+
response.addCode(`await page.${await generateLocator(locator)}.hover();`);
|
|
129
|
+
await tab.waitForCompletion(async () => {
|
|
130
|
+
await locator.hover();
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const selectOptionSchema = elementSchema.extend({
|
|
135
|
+
values: z.array(z.string()).describe('Array of values to select in the dropdown. This can be a single value or multiple values.'),
|
|
136
|
+
});
|
|
137
|
+
const selectOption = defineTabTool({
|
|
138
|
+
capability: 'core',
|
|
139
|
+
schema: {
|
|
140
|
+
name: 'browser_select_option',
|
|
141
|
+
title: 'Select option',
|
|
142
|
+
description: 'Select an option in a dropdown',
|
|
143
|
+
inputSchema: selectOptionSchema,
|
|
144
|
+
type: 'destructive',
|
|
145
|
+
},
|
|
146
|
+
handle: async (tab, params, response) => {
|
|
147
|
+
response.setIncludeSnapshot();
|
|
148
|
+
// Get locator with selector information for database logging
|
|
149
|
+
const { locator, selector, resolvedSelector } = await tab.refLocatorWithSelector(params);
|
|
150
|
+
// Store element interaction data for database logging
|
|
151
|
+
response.setElementInteraction({
|
|
152
|
+
elementRef: params.ref,
|
|
153
|
+
elementDescription: params.element,
|
|
154
|
+
playwrightSelector: selector,
|
|
155
|
+
resolvedSelector: resolvedSelector,
|
|
156
|
+
});
|
|
157
|
+
response.addCode(`await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`);
|
|
158
|
+
await tab.waitForCompletion(async () => {
|
|
159
|
+
await locator.selectOption(params.values);
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
export default [
|
|
164
|
+
snapshot,
|
|
165
|
+
click,
|
|
166
|
+
drag,
|
|
167
|
+
hover,
|
|
168
|
+
selectOption,
|
|
169
|
+
];
|
package/lib/tools/states.js
CHANGED
|
@@ -1 +1,147 @@
|
|
|
1
|
-
function _0x50e8(_0x1bfd1a,_0x1552a8){_0x1bfd1a=_0x1bfd1a-0x1b2;const _0x23c022=_0x2651();let _0x542723=_0x23c022[_0x1bfd1a];if(_0x50e8['JSNofR']===undefined){var _0x486488=function(_0x301241){const _0x159388='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x473848='',_0x526cd1='',_0x1fcb7e=_0x473848+_0x486488;for(let _0x45129e=0x0,_0x346011,_0x2c790,_0x112a99=0x0;_0x2c790=_0x301241['charAt'](_0x112a99++);~_0x2c790&&(_0x346011=_0x45129e%0x4?_0x346011*0x40+_0x2c790:_0x2c790,_0x45129e++%0x4)?_0x473848+=_0x1fcb7e['charCodeAt'](_0x112a99+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x346011>>(-0x2*_0x45129e&0x6)):_0x45129e:0x0){_0x2c790=_0x159388['indexOf'](_0x2c790);}for(let _0x4f5dc4=0x0,_0x31bc41=_0x473848['length'];_0x4f5dc4<_0x31bc41;_0x4f5dc4++){_0x526cd1+='%'+('00'+_0x473848['charCodeAt'](_0x4f5dc4)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x526cd1);};_0x50e8['NNFBIg']=_0x486488,_0x50e8['YbKICN']={},_0x50e8['JSNofR']=!![];}const _0x2651c4=_0x23c022[0x0],_0x50e882=_0x1bfd1a+_0x2651c4,_0x2fc000=_0x50e8['YbKICN'][_0x50e882];if(!_0x2fc000){const _0x5d82f4=function(_0x54b5f5){this['OULsAC']=_0x54b5f5,this['wzvJFT']=[0x1,0x0,0x0],this['pBwVbO']=function(){return'newState';},this['eYygNP']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['vlFFxi']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x5d82f4['prototype']['BWaGnU']=function(){const _0xb19c03=new RegExp(this['eYygNP']+this['vlFFxi']),_0x523f26=_0xb19c03['test'](this['pBwVbO']['toString']())?--this['wzvJFT'][0x1]:--this['wzvJFT'][0x0];return this['wkeaGJ'](_0x523f26);},_0x5d82f4['prototype']['wkeaGJ']=function(_0x7c886){if(!Boolean(~_0x7c886))return _0x7c886;return this['iLPKQM'](this['OULsAC']);},_0x5d82f4['prototype']['iLPKQM']=function(_0x34ee8d){for(let _0x344ea9=0x0,_0x3d7d27=this['wzvJFT']['length'];_0x344ea9<_0x3d7d27;_0x344ea9++){this['wzvJFT']['push'](Math['round'](Math['random']())),_0x3d7d27=this['wzvJFT']['length'];}return _0x34ee8d(this['wzvJFT'][0x0]);},new _0x5d82f4(_0x50e8)['BWaGnU'](),_0x542723=_0x50e8['NNFBIg'](_0x542723),_0x50e8['YbKICN'][_0x50e882]=_0x542723;}else _0x542723=_0x2fc000;return _0x542723;}const _0x48f9b6=_0x50e8;(function(_0x46e4c4,_0x546db8){const _0x59497f=_0x50e8,_0x4e16f9=_0x46e4c4();while(!![]){try{const _0x106cdf=parseInt(_0x59497f(0x1d1))/0x1+parseInt(_0x59497f(0x1ee))/0x2+-parseInt(_0x59497f(0x212))/0x3+parseInt(_0x59497f(0x1cd))/0x4*(-parseInt(_0x59497f(0x1f5))/0x5)+-parseInt(_0x59497f(0x215))/0x6*(-parseInt(_0x59497f(0x1dd))/0x7)+-parseInt(_0x59497f(0x207))/0x8+-parseInt(_0x59497f(0x1cc))/0x9*(-parseInt(_0x59497f(0x1da))/0xa);if(_0x106cdf===_0x546db8)break;else _0x4e16f9['push'](_0x4e16f9['shift']());}catch(_0x269b9a){_0x4e16f9['push'](_0x4e16f9['shift']());}}}(_0x2651,0x5f2e5));const _0x486488=(function(){let _0x2520d0=!![];return function(_0x2ddd90,_0x315c2c){const _0x3057fb=_0x2520d0?function(){const _0x59b3c2=_0x50e8;if(_0x315c2c){const _0x38837a=_0x315c2c[_0x59b3c2(0x1db)](_0x2ddd90,arguments);return _0x315c2c=null,_0x38837a;}}:function(){};return _0x2520d0=![],_0x3057fb;};}()),_0x542723=_0x486488(this,function(){const _0x5b04c7=_0x50e8,_0x6202d6={};_0x6202d6[_0x5b04c7(0x1e3)]=_0x5b04c7(0x1b2);const _0x1e9545=_0x6202d6;return _0x542723[_0x5b04c7(0x1f4)]()[_0x5b04c7(0x1c4)](_0x1e9545[_0x5b04c7(0x1e3)])['toString']()[_0x5b04c7(0x200)](_0x542723)['search'](_0x1e9545[_0x5b04c7(0x1e3)]);});_0x542723();import{z}from'zod';import{defineTabTool}from'./tool.js';import{elementSchema}from'./snapshot.js';function _0x2651(){const _0x27e037=['Dg9tDhjPBMC','nuHJqNrNAq','lNDHAxrgB3iOEYbZDgf0ztOGjW','zw51Bq','C3rYAw5N','ywrKq29Kzq','rMfPBgvKihrVihDHAxqGzM9YigvSzw1LBNqGDg8GyMuG','rMfPBgvKihrVignOzwnRihzPC2LIAwXPDhK6ia','rMfPBgvKihrVignOzwnRigLMigvSzw1LBNqGAxmGzw5HyMXLzdOG','yNjVD3nLCL9PC192AxnPyMXL','BM90ignOzwnRzwq','y291BNq','y29UC3rYDwn0B3i','yNjVD3nLCL9PC19LBMfIBgvK','ih0PoW','ywrKuMvZDwX0','B3b0Aw9UywW','igvSzw1LBNrZig1HDgnOAw5Nici','y29UC3qGAxnfBMfIBgvKid0GyxDHAxqGCgfNzs4','mtaYnJC3nMrbvuPWAq','zgv0ywnOzwq','q291BNqGDgHLig51BwjLCIbVzIbLBgvTzw50CYbTyxrJAgLUzYbHientuYbZzwXLy3rVCG','yNjVD3nLCL93ywL0x2zVCL9LBgvTzw50','zgvZy3jPyMu','y2HLy2TLza','vu96se0','zgvMyxvSDa','B2jQzwn0','uuPYrfC','rK9SrgS','mtaYodG1rfHozMzg','BMfTzq','AxnwAxnPyMXL','mtaXnersDhfXBa','DhLWzq','kcGOlISPkYKRksSK','yMn4tey','yNjVD3nLCL9NzxrFzwXLBwvUDf9JB3vUDa','DKP3DNy','vgLTzw91DcbPBIbTAwXSAxnLy29Uzhm','yNjVD3nLCL9PC19JAgvJA2vK','C3rHDgu','AxndAgvJA2vK','jYWGDgLTzw91DdOG','rMfPBgvKihrVignOzwnRigLMigvSzw1LBNqGAxmGy2HLy2TLzdOG','v2fPDcbMB3iGzwXLBwvUDcbZDgf0zq','DgLTzw91Da','v2fPDcbMB3iGyw4GzwXLBwvUDcb0BYbHChbLyxiSigrPC2fWCgvHCIWGB3iGy2HHBMDLihn0yxrL','q2HLy2SGAwyGyw4GzwXLBwvUDcbPCYbLBMfIBgvKicHUB3qGzgLZywjSzwqP','BM90ihzPC2LIBgu','rwXLBwvUDcbPCYbUB3CG','CMvMtg9JyxrVCG','BNvTyMvY','C2vHCMnO','DMLZAwjSzq','yxr0ywnOzwq','lMLZq2HLy2TLzcGPoW','C2vSzwn0B3i','q2HLy2SGAwyGyw4GzwXLBwvUDcbPCYb2AxnPyMXLig9UihrOzsbWywDL','B0j0Chq','Aw5WDxrty2HLBwe','mJyXodmWn3HJCNLKDa','mJuWmtC2oeHcz0XbrG','DwvTs1G','zxH0zw5K','y29UC3qGAxnwAxnPyMXLid0GyxDHAxqGCgfNzs4','mJuWoty5qNHJtuXU','rwXLBwvUDcbPCYa','wNHnvgu','AxnfBMfIBgvK','sffotNa','zw5HyMXLza','yxDHAxqGCgfNzs4','Bg9JyxrVCG','v2TKz1u','mtbbveTSCwO','yxbWBhK','q2HLy2SGAwyGzwXLBwvUDcbPCYb2AxnPyMXL','mZCZmuTltvr0zW','u3rHDguGDg8GD2fPDcbMB3i','werpvfC','D2fPDezVCG','ywrKrxjYB3i','DgL0Bgu','BerZCxm','y29UC3qGAxndAgvJA2vKid0GyxDHAxqGCgfNzs4','rMfPBgvKihrVignVDw50igvSzw1LBNrZoIa','CgfNzq','q2HLy2SGAwyGysbJAgvJA2jVEcbVCIbYywrPBYbIDxr0B24GAxmGy2HLy2TLzc9ZzwXLy3rLza','jYKUy291BNqOktS','AgLKzgvU','CMvHze9UBhK','C2v0sw5JBhvKzvnUyxbZAg90','y29Yzq','lMLZrw5HyMXLzcGPoW','mta5mtK1mMrWsMLqta','q291BNqGzwXLBwvUDhm','zgLZywjSzwq','zgvZy3jPChrPB24','q1ntihnLBgvJDg9YihrVignVDw50igvSzw1LBNrZ','q2HLy2SGAwyGzwXLBwvUDcbPCYbLBMfIBgvK'];_0x2651=function(){return _0x27e037;};return _0x2651();}import{generateLocator}from'./utils.js';const _0xab2924={};_0xab2924[_0x48f9b6(0x213)]=_0x48f9b6(0x1fd),_0xab2924[_0x48f9b6(0x1e2)]=_0x48f9b6(0x1dc),_0xab2924[_0x48f9b6(0x1f1)]=_0x48f9b6(0x1c9),_0xab2924[_0x48f9b6(0x1cb)]=elementSchema,_0xab2924[_0x48f9b6(0x216)]=_0x48f9b6(0x1ea);const isVisible=defineTabTool({'capability':_0x48f9b6(0x1ec),'schema':_0xab2924,'handle':async(_0xa32850,_0x5c171e,_0x435cdf)=>{const _0x12fa1f=_0x48f9b6,_0x28ec66={};_0x28ec66[_0x12fa1f(0x1d3)]=_0x12fa1f(0x1c5),_0x28ec66[_0x12fa1f(0x1d5)]=_0x12fa1f(0x1c0);const _0x45cc97=_0x28ec66;try{const _0x3342a4=await _0xa32850[_0x12fa1f(0x1c2)](_0x5c171e),_0x4d6392=await _0x3342a4[_0x12fa1f(0x214)]();_0x435cdf[_0x12fa1f(0x1f9)](_0x12fa1f(0x1d0)+await generateLocator(_0x3342a4)+'.isVisible();'),_0x435cdf[_0x12fa1f(0x203)](_0x12fa1f(0x1d2)+(_0x4d6392?_0x45cc97[_0x12fa1f(0x1d3)]:_0x45cc97[_0x12fa1f(0x1d5)]));}catch(_0x2ab5b1){_0x435cdf[_0x12fa1f(0x1e1)](_0x12fa1f(0x1fb)+_0x2ab5b1);}}}),_0x4b415b={};_0x4b415b[_0x48f9b6(0x213)]=_0x48f9b6(0x201),_0x4b415b[_0x48f9b6(0x1e2)]=_0x48f9b6(0x1f3),_0x4b415b[_0x48f9b6(0x1f1)]=_0x48f9b6(0x1bf),_0x4b415b[_0x48f9b6(0x1cb)]=elementSchema,_0x4b415b[_0x48f9b6(0x216)]=_0x48f9b6(0x1ea);const isEnabled=defineTabTool({'capability':_0x48f9b6(0x1ec),'schema':_0x4b415b,'handle':async(_0x174e8e,_0xff1c3a,_0x236fc0)=>{const _0x3277ce=_0x48f9b6,_0x3ea1dc={};_0x3ea1dc[_0x3277ce(0x1ce)]=_0x3277ce(0x1d6),_0x3ea1dc[_0x3277ce(0x1ca)]=_0x3277ce(0x1f0);const _0x1c6241=_0x3ea1dc;try{const _0x3b3cee=await _0x174e8e[_0x3277ce(0x1c2)](_0xff1c3a),_0x4a4669=await _0x3b3cee[_0x3277ce(0x1d4)]();_0x236fc0['addCode'](_0x3277ce(0x206)+await generateLocator(_0x3b3cee)+_0x3277ce(0x1ed)),_0x236fc0[_0x3277ce(0x203)](_0x3277ce(0x1d2)+(_0x4a4669?_0x1c6241[_0x3277ce(0x1ce)]:_0x1c6241[_0x3277ce(0x1ca)]));}catch(_0xab5572){_0x236fc0[_0x3277ce(0x1e1)](_0x3277ce(0x1fc)+_0xab5572);}}}),_0x19d7a1={};_0x19d7a1[_0x48f9b6(0x213)]=_0x48f9b6(0x1b7),_0x19d7a1[_0x48f9b6(0x1e2)]='Check\x20if\x20checkbox/radio\x20is\x20selected',_0x19d7a1[_0x48f9b6(0x1f1)]=_0x48f9b6(0x1e7),_0x19d7a1[_0x48f9b6(0x1cb)]=elementSchema,_0x19d7a1[_0x48f9b6(0x216)]=_0x48f9b6(0x1ea);const isChecked=defineTabTool({'capability':_0x48f9b6(0x1ec),'schema':_0x19d7a1,'handle':async(_0x170246,_0x8249bd,_0x23446c)=>{const _0x133822=_0x48f9b6,_0x23566f={'FOlDk':function(_0x18e933,_0x3f2b9d){return _0x18e933(_0x3f2b9d);},'bcxLF':_0x133822(0x20c),'UOzHM':_0x133822(0x1fe)};try{const _0x1f2f37=await _0x170246[_0x133822(0x1c2)](_0x8249bd),_0x7045ff=await _0x1f2f37[_0x133822(0x1b9)]();_0x23446c[_0x133822(0x1f9)](_0x133822(0x1e4)+await _0x23566f[_0x133822(0x211)](generateLocator,_0x1f2f37)+_0x133822(0x1c7)),_0x23446c[_0x133822(0x203)](_0x133822(0x1d2)+(_0x7045ff?_0x23566f[_0x133822(0x1b3)]:_0x23566f[_0x133822(0x20d)]));}catch(_0x5aaad9){_0x23446c[_0x133822(0x1e1)](_0x133822(0x1bb)+_0x5aaad9);}}}),waitForElement=defineTabTool({'capability':_0x48f9b6(0x1ec),'schema':{'name':_0x48f9b6(0x20a),'title':_0x48f9b6(0x1bc),'description':_0x48f9b6(0x1be),'inputSchema':elementSchema[_0x48f9b6(0x1cf)]({'state':z[_0x48f9b6(0x1f7)]([_0x48f9b6(0x1c5),_0x48f9b6(0x1e9),_0x48f9b6(0x1c6),_0x48f9b6(0x208)])[_0x48f9b6(0x20e)](_0x48f9b6(0x1c5))[_0x48f9b6(0x20b)](_0x48f9b6(0x1de)),'timeout':z[_0x48f9b6(0x1c3)]()[_0x48f9b6(0x204)]()[_0x48f9b6(0x20e)](0x1388)[_0x48f9b6(0x20b)](_0x48f9b6(0x1b6))}),'type':_0x48f9b6(0x1ea)},'handle':async(_0x1db23a,_0x1d3dce,_0xd8655)=>{const _0x45c638=_0x48f9b6,_0x4823c3={'XDOTW':function(_0xeea307,_0x3614d3){return _0xeea307(_0x3614d3);},'WkdgU':function(_0x6c87d8,_0x76572c){return _0x6c87d8===_0x76572c;},'vJwvv':_0x45c638(0x1c5),'QJrDW':_0x45c638(0x1c6)};try{const _0x122f8b=await _0x1db23a['refLocator'](_0x1d3dce),_0x5c07f2={};_0x5c07f2[_0x45c638(0x1b8)]=_0x1d3dce[_0x45c638(0x1b8)],_0x5c07f2[_0x45c638(0x1bd)]=_0x1d3dce[_0x45c638(0x1bd)],await _0x122f8b[_0x45c638(0x1e0)](_0x5c07f2),_0xd8655[_0x45c638(0x1f9)](_0x45c638(0x1d7)+await _0x4823c3[_0x45c638(0x1df)](generateLocator,_0x122f8b)+_0x45c638(0x1f6)+_0x1d3dce[_0x45c638(0x1b8)]+_0x45c638(0x1ba)+_0x1d3dce[_0x45c638(0x1bd)]+_0x45c638(0x202)),_0xd8655[_0x45c638(0x203)](_0x45c638(0x1c1)+_0x1d3dce[_0x45c638(0x1b8)]),(_0x4823c3[_0x45c638(0x1d9)](_0x1d3dce[_0x45c638(0x1b8)],_0x4823c3[_0x45c638(0x1b5)])||_0x4823c3[_0x45c638(0x1d9)](_0x1d3dce[_0x45c638(0x1b8)],_0x4823c3[_0x45c638(0x210)]))&&_0xd8655[_0x45c638(0x1eb)]();}catch(_0x545371){_0xd8655[_0x45c638(0x1e1)](_0x45c638(0x1fa)+_0x1d3dce[_0x45c638(0x1b8)]+':\x20'+_0x545371);}}}),getElementCount=defineTabTool({'capability':_0x48f9b6(0x1ec),'schema':{'name':_0x48f9b6(0x1b4),'title':_0x48f9b6(0x1ef),'description':_0x48f9b6(0x209),'inputSchema':z[_0x48f9b6(0x20f)]({'selector':z[_0x48f9b6(0x1f8)]()[_0x48f9b6(0x20b)](_0x48f9b6(0x1f2))}),'type':_0x48f9b6(0x1ea)},'handle':async(_0x5b2912,_0x2a949d,_0x680a48)=>{const _0x405657=_0x48f9b6;try{const _0x222cbe=_0x5b2912[_0x405657(0x1e6)][_0x405657(0x1d8)](_0x2a949d[_0x405657(0x1c8)]),_0x1ed5a7=await _0x222cbe[_0x405657(0x1ff)]();_0x680a48['addCode']('const\x20count\x20=\x20await\x20page.locator(\x27'+_0x2a949d[_0x405657(0x1c8)]+_0x405657(0x1e8)),_0x680a48[_0x405657(0x203)]('Found\x20'+_0x1ed5a7+_0x405657(0x205)+_0x2a949d[_0x405657(0x1c8)]+'\x22');}catch(_0x3d030b){_0x680a48[_0x405657(0x1e1)](_0x405657(0x1e5)+_0x3d030b);}}});export default[isVisible,isEnabled,isChecked,waitForElement,getElementCount];
|
|
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 { elementSchema } from './snapshot.js';
|
|
19
|
+
import { generateLocator } from './utils.js';
|
|
20
|
+
// Check if element is visible
|
|
21
|
+
const isVisible = defineTabTool({
|
|
22
|
+
capability: 'core',
|
|
23
|
+
schema: {
|
|
24
|
+
name: 'browser_is_visible',
|
|
25
|
+
title: 'Check if element is visible',
|
|
26
|
+
description: 'Check if an element is visible on the page',
|
|
27
|
+
inputSchema: elementSchema,
|
|
28
|
+
type: 'readOnly',
|
|
29
|
+
},
|
|
30
|
+
handle: async (tab, params, response) => {
|
|
31
|
+
try {
|
|
32
|
+
const locator = await tab.refLocator(params);
|
|
33
|
+
const visible = await locator.isVisible();
|
|
34
|
+
response.addCode(`const isVisible = await page.${await generateLocator(locator)}.isVisible();`);
|
|
35
|
+
response.addResult(`Element is ${visible ? 'visible' : 'not visible'}`);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
response.addError(`Failed to check visibility: ${error}`);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
// Check if element is enabled
|
|
43
|
+
const isEnabled = defineTabTool({
|
|
44
|
+
capability: 'core',
|
|
45
|
+
schema: {
|
|
46
|
+
name: 'browser_is_enabled',
|
|
47
|
+
title: 'Check if element is enabled',
|
|
48
|
+
description: 'Check if an element is enabled (not disabled)',
|
|
49
|
+
inputSchema: elementSchema,
|
|
50
|
+
type: 'readOnly',
|
|
51
|
+
},
|
|
52
|
+
handle: async (tab, params, response) => {
|
|
53
|
+
try {
|
|
54
|
+
const locator = await tab.refLocator(params);
|
|
55
|
+
const enabled = await locator.isEnabled();
|
|
56
|
+
response.addCode(`const isEnabled = await page.${await generateLocator(locator)}.isEnabled();`);
|
|
57
|
+
response.addResult(`Element is ${enabled ? 'enabled' : 'disabled'}`);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
response.addError(`Failed to check if element is enabled: ${error}`);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
// Check if checkbox/radio is checked
|
|
65
|
+
const isChecked = defineTabTool({
|
|
66
|
+
capability: 'core',
|
|
67
|
+
schema: {
|
|
68
|
+
name: 'browser_is_checked',
|
|
69
|
+
title: 'Check if checkbox/radio is selected',
|
|
70
|
+
description: 'Check if a checkbox or radio button is checked/selected',
|
|
71
|
+
inputSchema: elementSchema,
|
|
72
|
+
type: 'readOnly',
|
|
73
|
+
},
|
|
74
|
+
handle: async (tab, params, response) => {
|
|
75
|
+
try {
|
|
76
|
+
const locator = await tab.refLocator(params);
|
|
77
|
+
const checked = await locator.isChecked();
|
|
78
|
+
response.addCode(`const isChecked = await page.${await generateLocator(locator)}.isChecked();`);
|
|
79
|
+
response.addResult(`Element is ${checked ? 'checked' : 'not checked'}`);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
response.addError(`Failed to check if element is checked: ${error}`);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
// Wait for element to appear/disappear
|
|
87
|
+
const waitForElement = defineTabTool({
|
|
88
|
+
capability: 'core',
|
|
89
|
+
schema: {
|
|
90
|
+
name: 'browser_wait_for_element',
|
|
91
|
+
title: 'Wait for element state',
|
|
92
|
+
description: 'Wait for an element to appear, disappear, or change state',
|
|
93
|
+
inputSchema: elementSchema.extend({
|
|
94
|
+
state: z.enum(['visible', 'hidden', 'attached', 'detached']).default('visible').describe('State to wait for'),
|
|
95
|
+
timeout: z.number().optional().default(5000).describe('Timeout in milliseconds'),
|
|
96
|
+
}),
|
|
97
|
+
type: 'readOnly',
|
|
98
|
+
},
|
|
99
|
+
handle: async (tab, params, response) => {
|
|
100
|
+
try {
|
|
101
|
+
const locator = await tab.refLocator(params);
|
|
102
|
+
await locator.waitFor({
|
|
103
|
+
state: params.state,
|
|
104
|
+
timeout: params.timeout
|
|
105
|
+
});
|
|
106
|
+
response.addCode(`await page.${await generateLocator(locator)}.waitFor({ state: '${params.state}', timeout: ${params.timeout} });`);
|
|
107
|
+
response.addResult(`Element is now ${params.state}`);
|
|
108
|
+
if (params.state === 'visible' || params.state === 'attached') {
|
|
109
|
+
response.setIncludeSnapshot();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
response.addError(`Failed to wait for element to be ${params.state}: ${error}`);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
// Count matching elements
|
|
118
|
+
const getElementCount = defineTabTool({
|
|
119
|
+
capability: 'core',
|
|
120
|
+
schema: {
|
|
121
|
+
name: 'browser_get_element_count',
|
|
122
|
+
title: 'Count elements',
|
|
123
|
+
description: 'Count the number of elements matching a CSS selector',
|
|
124
|
+
inputSchema: z.object({
|
|
125
|
+
selector: z.string().describe('CSS selector to count elements'),
|
|
126
|
+
}),
|
|
127
|
+
type: 'readOnly',
|
|
128
|
+
},
|
|
129
|
+
handle: async (tab, params, response) => {
|
|
130
|
+
try {
|
|
131
|
+
const locator = tab.page.locator(params.selector);
|
|
132
|
+
const count = await locator.count();
|
|
133
|
+
response.addCode(`const count = await page.locator('${params.selector}').count();`);
|
|
134
|
+
response.addResult(`Found ${count} elements matching "${params.selector}"`);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
response.addError(`Failed to count elements: ${error}`);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
export default [
|
|
142
|
+
isVisible,
|
|
143
|
+
isEnabled,
|
|
144
|
+
isChecked,
|
|
145
|
+
waitForElement,
|
|
146
|
+
getElementCount,
|
|
147
|
+
];
|