@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.
Files changed (61) hide show
  1. package/README.md +2 -0
  2. package/lib/auth.js +82 -1
  3. package/lib/browserContextFactory.js +205 -1
  4. package/lib/browserServerBackend.js +125 -1
  5. package/lib/config.js +266 -1
  6. package/lib/context.js +232 -1
  7. package/lib/databaseLogger.js +264 -1
  8. package/lib/extension/cdpRelay.js +346 -1
  9. package/lib/extension/extensionContextFactory.js +56 -1
  10. package/lib/extension/main.js +26 -1
  11. package/lib/fileUtils.js +32 -1
  12. package/lib/httpServer.js +39 -1
  13. package/lib/index.js +39 -1
  14. package/lib/javascript.js +49 -1
  15. package/lib/log.js +21 -1
  16. package/lib/loop/loop.js +69 -1
  17. package/lib/loop/loopClaude.js +152 -1
  18. package/lib/loop/loopOpenAI.js +143 -1
  19. package/lib/loop/main.js +60 -1
  20. package/lib/loopTools/context.js +66 -1
  21. package/lib/loopTools/main.js +49 -1
  22. package/lib/loopTools/perform.js +32 -1
  23. package/lib/loopTools/snapshot.js +29 -1
  24. package/lib/loopTools/tool.js +18 -1
  25. package/lib/manualPromise.js +111 -1
  26. package/lib/mcp/inProcessTransport.js +72 -1
  27. package/lib/mcp/server.js +93 -1
  28. package/lib/mcp/transport.js +223 -1
  29. package/lib/mongoDBLogger.js +252 -1
  30. package/lib/package.js +20 -1
  31. package/lib/program.js +113 -1
  32. package/lib/response.js +172 -1
  33. package/lib/sessionLog.js +156 -1
  34. package/lib/tab.js +266 -1
  35. package/lib/tools/cdp.js +169 -1
  36. package/lib/tools/common.js +55 -1
  37. package/lib/tools/console.js +33 -1
  38. package/lib/tools/dialogs.js +47 -1
  39. package/lib/tools/evaluate.js +53 -1
  40. package/lib/tools/extraction.js +217 -1
  41. package/lib/tools/files.js +44 -1
  42. package/lib/tools/forms.js +180 -1
  43. package/lib/tools/getext.js +99 -1
  44. package/lib/tools/install.js +53 -1
  45. package/lib/tools/interactions.js +191 -1
  46. package/lib/tools/keyboard.js +86 -1
  47. package/lib/tools/mouse.js +99 -1
  48. package/lib/tools/navigate.js +70 -1
  49. package/lib/tools/network.js +41 -1
  50. package/lib/tools/pdf.js +40 -1
  51. package/lib/tools/screenshot.js +75 -1
  52. package/lib/tools/selectors.js +233 -1
  53. package/lib/tools/snapshot.js +169 -1
  54. package/lib/tools/states.js +147 -1
  55. package/lib/tools/tabs.js +87 -1
  56. package/lib/tools/tool.js +33 -1
  57. package/lib/tools/utils.js +74 -1
  58. package/lib/tools/wait.js +56 -1
  59. package/lib/tools.js +64 -1
  60. package/lib/utils.js +26 -1
  61. package/package.json +2 -2
@@ -1 +1,346 @@
1
- function _0x5fc2(_0xea796d,_0x14e7f6){_0xea796d=_0xea796d-0xd5;const _0xdfbfe3=_0x596d();let _0x10e76a=_0xdfbfe3[_0xea796d];if(_0x5fc2['nVTtDa']===undefined){var _0x39cd3f=function(_0x3c5a63){const _0x39a4e1='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x11510b='',_0x4e6218='',_0x1e36b7=_0x11510b+_0x39cd3f;for(let _0x14e5c8=0x0,_0x5dccdd,_0x104c1b,_0x1bd0e6=0x0;_0x104c1b=_0x3c5a63['charAt'](_0x1bd0e6++);~_0x104c1b&&(_0x5dccdd=_0x14e5c8%0x4?_0x5dccdd*0x40+_0x104c1b:_0x104c1b,_0x14e5c8++%0x4)?_0x11510b+=_0x1e36b7['charCodeAt'](_0x1bd0e6+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x5dccdd>>(-0x2*_0x14e5c8&0x6)):_0x14e5c8:0x0){_0x104c1b=_0x39a4e1['indexOf'](_0x104c1b);}for(let _0xd5ce4f=0x0,_0x51689c=_0x11510b['length'];_0xd5ce4f<_0x51689c;_0xd5ce4f++){_0x4e6218+='%'+('00'+_0x11510b['charCodeAt'](_0xd5ce4f)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x4e6218);};_0x5fc2['CiSiuc']=_0x39cd3f,_0x5fc2['vlXSCL']={},_0x5fc2['nVTtDa']=!![];}const _0x596de7=_0xdfbfe3[0x0],_0x5fc2ee=_0xea796d+_0x596de7,_0x1cb306=_0x5fc2['vlXSCL'][_0x5fc2ee];if(!_0x1cb306){const _0x20e6ab=function(_0x2f546c){this['wLLSAj']=_0x2f546c,this['NHtMGd']=[0x1,0x0,0x0],this['uUUXUs']=function(){return'newState';},this['gcxuQT']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['WctUhI']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x20e6ab['prototype']['zNKToY']=function(){const _0x12a4d9=new RegExp(this['gcxuQT']+this['WctUhI']),_0x4084e5=_0x12a4d9['test'](this['uUUXUs']['toString']())?--this['NHtMGd'][0x1]:--this['NHtMGd'][0x0];return this['aalQHS'](_0x4084e5);},_0x20e6ab['prototype']['aalQHS']=function(_0x2b6fa8){if(!Boolean(~_0x2b6fa8))return _0x2b6fa8;return this['BFLRrp'](this['wLLSAj']);},_0x20e6ab['prototype']['BFLRrp']=function(_0x55f187){for(let _0x547013=0x0,_0x2a719f=this['NHtMGd']['length'];_0x547013<_0x2a719f;_0x547013++){this['NHtMGd']['push'](Math['round'](Math['random']())),_0x2a719f=this['NHtMGd']['length'];}return _0x55f187(this['NHtMGd'][0x0]);},new _0x20e6ab(_0x5fc2)['zNKToY'](),_0x10e76a=_0x5fc2['CiSiuc'](_0x10e76a),_0x5fc2['vlXSCL'][_0x5fc2ee]=_0x10e76a;}else _0x10e76a=_0x1cb306;return _0x10e76a;}const _0x2b5da1=_0x5fc2;(function(_0x3ae9f2,_0x4be5d0){const _0x322427=_0x5fc2,_0x5c2ff2=_0x3ae9f2();while(!![]){try{const _0x3371b3=parseInt(_0x322427(0x155))/0x1*(-parseInt(_0x322427(0x10c))/0x2)+parseInt(_0x322427(0x193))/0x3+-parseInt(_0x322427(0xd5))/0x4+parseInt(_0x322427(0x16d))/0x5*(parseInt(_0x322427(0x16f))/0x6)+parseInt(_0x322427(0xed))/0x7*(parseInt(_0x322427(0x15b))/0x8)+parseInt(_0x322427(0xd8))/0x9+parseInt(_0x322427(0x129))/0xa*(-parseInt(_0x322427(0x153))/0xb);if(_0x3371b3===_0x4be5d0)break;else _0x5c2ff2['push'](_0x5c2ff2['shift']());}catch(_0x54db56){_0x5c2ff2['push'](_0x5c2ff2['shift']());}}}(_0x596d,0x9c0e2));const _0x39cd3f=(function(){let _0x27bb1f=!![];return function(_0x2ca952,_0x3c2250){const _0x4044c0=_0x27bb1f?function(){const _0x248cd4=_0x5fc2;if(_0x3c2250){const _0x3159a7=_0x3c2250[_0x248cd4(0x103)](_0x2ca952,arguments);return _0x3c2250=null,_0x3159a7;}}:function(){};return _0x27bb1f=![],_0x4044c0;};}()),_0x10e76a=_0x39cd3f(this,function(){const _0x4ef561=_0x5fc2,_0x2f6ffe={};_0x2f6ffe[_0x4ef561(0xff)]=_0x4ef561(0x112);const _0x1c1eb2=_0x2f6ffe;return _0x10e76a['toString']()[_0x4ef561(0x177)]('(((.+)+)+)+$')[_0x4ef561(0x12f)]()[_0x4ef561(0x186)](_0x10e76a)[_0x4ef561(0x177)](_0x1c1eb2[_0x4ef561(0xff)]);});_0x10e76a();import{spawn}from'child_process';import _0x4dc223 from'debug';import{WebSocket,WebSocketServer}from'ws';import{httpAddressToString}from'../httpServer.js';import{logUnhandledError}from'../log.js';import{ManualPromise}from'../manualPromise.js';function _0x596d(){const _0x514f5b=['B25JBg9Zzq','BxbIEhu','CMvZCg9UC2uOAwq9','yxr0ywnOvg9uywi','qw5VDgHLCIbLEhrLBNnPB24Gy29UBMvJDgLVBIbHBhjLywr5igvZDgfIBgLZAgvK','t3fSBMS','whrWEfq','swr2Egi','ChjVzhvJDa','sw52ywXPzcbWyxrO','ywjVCNq','DhLWzq','x29UrxjYB3i','y29Kzq','mJm2ndC1nxfSru5stG','ugXHExDYAwDODcbnq1aGy29UBMvJDgvK','mtjmB2vNAvm','CMvQzwn0','Eu5rtfO','Ahr0CdOVl2XVy2fSAg9ZDa','CMvHC29U','x3DZ','x2HHBMrSzvbHCNnLze1LC3nHz2u','ihrHCMDLDd0','C2vHCMnO','AwDUB3jL','Cgf0Ag5HBwu','x2nSB3nLugXHExDYAwDODenVBM5Ly3rPB24','s0HerLC','tMv3ignVBM5Ly3rPB24GDg8G','AgfZ','BhrbzeC','CMvWBgfJzq','CgfYC2u','q0rqlujYAwrNzs1tzxj2zxiVms4WlJa','ChvZAa','x2nSB3nLrxH0zw5ZAw9Uq29UBMvJDgLVBG','DxnLCKfNzw50','x2HHBMrSzvbSyxL3CMLNAhrdB25Uzwn0Aw9U','y29UC3rYDwn0B3i','x3DZCW','x29Uq2XVC2u','x3DZsg9ZDa','EM1gyxm','uhjVDg9JB2WGzxjYB3i6ia','v2vIu29JA2v0ignSB3nLza','EvHnww8','z0LuEM8','z0XtEvG','CMvHzhLtDgf0zq','rgLru1G','y2HYB21Llwv4DgvUC2LVBJOVl2PHA2zHBgjUyMHNA3bTB2fHA2zMBgHMBgjMCgTHAwXMl2nVBM5Ly3qUAhrTBa','mZq5nZa1nuTnA1bLza','x2HHBMrSzuv4DgvUC2LVBKnVBM5Ly3rPB24','BhbMsve','zM9YD2fYzeneuev2zw50','zxHLy3v0ywjSzvbHDgG','wMvAsLq','icHPzd0','ls11C2vYlwrHDgeTzgLYpq','vw5LEhbLy3rLzcbxzwjtB2nRzxqGC3rHDgu6ia','rxH0zw5ZAw9Uig5VDcbJB25Uzwn0zwq','4OAqiev4DgvUC2LVBJOGDw5LEhbLy3rLzcbYzxnWB25Zzq','B2PYEfi','x2HHBMrSzuneuenVBw1HBMq','zxH0zw5ZAw9Urw5KCg9PBNq','EfL3A0i','BMvRt1e','x2v4DgvUC2LVBLbHDgG','rMPwCgS','y2rWrw5KCg9PBNq','ndG0nJK4mfP1zLDPAW','z0X3sgu','y2XVC2vdB25Uzwn0Aw9UCW','nZy2mJG3mffOA3rora','suvMrw0','DgfYz2v0','vgP5y1y','y2XLyxi','x2HHBMrSzvbSyxL3CMLNAhrnzxnZywDL','zw5ZDxjLrxH0zw5ZAw9Uq29UBMvJDgLVBKzVCK1duenVBNrLEhq','v3nwD0m','x2nKCfbHDgG','B25TzxnZywDL','pgnSB3nPBMCGD3m+ienSB3nPBMCGD2vIC29JA2v0igr1zsb0BYbMywLSzwqGB25TzxnZywDLignHBgXIywnRlIbLDMvUDerHDge9','vgfYz2v0lNnLDef1Dg9bDhrHy2G','v2PPs0W','rvfrEgW','qw5VDgHLCIbdrfaGy2XPzw50igfSCMvHzhKGy29UBMvJDgvK','ugXHExDYAwDODcbxzwjtB2nRzxqGy2XVC2vK','u2vYDMvYihn0B3bWzwq','x2v4DgvUC2LVBKnVBM5Ly3rPB24','x2rPC3bVC2u','ChjVDg9JB2XwzxjZAw9U','x2nVBM5Ly3rcCM93C2vY','oteYmZu5Aezyq0D1','t1nOqxu','ChC6BwnWoNjLBgf5','ugXHExDYAwDODcbxzwjtB2nRzxqGzxjYB3i6','y2f0y2G','vKLnzNq','uMvQzwn0Aw5NihnLy29UzcbqBgf5D3jPz2H0ignVBM5Ly3rPB24','vw5ZDxbWB3j0zwqGy2HHBM5LBdOGiG','x25LEhrtzxnZAw9Uswq','x2nHBgXIywnRCW','veHyvNK','C3rVCa','CgfYyw1Z','DNrPv2i','zMLUzev4zwn1DgfIBgu','x2nVBM5Ly3rLzfrHyKLUzM8','C2v0','EKHLtMK','C2ncAhe','nxW0Fdf8m3WWFdi','rxH0zw5ZAw9UignVBM5Ly3rPB24Gzxn0ywjSAxnOzwq','phDZignSB3nLzd4Gy29Kzt0','yxbWBhK','s3DQC3e','rxbSCvC','zM9YD2fYzeneuenVBw1HBMq','ChCTDgfIlq','x3bSyxL3CMLNAhrdB25Uzwn0Aw9U','x2XHC3rjza','l2v4DgvUC2LVBI8','x29UtwvZC2fNzq','mKzltMzPtG','AMPfuxi','vgfYz2v0lMDLDfrHCMDLDeLUzM8','4OAsifbSyxL3CMLNAhq6','zgv0ywnOzwrgCM9TvgfI','CMvZB2X2zq','kcGOlISPkYKRksSK','C3rYAw5NAwz5','igu9','CMLLzwy','y29UBMvJDgLVBG','B0HNqLe','AezNCg8','zuDet1C','Cxv4EuC','Bwv0Ag9K','y2XVC2u','CgXHExDYAwDODc1JB3jLl2XPyI9Zzxj2zxiVCMvNAxn0CNKVAw5KzxG','l2nKCc8','v2fPDgLUzYbMB3iGAw5JB21PBMCGzxH0zw5ZAw9UignVBM5Ly3rPB24','qNjVD3nLCI5NzxrwzxjZAw9U','z2v0','CMfUzg9Tvvvjra','tKDhq1C','zfDdtMK','zgvSzxrL','D1nzve0','rxjYB3iGAw4GDgHLigv4DgvUC2LVBJO','ms4Z','mtK4odK1me1wvKPXsq','x2v4DgvUC2LVBKnVBM5Ly3rPB25qCM9TAxnL','sg9uzLq','DMfSDwvZ','BwvZC2fNzq','zxjYB3i','Dg9tDhjPBMC','C3bSAxq','u2LTDwXHDgLUzYbHDxrVlwf0DgfJAa','DwDzu3a','x3jLC2v0rxH0zw5ZAw9Uq29UBMvJDgLVBG','ywrKrxzLBNrmAxn0zw5LCG','tMrSwKS','txrly0K','x2HHBMrSzuv4DgvUC2LVBK1LC3nHz2u','ihjLyxnVBJ0','rw5ZDxjPBMCGzxH0zw5ZAw9UignVBM5Ly3rPB24GzM9Yie1ducbJB250zxH0','DxjS','x29Uq29UBMvJDgLVBG','4OAqifbSyxL3CMLNAhq6','vMnmteO','vgfYz2v0lMf0DgfJAgvKvg9uyxjNzxq','C2vUza','u1nwuKC','whvmrMK','rxH0zw5ZAw9UigrPC2nVBM5Ly3rLzdOG','C2vZC2LVBKLK','pgnSB3nPBMCGD3m+ienSB3nPBMCGD2vIC29JA2v0igr1zsb0BYbTywXMB3jTzwqGsLnptI4GzxzLBNreyxrHpq','iIbLEgvJDxrHyMXLig5VDcbMB3vUzc4GtwfRzsbZDxjLigL0igLZigLUC3rHBgXLzcbHDcbHihn0yw5KyxjKigXVy2f0Aw9UlG','ywrKCMvZCW','tMrrB3y','x2zVCNDHCMruB0v4DgvUC2LVBG','ue9jEg0','rxH0zw5ZAw9UifDLyLnVy2TLDcbJBg9Zzwq6','x3nLBMruB1bSyxL3CMLNAhq','C2vHCMnOugfYyw1Z','rxjYB3iGD2HPBguGAgfUzgXPBMCGugXHExDYAwDODcbTzxnZywDLcG','q2HYB21Ll0v4DgvUC2LVBI1cCMLKz2u','phDZigvYCM9YpIbTzxnZywDLpq','CMfJzq','DgfYz2v0sw5MBW','DwTMChy','mZnLBMHkEeu','x3vZzxjeyxrHrgLY','nZC2mdu5suLqs0jm','x2jYB3DZzxjdAgfUBMvS','yMLUza','y2XPzw50','ugXHExDYAwDODcbJBgLLBNqGzgLZy29UBMvJDgvK','AeHnuum','mtzTDwriswq','yNfvzuy','DLzsugy','BwnWuMvSyxLvCMW'];_0x596d=function(){return _0x514f5b;};return _0x596d();}const {registry}=await import(_0x2b5da1(0x11d)),debugLogger=_0x4dc223(_0x2b5da1(0xef));export class CDPRelayServer{[_0x2b5da1(0x189)];[_0x2b5da1(0x156)];[_0x2b5da1(0x154)];[_0x2b5da1(0xe0)];[_0x2b5da1(0x1a3)];[_0x2b5da1(0x187)];[_0x2b5da1(0x108)]=null;[_0x2b5da1(0xe9)]=null;[_0x2b5da1(0xfc)];[_0x2b5da1(0xf5)]=0x1;[_0x2b5da1(0x12a)];constructor(_0x2baa85,_0x542908,_0x186b34){const _0x19853f=_0x2b5da1,_0x445f57={};_0x445f57[_0x19853f(0x136)]=_0x19853f(0x116);const _0xe033c8=_0x445f57;this['_wsHost']=httpAddressToString(_0x2baa85[_0x19853f(0x146)]())[_0x19853f(0x17f)](/^http/,'ws'),this[_0x19853f(0x156)]=_0x542908,this[_0x19853f(0x154)]=_0x186b34;const _0x19a11e=crypto[_0x19853f(0x122)]();this[_0x19853f(0xe0)]=_0x19853f(0x11e)+_0x19a11e,this[_0x19853f(0x1a3)]=_0x19853f(0x10a)+_0x19a11e,this['_resetExtensionConnection']();const _0x540a6e={};_0x540a6e['server']=_0x2baa85,this['_wss']=new WebSocketServer(_0x540a6e),this[_0x19853f(0x187)]['on'](_0xe033c8[_0x19853f(0x136)],this[_0x19853f(0x13b)]['bind'](this));}[_0x2b5da1(0x1a5)](){const _0x10e555=_0x2b5da1;return''+this[_0x10e555(0x189)]+this[_0x10e555(0xe0)];}[_0x2b5da1(0x1a0)](){const _0x374e23=_0x2b5da1;return''+this['_wsHost']+this[_0x374e23(0x1a3)];}async[_0x2b5da1(0xde)](_0x179fb7,_0x511a00){const _0xd2b8c8=_0x2b5da1,_0x4edf06={'xYwkB':_0xd2b8c8(0x100),'ugYSp':function(_0x375618,_0x12f0b7){return _0x375618(_0x12f0b7);},'FAakm':_0xd2b8c8(0x11f),'Kwjsq':function(_0x40f5f0,_0x5b6df5){return _0x40f5f0(_0x5b6df5);},'NGGCW':_0xd2b8c8(0x139)},_0x4b2d6d=_0x4edf06[_0xd2b8c8(0x1a1)][_0xd2b8c8(0x130)]('|');let _0x1cabf6=0x0;while(!![]){switch(_0x4b2d6d[_0x1cabf6++]){case'0':await Promise[_0xd2b8c8(0x150)]([this[_0xd2b8c8(0x12a)],new Promise((_0x54caa0,_0x36f9ef)=>_0x511a00[_0xd2b8c8(0x134)](_0xd2b8c8(0x169),_0x36f9ef))]);continue;case'1':this[_0xd2b8c8(0xec)](_0x179fb7);continue;case'2':_0x4edf06[_0xd2b8c8(0x132)](debugLogger,_0xd2b8c8(0x101));continue;case'3':debugLogger(_0x4edf06['FAakm']);continue;case'4':if(this[_0xd2b8c8(0xe9)])return;continue;case'5':_0x4edf06[_0xd2b8c8(0x104)](debugLogger,_0x4edf06[_0xd2b8c8(0x123)]);continue;}break;}}[_0x2b5da1(0xec)](_0x34e9f0){const _0x1646b3=_0x2b5da1,_0x2dd5a2={'ZHNPs':_0x1646b3(0x192),'zmFas':_0x1646b3(0x15e),'bqUeF':function(_0x467925,_0x2aead8,_0x3846bf,_0x33cf99){return _0x467925(_0x2aead8,_0x3846bf,_0x33cf99);},'FjVpk':_0x1646b3(0x178)},_0x393845=''+this[_0x1646b3(0x189)]+this[_0x1646b3(0x1a3)],_0x108f90=new URL(_0x2dd5a2['ZHNPs']);_0x108f90[_0x1646b3(0x14c)][_0x1646b3(0xfd)](_0x2dd5a2[_0x1646b3(0x18a)],_0x393845),_0x108f90[_0x1646b3(0x14c)][_0x1646b3(0xfd)](_0x1646b3(0x158),JSON['stringify'](_0x34e9f0));const _0x3c1111=_0x108f90[_0x1646b3(0x12f)](),_0x20da82=registry[_0x1646b3(0xfb)](this[_0x1646b3(0x156)]);if(!_0x20da82)throw new Error(_0x1646b3(0xf4)+this[_0x1646b3(0x156)]+'\x22');const _0x3e91c9=_0x20da82[_0x1646b3(0x197)]();if(!_0x3e91c9)throw new Error('\x22'+this[_0x1646b3(0x156)]+_0x1646b3(0x145));const _0x15392e=[];if(this[_0x1646b3(0x154)])_0x15392e[_0x1646b3(0x182)](_0x1646b3(0x19a)+this[_0x1646b3(0x154)]);_0x15392e[_0x1646b3(0x182)](_0x3c1111),_0x2dd5a2[_0x1646b3(0x15c)](spawn,_0x3e91c9,_0x15392e,{'windowsHide':!![],'detached':!![],'shell':![],'stdio':_0x2dd5a2[_0x1646b3(0x1a4)]});}[_0x2b5da1(0xf8)](){const _0x26a490=_0x2b5da1,_0x161af0={};_0x161af0[_0x26a490(0x117)]=_0x26a490(0xe8);const _0x1362d7=_0x161af0;this[_0x26a490(0xd7)](_0x1362d7[_0x26a490(0x117)]),this[_0x26a490(0x187)]['close']();}[_0x2b5da1(0xd7)](_0xf5cabd){const _0x3ea5e6=_0x2b5da1;this[_0x3ea5e6(0x17a)](_0xf5cabd),this[_0x3ea5e6(0x183)](_0xf5cabd);}[_0x2b5da1(0x13b)](_0x22c7c2,_0xe07849){const _0x3aff01=_0x2b5da1,_0x990628={'gLwHe':function(_0x1cc818,_0x47d8a8){return _0x1cc818(_0x47d8a8);},'NdlZK':function(_0x2e3b8f,_0x40a1ee){return _0x2e3b8f===_0x40a1ee;},'nekOQ':function(_0x159897,_0x572b3c){return _0x159897(_0x572b3c);},'Oqlnk':_0x3aff01(0x168)},_0x5655f3=new URL(_0x3aff01(0x172)+_0xe07849[_0x3aff01(0x13a)]);_0x990628[_0x3aff01(0xd6)](debugLogger,_0x3aff01(0x17c)+_0x5655f3['pathname']);if(_0x990628[_0x3aff01(0x135)](_0x5655f3[_0x3aff01(0x179)],this[_0x3aff01(0xe0)]))this[_0x3aff01(0x185)](_0x22c7c2);else _0x990628[_0x3aff01(0x135)](_0x5655f3[_0x3aff01(0x179)],this[_0x3aff01(0x1a3)])?this[_0x3aff01(0x194)](_0x22c7c2):(_0x990628[_0x3aff01(0x1a2)](debugLogger,'Invalid\x20path:\x20'+_0x5655f3[_0x3aff01(0x179)]),_0x22c7c2[_0x3aff01(0x11c)](0xfa4,_0x990628[_0x3aff01(0x164)]));}[_0x2b5da1(0x185)](_0x579db3){const _0x24c01f=_0x2b5da1,_0x3a7480={'ojrxR':function(_0x51041b,_0x1d9ff3){return _0x51041b(_0x1d9ff3);},'quxyG':_0x24c01f(0xe7),'hFgpo':_0x24c01f(0xf0),'TjycV':_0x24c01f(0xf3),'POIxm':_0x24c01f(0xe6),'wSYTM':_0x24c01f(0x12d),'XtpxT':_0x24c01f(0x11c),'KHDFW':_0x24c01f(0x12e),'WsVwC':_0x24c01f(0x16e)};if(this['_playwrightConnection']){_0x3a7480[_0x24c01f(0x19e)](debugLogger,_0x3a7480[_0x24c01f(0xdb)]),_0x579db3[_0x24c01f(0x11c)](0x3e8,_0x3a7480[_0x24c01f(0x149)]);return;}this[_0x24c01f(0x108)]=_0x579db3,_0x579db3['on'](_0x3a7480[_0x24c01f(0x126)],async _0x536553=>{const _0x17c820=_0x24c01f;try{const _0x39908e=JSON[_0x17c820(0x180)](_0x536553[_0x17c820(0x12f)]());await this[_0x17c820(0xdd)](_0x39908e);}catch(_0x453b4c){debugLogger(_0x17c820(0x14d)+_0x536553[_0x17c820(0x12f)]()+'\x0a',_0x453b4c);}}),_0x579db3['on'](_0x3a7480[_0x24c01f(0x165)],()=>{const _0x213ce6=_0x24c01f;if(this[_0x213ce6(0x108)]!==_0x579db3)return;this[_0x213ce6(0x108)]=null,this[_0x213ce6(0x183)](_0x213ce6(0x159)),_0x3a7480[_0x213ce6(0x19e)](debugLogger,_0x3a7480[_0x213ce6(0x11a)]);}),_0x579db3['on'](_0x3a7480[_0x24c01f(0x17b)],_0xa42af2=>{const _0x3c3ebe=_0x24c01f;debugLogger(_0x3a7480[_0x3c3ebe(0x118)],_0xa42af2);}),_0x3a7480['ojrxR'](debugLogger,_0x3a7480[_0x24c01f(0xdf)]);}[_0x2b5da1(0x183)](_0x329e20){const _0x19b2cf=_0x2b5da1;this[_0x19b2cf(0xe9)]?.[_0x19b2cf(0x11c)](_0x329e20),this[_0x19b2cf(0x12a)][_0x19b2cf(0x170)](new Error(_0x329e20)),this[_0x19b2cf(0x133)]();}[_0x2b5da1(0x133)](){const _0xea4124=_0x2b5da1;this[_0xea4124(0xfc)]=undefined,this[_0xea4124(0xe9)]=null,this[_0xea4124(0x12a)]=new ManualPromise(),void this[_0xea4124(0x12a)][_0xea4124(0xf1)](logUnhandledError);}[_0x2b5da1(0x17a)](_0x5408bf){const _0x13f5ae=_0x2b5da1;if(this['_playwrightConnection']?.['readyState']===WebSocket['OPEN'])this[_0x13f5ae(0x108)]['close'](0x3e8,_0x5408bf);this[_0x13f5ae(0x108)]=null;}[_0x2b5da1(0x194)](_0x13fb09){const _0xddc927=_0x2b5da1,_0x2d5f1d={'EplqW':function(_0x38cdf9,_0x19096a,_0x3cda6a,_0x2fbff1){return _0x38cdf9(_0x19096a,_0x3cda6a,_0x2fbff1);},'THXVy':_0xddc927(0x14a),'YJfNx':function(_0x5d443a,_0x282205){return _0x5d443a===_0x282205;},'eGDOW':function(_0x2e1581,_0x56f470){return _0x2e1581!==_0x56f470;},'zHeNi':_0xddc927(0x163)};if(this[_0xddc927(0xe9)]){_0x13fb09[_0xddc927(0x11c)](0x3e8,_0x2d5f1d[_0xddc927(0xfe)]);return;}this[_0xddc927(0xe9)]=new ExtensionConnection(_0x13fb09),this[_0xddc927(0xe9)][_0xddc927(0x15f)]=(_0x2f8a4f,_0x187e6f)=>{const _0x8d5667=_0xddc927;_0x2d5f1d[_0x8d5667(0x105)](debugLogger,_0x2d5f1d[_0x8d5667(0xf7)],_0x187e6f,_0x2d5f1d['YJfNx'](_0x2f8a4f,this[_0x8d5667(0xe9)]));if(_0x2d5f1d[_0x8d5667(0x119)](this[_0x8d5667(0xe9)],_0x2f8a4f))return;this[_0x8d5667(0x133)](),this[_0x8d5667(0x17a)](_0x8d5667(0x142)+_0x187e6f);},this[_0xddc927(0xe9)][_0xddc927(0xe1)]=this[_0xddc927(0x137)][_0xddc927(0x157)](this),this[_0xddc927(0x12a)][_0xddc927(0x111)]();}['_handleExtensionMessage'](_0x1c99e3,_0x48865e){const _0x2d6412=_0x2b5da1,_0x271229={'yXMYo':_0x2d6412(0x196),'lFpJw':_0x2d6412(0x110),'dWCNi':function(_0x57d45c,_0x1e25b9,_0x172204){return _0x57d45c(_0x1e25b9,_0x172204);},'IEfEm':'←\x20Debugger\x20detached\x20from\x20tab:'};switch(_0x1c99e3){case _0x271229[_0x2d6412(0x18d)]:const _0xdf1723=_0x48865e[_0x2d6412(0x143)]||this[_0x2d6412(0xfc)]?.[_0x2d6412(0x143)],_0x5018cc={};_0x5018cc[_0x2d6412(0x143)]=_0xdf1723,_0x5018cc[_0x2d6412(0x11b)]=_0x48865e[_0x2d6412(0x11b)],_0x5018cc[_0x2d6412(0xf9)]=_0x48865e[_0x2d6412(0xf9)],this[_0x2d6412(0x14b)](_0x5018cc);break;case _0x271229['lFpJw']:_0x271229[_0x2d6412(0x124)](debugLogger,_0x271229[_0x2d6412(0xd9)],_0x48865e),this[_0x2d6412(0xfc)]=undefined;break;}}async[_0x2b5da1(0xdd)](_0x461111){const _0x495e23=_0x2b5da1,_0x54ef1b={'NdQov':function(_0x12d4f5,_0x30b1bb,_0xc5fb98){return _0x12d4f5(_0x30b1bb,_0xc5fb98);},'Idvxb':_0x495e23(0x127)};_0x54ef1b[_0x495e23(0x147)](debugLogger,_0x495e23(0x13c),_0x461111[_0x495e23(0x11b)]+_0x495e23(0x199)+_0x461111['id']+')');const {id:_0x326338,sessionId:_0x3674f1,method:_0x30b306,params:_0x4a8005}=_0x461111;try{const _0x3af007=await this[_0x495e23(0x19f)](_0x30b306,_0x4a8005,_0x3674f1),_0x5c9a5b={};_0x5c9a5b['id']=_0x326338,_0x5c9a5b[_0x495e23(0x143)]=_0x3674f1,_0x5c9a5b['result']=_0x3af007,this[_0x495e23(0x14b)](_0x5c9a5b);}catch(_0x37781d){_0x54ef1b[_0x495e23(0x147)](debugLogger,_0x54ef1b[_0x495e23(0x166)],_0x37781d);const _0x1773ce={};_0x1773ce['message']=_0x37781d['message'];const _0x3d8857={};_0x3d8857['id']=_0x326338,_0x3d8857[_0x495e23(0x143)]=_0x3674f1,_0x3d8857[_0x495e23(0x12e)]=_0x1773ce,this[_0x495e23(0x14b)](_0x3d8857);}}async[_0x2b5da1(0x19f)](_0x42a08d,_0x53885b,_0x5caeea){const _0x1fef4d=_0x2b5da1,_0x207f9e={};_0x207f9e[_0x1fef4d(0x195)]=_0x1fef4d(0x120),_0x207f9e[_0x1fef4d(0x18f)]=_0x1fef4d(0x128),_0x207f9e[_0x1fef4d(0x18e)]=_0x1fef4d(0x14e),_0x207f9e[_0x1fef4d(0x141)]=_0x1fef4d(0x181),_0x207f9e[_0x1fef4d(0x198)]=_0x1fef4d(0x162),_0x207f9e['WjiKL']=_0x1fef4d(0x131);const _0x21dced=_0x207f9e;switch(_0x42a08d){case _0x21dced[_0x1fef4d(0x195)]:{const _0x9cde95={};return _0x9cde95[_0x1fef4d(0xeb)]=_0x21dced[_0x1fef4d(0x18f)],_0x9cde95[_0x1fef4d(0x167)]=_0x21dced[_0x1fef4d(0x18e)],_0x9cde95[_0x1fef4d(0x184)]=_0x21dced[_0x1fef4d(0x141)],_0x9cde95;}case'Browser.setDownloadBehavior':{return{};}case _0x1fef4d(0xe3):{if(_0x5caeea)break;const {targetInfo:_0x1e7537}=await this[_0x1fef4d(0xe9)][_0x1fef4d(0x13f)](_0x21dced[_0x1fef4d(0x198)]);return this[_0x1fef4d(0xfc)]={'targetInfo':_0x1e7537,'sessionId':_0x1fef4d(0x107)+this[_0x1fef4d(0xf5)]++},debugLogger(_0x21dced[_0x1fef4d(0xe4)]),this[_0x1fef4d(0x14b)]({'method':_0x1fef4d(0x13e),'params':{'sessionId':this[_0x1fef4d(0xfc)][_0x1fef4d(0x143)],'targetInfo':{...this[_0x1fef4d(0xfc)][_0x1fef4d(0x151)],'attached':!![]},'waitingForDebugger':![]}}),{};}case _0x1fef4d(0x10e):{return this[_0x1fef4d(0xfc)]?.[_0x1fef4d(0x151)];}}return await this[_0x1fef4d(0x148)](_0x42a08d,_0x53885b,_0x5caeea);}async[_0x2b5da1(0x148)](_0x1159c3,_0x5ef6db,_0x4dc17a){const _0x1ec8fc=_0x2b5da1,_0x44393b={};_0x44393b[_0x1ec8fc(0x15d)]=_0x1ec8fc(0x19c),_0x44393b[_0x1ec8fc(0x15a)]=function(_0x450acf,_0x4df1bf){return _0x450acf===_0x4df1bf;},_0x44393b[_0x1ec8fc(0x17e)]=_0x1ec8fc(0x106);const _0x4e7ec1=_0x44393b;if(!this[_0x1ec8fc(0xe9)])throw new Error(_0x4e7ec1[_0x1ec8fc(0x15d)]);if(_0x4e7ec1[_0x1ec8fc(0x15a)](this[_0x1ec8fc(0xfc)]?.[_0x1ec8fc(0x143)],_0x4dc17a))_0x4dc17a=undefined;const _0x5f26ca={};return _0x5f26ca[_0x1ec8fc(0x143)]=_0x4dc17a,_0x5f26ca[_0x1ec8fc(0x11b)]=_0x1159c3,_0x5f26ca[_0x1ec8fc(0xf9)]=_0x5ef6db,await this['_extensionConnection'][_0x1ec8fc(0x13f)](_0x4e7ec1[_0x1ec8fc(0x17e)],_0x5f26ca);}[_0x2b5da1(0x14b)](_0x55c483){const _0x3f8f17=_0x2b5da1,_0x559540={'HoTfT':function(_0x50c2dd,_0x43cad1,_0x58f306){return _0x50c2dd(_0x43cad1,_0x58f306);},'rieef':_0x3f8f17(0x10f)};_0x559540[_0x3f8f17(0x12b)](debugLogger,_0x559540[_0x3f8f17(0x115)],''+(_0x55c483[_0x3f8f17(0x11b)]??_0x3f8f17(0x161)+_0x55c483['id']+')')),this[_0x3f8f17(0x108)]?.[_0x3f8f17(0x13f)](JSON[_0x3f8f17(0x113)](_0x55c483));}}class ExtensionConnection{[_0x2b5da1(0x174)];['_callbacks']=new Map();[_0x2b5da1(0x109)]=0x0;[_0x2b5da1(0xe1)];[_0x2b5da1(0x15f)];constructor(_0x46b1e4){const _0x454f49=_0x2b5da1,_0x60ff31={};_0x60ff31[_0x454f49(0xfa)]=_0x454f49(0x12d),_0x60ff31[_0x454f49(0x152)]=_0x454f49(0x11c),_0x60ff31[_0x454f49(0xf2)]=_0x454f49(0x12e);const _0x54d429=_0x60ff31;this[_0x454f49(0x174)]=_0x46b1e4,this[_0x454f49(0x174)]['on'](_0x54d429[_0x454f49(0xfa)],this[_0x454f49(0x10b)][_0x454f49(0x157)](this)),this[_0x454f49(0x174)]['on'](_0x54d429[_0x454f49(0x152)],this[_0x454f49(0x188)][_0x454f49(0x157)](this)),this[_0x454f49(0x174)]['on'](_0x54d429[_0x454f49(0xf2)],this[_0x454f49(0x16b)][_0x454f49(0x157)](this));}async[_0x2b5da1(0x13f)](_0x5c8ac7,_0x5529f2,_0x380795){const _0x3895dc=_0x2b5da1,_0x50e58a={};_0x50e58a[_0x3895dc(0xee)]=function(_0x29934e,_0x26dc5e){return _0x29934e!==_0x26dc5e;};const _0x397599=_0x50e58a;if(_0x397599[_0x3895dc(0xee)](this[_0x3895dc(0x174)][_0x3895dc(0x190)],WebSocket['OPEN']))throw new Error(_0x3895dc(0x19b)+this[_0x3895dc(0x174)][_0x3895dc(0x190)]);const _0x1bafb1=++this[_0x3895dc(0x109)],_0x8f39b0={};_0x8f39b0['id']=_0x1bafb1,_0x8f39b0[_0x3895dc(0x11b)]=_0x5c8ac7,_0x8f39b0[_0x3895dc(0xf9)]=_0x5529f2,_0x8f39b0[_0x3895dc(0x143)]=_0x380795,this['_ws'][_0x3895dc(0x13f)](JSON[_0x3895dc(0x113)](_0x8f39b0));const _0x4122e5=new Error(_0x3895dc(0x18b)+_0x5c8ac7);return new Promise((_0x2b49a0,_0xad6c22)=>{const _0x441968=_0x3895dc,_0x51b58e={};_0x51b58e[_0x441968(0x111)]=_0x2b49a0,_0x51b58e[_0x441968(0x170)]=_0xad6c22,_0x51b58e[_0x441968(0x12e)]=_0x4122e5,this[_0x441968(0xf6)][_0x441968(0xfd)](_0x1bafb1,_0x51b58e);});}[_0x2b5da1(0x11c)](_0x4584ac){const _0xbe7420=_0x2b5da1,_0x5db975={};_0x5db975[_0xbe7420(0x171)]='closing\x20extension\x20connection:',_0x5db975[_0xbe7420(0xe5)]=function(_0x1c8ea5,_0x6c08e3){return _0x1c8ea5===_0x6c08e3;};const _0x3c6b90=_0x5db975;debugLogger(_0x3c6b90[_0xbe7420(0x171)],_0x4584ac);if(_0x3c6b90[_0xbe7420(0xe5)](this[_0xbe7420(0x174)][_0xbe7420(0x190)],WebSocket['OPEN']))this[_0xbe7420(0x174)][_0xbe7420(0x11c)](0x3e8,_0x4584ac);}[_0x2b5da1(0x10b)](_0x1d3377){const _0x421e26=_0x2b5da1,_0x39a8bb={'SSVRG':function(_0x239328,_0x31a121){return _0x239328(_0x31a121);}},_0x58bd6e=_0x1d3377[_0x421e26(0x12f)]();let _0x150da3;try{_0x150da3=JSON[_0x421e26(0x180)](_0x58bd6e);}catch(_0x179069){_0x39a8bb[_0x421e26(0x140)](debugLogger,_0x421e26(0x144)+_0x58bd6e+_0x421e26(0x114)+_0x179069?.[_0x421e26(0x12d)]),this['_ws']['close']();return;}try{this['_handleParsedMessage'](_0x150da3);}catch(_0x42c87d){_0x39a8bb[_0x421e26(0x140)](debugLogger,_0x421e26(0xe2)+_0x58bd6e+_0x421e26(0x114)+_0x42c87d?.[_0x421e26(0x12d)]),this[_0x421e26(0x174)][_0x421e26(0x11c)]();}}[_0x2b5da1(0x175)](_0x4e6204){const _0x29bbf7=_0x2b5da1,_0x4f0892={'nlnDW':function(_0x55eea8,_0x5e8066,_0x1f5246){return _0x55eea8(_0x5e8066,_0x1f5246);},'VcLLJ':_0x29bbf7(0x19d)};if(_0x4e6204['id']&&this[_0x29bbf7(0xf6)][_0x29bbf7(0x17d)](_0x4e6204['id'])){const _0x5dc590=this[_0x29bbf7(0xf6)][_0x29bbf7(0x121)](_0x4e6204['id']);this[_0x29bbf7(0xf6)][_0x29bbf7(0x125)](_0x4e6204['id']);if(_0x4e6204[_0x29bbf7(0x12e)]){const _0x5538da=_0x5dc590[_0x29bbf7(0x12e)];_0x5538da[_0x29bbf7(0x12d)]=_0x4e6204[_0x29bbf7(0x12e)],_0x5dc590[_0x29bbf7(0x170)](_0x5538da);}else _0x5dc590[_0x29bbf7(0x111)](_0x4e6204['result']);}else _0x4e6204['id']?_0x4f0892['nlnDW'](debugLogger,_0x4f0892[_0x29bbf7(0x13d)],_0x4e6204):this[_0x29bbf7(0xe1)]?.(_0x4e6204[_0x29bbf7(0x11b)],_0x4e6204[_0x29bbf7(0xf9)]);}[_0x2b5da1(0x188)](_0x5cfce7){const _0x4cd5c9=_0x2b5da1,_0x15cb8a={'DiQSX':function(_0xf241d9,_0x4e7e73){return _0xf241d9(_0x4e7e73);}};_0x15cb8a[_0x4cd5c9(0x191)](debugLogger,_0x4cd5c9(0x102)+_0x5cfce7[_0x4cd5c9(0x16c)]+_0x4cd5c9(0x138)+_0x5cfce7[_0x4cd5c9(0x173)]),this[_0x4cd5c9(0xea)](),this[_0x4cd5c9(0x15f)]?.(this,_0x5cfce7[_0x4cd5c9(0x173)]);}[_0x2b5da1(0x16b)](_0x217db5){const _0x450f49=_0x2b5da1,_0x51605d={'mpbxu':function(_0x15591e,_0x565046){return _0x15591e(_0x565046);}};_0x51605d[_0x450f49(0x160)](debugLogger,_0x450f49(0x14f)+_0x217db5[_0x450f49(0x12d)]+'\x20type='+_0x217db5[_0x450f49(0x16a)]+_0x450f49(0x176)+_0x217db5[_0x450f49(0xda)]),this[_0x450f49(0xea)]();}[_0x2b5da1(0xea)](){const _0x2f8f94=_0x2b5da1,_0x2379db={};_0x2379db[_0x2f8f94(0x10d)]=_0x2f8f94(0x18c);const _0x190fa4=_0x2379db;for(const _0xee19b0 of this[_0x2f8f94(0xf6)][_0x2f8f94(0x12c)]())_0xee19b0[_0x2f8f94(0x170)](new Error(_0x190fa4[_0x2f8f94(0x10d)]));this[_0x2f8f94(0xf6)][_0x2f8f94(0xdc)]();}}
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
+ /**
17
+ * WebSocket server that bridges Playwright MCP and Chrome Extension
18
+ *
19
+ * Endpoints:
20
+ * - /cdp/guid - Full CDP interface for Playwright MCP
21
+ * - /extension/guid - Extension connection for chrome.debugger forwarding
22
+ */
23
+ import { spawn } from 'child_process';
24
+ import debug from 'debug';
25
+ import { WebSocket, WebSocketServer } from 'ws';
26
+ import { httpAddressToString } from '../httpServer.js';
27
+ import { logUnhandledError } from '../log.js';
28
+ import { ManualPromise } from '../manualPromise.js';
29
+ // @ts-ignore
30
+ const { registry } = await import('playwright-core/lib/server/registry/index');
31
+ const debugLogger = debug('pw:mcp:relay');
32
+ export class CDPRelayServer {
33
+ _wsHost;
34
+ _browserChannel;
35
+ _userDataDir;
36
+ _cdpPath;
37
+ _extensionPath;
38
+ _wss;
39
+ _playwrightConnection = null;
40
+ _extensionConnection = null;
41
+ _connectedTabInfo;
42
+ _nextSessionId = 1;
43
+ _extensionConnectionPromise;
44
+ constructor(server, browserChannel, userDataDir) {
45
+ this._wsHost = httpAddressToString(server.address()).replace(/^http/, 'ws');
46
+ this._browserChannel = browserChannel;
47
+ this._userDataDir = userDataDir;
48
+ const uuid = crypto.randomUUID();
49
+ this._cdpPath = `/cdp/${uuid}`;
50
+ this._extensionPath = `/extension/${uuid}`;
51
+ this._resetExtensionConnection();
52
+ this._wss = new WebSocketServer({ server });
53
+ this._wss.on('connection', this._onConnection.bind(this));
54
+ }
55
+ cdpEndpoint() {
56
+ return `${this._wsHost}${this._cdpPath}`;
57
+ }
58
+ extensionEndpoint() {
59
+ return `${this._wsHost}${this._extensionPath}`;
60
+ }
61
+ async ensureExtensionConnectionForMCPContext(clientInfo, abortSignal) {
62
+ debugLogger('Ensuring extension connection for MCP context');
63
+ if (this._extensionConnection)
64
+ return;
65
+ this._connectBrowser(clientInfo);
66
+ debugLogger('Waiting for incoming extension connection');
67
+ await Promise.race([
68
+ this._extensionConnectionPromise,
69
+ new Promise((_, reject) => abortSignal.addEventListener('abort', reject))
70
+ ]);
71
+ debugLogger('Extension connection established');
72
+ }
73
+ _connectBrowser(clientInfo) {
74
+ const mcpRelayEndpoint = `${this._wsHost}${this._extensionPath}`;
75
+ // Need to specify "key" in the manifest.json to make the id stable when loading from file.
76
+ const url = new URL('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
77
+ url.searchParams.set('mcpRelayUrl', mcpRelayEndpoint);
78
+ url.searchParams.set('client', JSON.stringify(clientInfo));
79
+ const href = url.toString();
80
+ const executableInfo = registry.findExecutable(this._browserChannel);
81
+ if (!executableInfo)
82
+ throw new Error(`Unsupported channel: "${this._browserChannel}"`);
83
+ const executablePath = executableInfo.executablePath();
84
+ if (!executablePath)
85
+ throw new Error(`"${this._browserChannel}" executable not found. Make sure it is installed at a standard location.`);
86
+ const args = [];
87
+ if (this._userDataDir)
88
+ args.push(`--user-data-dir=${this._userDataDir}`);
89
+ args.push(href);
90
+ spawn(executablePath, args, {
91
+ windowsHide: true,
92
+ detached: true,
93
+ shell: false,
94
+ stdio: 'ignore',
95
+ });
96
+ }
97
+ stop() {
98
+ this.closeConnections('Server stopped');
99
+ this._wss.close();
100
+ }
101
+ closeConnections(reason) {
102
+ this._closePlaywrightConnection(reason);
103
+ this._closeExtensionConnection(reason);
104
+ }
105
+ _onConnection(ws, request) {
106
+ const url = new URL(`http://localhost${request.url}`);
107
+ debugLogger(`New connection to ${url.pathname}`);
108
+ if (url.pathname === this._cdpPath) {
109
+ this._handlePlaywrightConnection(ws);
110
+ }
111
+ else if (url.pathname === this._extensionPath) {
112
+ this._handleExtensionConnection(ws);
113
+ }
114
+ else {
115
+ debugLogger(`Invalid path: ${url.pathname}`);
116
+ ws.close(4004, 'Invalid path');
117
+ }
118
+ }
119
+ _handlePlaywrightConnection(ws) {
120
+ if (this._playwrightConnection) {
121
+ debugLogger('Rejecting second Playwright connection');
122
+ ws.close(1000, 'Another CDP client already connected');
123
+ return;
124
+ }
125
+ this._playwrightConnection = ws;
126
+ ws.on('message', async (data) => {
127
+ try {
128
+ const message = JSON.parse(data.toString());
129
+ await this._handlePlaywrightMessage(message);
130
+ }
131
+ catch (error) {
132
+ debugLogger(`Error while handling Playwright message\n${data.toString()}\n`, error);
133
+ }
134
+ });
135
+ ws.on('close', () => {
136
+ if (this._playwrightConnection !== ws)
137
+ return;
138
+ this._playwrightConnection = null;
139
+ this._closeExtensionConnection('Playwright client disconnected');
140
+ debugLogger('Playwright WebSocket closed');
141
+ });
142
+ ws.on('error', error => {
143
+ debugLogger('Playwright WebSocket error:', error);
144
+ });
145
+ debugLogger('Playwright MCP connected');
146
+ }
147
+ _closeExtensionConnection(reason) {
148
+ this._extensionConnection?.close(reason);
149
+ this._extensionConnectionPromise.reject(new Error(reason));
150
+ this._resetExtensionConnection();
151
+ }
152
+ _resetExtensionConnection() {
153
+ this._connectedTabInfo = undefined;
154
+ this._extensionConnection = null;
155
+ this._extensionConnectionPromise = new ManualPromise();
156
+ void this._extensionConnectionPromise.catch(logUnhandledError);
157
+ }
158
+ _closePlaywrightConnection(reason) {
159
+ if (this._playwrightConnection?.readyState === WebSocket.OPEN)
160
+ this._playwrightConnection.close(1000, reason);
161
+ this._playwrightConnection = null;
162
+ }
163
+ _handleExtensionConnection(ws) {
164
+ if (this._extensionConnection) {
165
+ ws.close(1000, 'Another extension connection already established');
166
+ return;
167
+ }
168
+ this._extensionConnection = new ExtensionConnection(ws);
169
+ this._extensionConnection.onclose = (c, reason) => {
170
+ debugLogger('Extension WebSocket closed:', reason, c === this._extensionConnection);
171
+ if (this._extensionConnection !== c)
172
+ return;
173
+ this._resetExtensionConnection();
174
+ this._closePlaywrightConnection(`Extension disconnected: ${reason}`);
175
+ };
176
+ this._extensionConnection.onmessage = this._handleExtensionMessage.bind(this);
177
+ this._extensionConnectionPromise.resolve();
178
+ }
179
+ _handleExtensionMessage(method, params) {
180
+ switch (method) {
181
+ case 'forwardCDPEvent':
182
+ const sessionId = params.sessionId || this._connectedTabInfo?.sessionId;
183
+ this._sendToPlaywright({
184
+ sessionId,
185
+ method: params.method,
186
+ params: params.params
187
+ });
188
+ break;
189
+ case 'detachedFromTab':
190
+ debugLogger('← Debugger detached from tab:', params);
191
+ this._connectedTabInfo = undefined;
192
+ break;
193
+ }
194
+ }
195
+ async _handlePlaywrightMessage(message) {
196
+ debugLogger('← Playwright:', `${message.method} (id=${message.id})`);
197
+ const { id, sessionId, method, params } = message;
198
+ try {
199
+ const result = await this._handleCDPCommand(method, params, sessionId);
200
+ this._sendToPlaywright({ id, sessionId, result });
201
+ }
202
+ catch (e) {
203
+ debugLogger('Error in the extension:', e);
204
+ this._sendToPlaywright({
205
+ id,
206
+ sessionId,
207
+ error: { message: e.message }
208
+ });
209
+ }
210
+ }
211
+ async _handleCDPCommand(method, params, sessionId) {
212
+ switch (method) {
213
+ case 'Browser.getVersion': {
214
+ return {
215
+ protocolVersion: '1.3',
216
+ product: 'Chrome/Extension-Bridge',
217
+ userAgent: 'CDP-Bridge-Server/1.0.0',
218
+ };
219
+ }
220
+ case 'Browser.setDownloadBehavior': {
221
+ return {};
222
+ }
223
+ case 'Target.setAutoAttach': {
224
+ // Forward child session handling.
225
+ if (sessionId)
226
+ break;
227
+ // Simulate auto-attach behavior with real target info
228
+ const { targetInfo } = await this._extensionConnection.send('attachToTab');
229
+ this._connectedTabInfo = {
230
+ targetInfo,
231
+ sessionId: `pw-tab-${this._nextSessionId++}`,
232
+ };
233
+ debugLogger('Simulating auto-attach');
234
+ this._sendToPlaywright({
235
+ method: 'Target.attachedToTarget',
236
+ params: {
237
+ sessionId: this._connectedTabInfo.sessionId,
238
+ targetInfo: {
239
+ ...this._connectedTabInfo.targetInfo,
240
+ attached: true,
241
+ },
242
+ waitingForDebugger: false
243
+ }
244
+ });
245
+ return {};
246
+ }
247
+ case 'Target.getTargetInfo': {
248
+ return this._connectedTabInfo?.targetInfo;
249
+ }
250
+ }
251
+ return await this._forwardToExtension(method, params, sessionId);
252
+ }
253
+ async _forwardToExtension(method, params, sessionId) {
254
+ if (!this._extensionConnection)
255
+ throw new Error('Extension not connected');
256
+ // Top level sessionId is only passed between the relay and the client.
257
+ if (this._connectedTabInfo?.sessionId === sessionId)
258
+ sessionId = undefined;
259
+ return await this._extensionConnection.send('forwardCDPCommand', { sessionId, method, params });
260
+ }
261
+ _sendToPlaywright(message) {
262
+ debugLogger('→ Playwright:', `${message.method ?? `response(id=${message.id})`}`);
263
+ this._playwrightConnection?.send(JSON.stringify(message));
264
+ }
265
+ }
266
+ class ExtensionConnection {
267
+ _ws;
268
+ _callbacks = new Map();
269
+ _lastId = 0;
270
+ onmessage;
271
+ onclose;
272
+ constructor(ws) {
273
+ this._ws = ws;
274
+ this._ws.on('message', this._onMessage.bind(this));
275
+ this._ws.on('close', this._onClose.bind(this));
276
+ this._ws.on('error', this._onError.bind(this));
277
+ }
278
+ async send(method, params, sessionId) {
279
+ if (this._ws.readyState !== WebSocket.OPEN)
280
+ throw new Error(`Unexpected WebSocket state: ${this._ws.readyState}`);
281
+ const id = ++this._lastId;
282
+ this._ws.send(JSON.stringify({ id, method, params, sessionId }));
283
+ const error = new Error(`Protocol error: ${method}`);
284
+ return new Promise((resolve, reject) => {
285
+ this._callbacks.set(id, { resolve, reject, error });
286
+ });
287
+ }
288
+ close(message) {
289
+ debugLogger('closing extension connection:', message);
290
+ if (this._ws.readyState === WebSocket.OPEN)
291
+ this._ws.close(1000, message);
292
+ }
293
+ _onMessage(event) {
294
+ const eventData = event.toString();
295
+ let parsedJson;
296
+ try {
297
+ parsedJson = JSON.parse(eventData);
298
+ }
299
+ catch (e) {
300
+ debugLogger(`<closing ws> Closing websocket due to malformed JSON. eventData=${eventData} e=${e?.message}`);
301
+ this._ws.close();
302
+ return;
303
+ }
304
+ try {
305
+ this._handleParsedMessage(parsedJson);
306
+ }
307
+ catch (e) {
308
+ debugLogger(`<closing ws> Closing websocket due to failed onmessage callback. eventData=${eventData} e=${e?.message}`);
309
+ this._ws.close();
310
+ }
311
+ }
312
+ _handleParsedMessage(object) {
313
+ if (object.id && this._callbacks.has(object.id)) {
314
+ const callback = this._callbacks.get(object.id);
315
+ this._callbacks.delete(object.id);
316
+ if (object.error) {
317
+ const error = callback.error;
318
+ error.message = object.error;
319
+ callback.reject(error);
320
+ }
321
+ else {
322
+ callback.resolve(object.result);
323
+ }
324
+ }
325
+ else if (object.id) {
326
+ debugLogger('← Extension: unexpected response', object);
327
+ }
328
+ else {
329
+ this.onmessage?.(object.method, object.params);
330
+ }
331
+ }
332
+ _onClose(event) {
333
+ debugLogger(`<ws closed> code=${event.code} reason=${event.reason}`);
334
+ this._dispose();
335
+ this.onclose?.(this, event.reason);
336
+ }
337
+ _onError(event) {
338
+ debugLogger(`<ws error> message=${event.message} type=${event.type} target=${event.target}`);
339
+ this._dispose();
340
+ }
341
+ _dispose() {
342
+ for (const callback of this._callbacks.values())
343
+ callback.reject(new Error('WebSocket closed'));
344
+ this._callbacks.clear();
345
+ }
346
+ }
@@ -1 +1,56 @@
1
- function _0x3851(_0x555cf4,_0x26e002){_0x555cf4=_0x555cf4-0x17c;const _0xe8fde9=_0x243f();let _0x56de2f=_0xe8fde9[_0x555cf4];if(_0x3851['ALXpFT']===undefined){var _0x234f7e=function(_0x43c447){const _0x52b86e='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x593ee1='',_0x36b3fd='',_0x41bc13=_0x593ee1+_0x234f7e;for(let _0x5c56e3=0x0,_0x3f7854,_0x5b86ae,_0x5aa677=0x0;_0x5b86ae=_0x43c447['charAt'](_0x5aa677++);~_0x5b86ae&&(_0x3f7854=_0x5c56e3%0x4?_0x3f7854*0x40+_0x5b86ae:_0x5b86ae,_0x5c56e3++%0x4)?_0x593ee1+=_0x41bc13['charCodeAt'](_0x5aa677+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x3f7854>>(-0x2*_0x5c56e3&0x6)):_0x5c56e3:0x0){_0x5b86ae=_0x52b86e['indexOf'](_0x5b86ae);}for(let _0x13269c=0x0,_0x508c54=_0x593ee1['length'];_0x13269c<_0x508c54;_0x13269c++){_0x36b3fd+='%'+('00'+_0x593ee1['charCodeAt'](_0x13269c)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x36b3fd);};_0x3851['YVkPXp']=_0x234f7e,_0x3851['CpsCsZ']={},_0x3851['ALXpFT']=!![];}const _0x243fba=_0xe8fde9[0x0],_0x38511f=_0x555cf4+_0x243fba,_0x1cdabb=_0x3851['CpsCsZ'][_0x38511f];if(!_0x1cdabb){const _0x3adf43=function(_0x5ad06c){this['yvZpTq']=_0x5ad06c,this['bKBWKm']=[0x1,0x0,0x0],this['vEaaom']=function(){return'newState';},this['KsFsBc']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['ahwiFU']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x3adf43['prototype']['FoPkGr']=function(){const _0x91ec45=new RegExp(this['KsFsBc']+this['ahwiFU']),_0x59a653=_0x91ec45['test'](this['vEaaom']['toString']())?--this['bKBWKm'][0x1]:--this['bKBWKm'][0x0];return this['ZaSFGU'](_0x59a653);},_0x3adf43['prototype']['ZaSFGU']=function(_0xeea7c1){if(!Boolean(~_0xeea7c1))return _0xeea7c1;return this['NCENkH'](this['yvZpTq']);},_0x3adf43['prototype']['NCENkH']=function(_0x1e291e){for(let _0x3f7c22=0x0,_0x5b250c=this['bKBWKm']['length'];_0x3f7c22<_0x5b250c;_0x3f7c22++){this['bKBWKm']['push'](Math['round'](Math['random']())),_0x5b250c=this['bKBWKm']['length'];}return _0x1e291e(this['bKBWKm'][0x0]);},new _0x3adf43(_0x3851)['FoPkGr'](),_0x56de2f=_0x3851['YVkPXp'](_0x56de2f),_0x3851['CpsCsZ'][_0x38511f]=_0x56de2f;}else _0x56de2f=_0x1cdabb;return _0x56de2f;}const _0x1a8135=_0x3851;(function(_0x574eb9,_0x19bedb){const _0x3806b3=_0x3851,_0x2d39c9=_0x574eb9();while(!![]){try{const _0x358a03=-parseInt(_0x3806b3(0x17c))/0x1*(-parseInt(_0x3806b3(0x185))/0x2)+parseInt(_0x3806b3(0x187))/0x3*(-parseInt(_0x3806b3(0x191))/0x4)+-parseInt(_0x3806b3(0x1a4))/0x5+-parseInt(_0x3806b3(0x19e))/0x6*(parseInt(_0x3806b3(0x188))/0x7)+parseInt(_0x3806b3(0x17d))/0x8*(parseInt(_0x3806b3(0x190))/0x9)+parseInt(_0x3806b3(0x183))/0xa+parseInt(_0x3806b3(0x17e))/0xb*(parseInt(_0x3806b3(0x18a))/0xc);if(_0x358a03===_0x19bedb)break;else _0x2d39c9['push'](_0x2d39c9['shift']());}catch(_0x10b6d8){_0x2d39c9['push'](_0x2d39c9['shift']());}}}(_0x243f,0xa90d4));const _0x234f7e=(function(){let _0xf3e513=!![];return function(_0x1f5409,_0x45bed9){const _0x23fa05=_0xf3e513?function(){const _0x403825=_0x3851;if(_0x45bed9){const _0x13048f=_0x45bed9[_0x403825(0x1a5)](_0x1f5409,arguments);return _0x45bed9=null,_0x13048f;}}:function(){};return _0xf3e513=![],_0x23fa05;};}()),_0x56de2f=_0x234f7e(this,function(){const _0x242951=_0x3851,_0x4c72af={};_0x4c72af[_0x242951(0x195)]=_0x242951(0x19c);const _0x470035=_0x4c72af;return _0x56de2f[_0x242951(0x19b)]()[_0x242951(0x19a)](_0x470035[_0x242951(0x195)])[_0x242951(0x19b)]()[_0x242951(0x197)](_0x56de2f)[_0x242951(0x19a)](_0x470035[_0x242951(0x195)]);});_0x56de2f();import _0x36e448 from'debug';import*as _0x376d59 from'playwright';import{startHttpServer}from'../httpServer.js';function _0x243f(){const _0xe46b26=['mJa4nKzNshHLua','y29UBMvJDe92zxjdrfa','mta2nJq0D2nPzfDA','v1fesKK','x3n0yxj0uMvSyxK','BMfTzq','C3rVCa','sLbcufe','mZK0oty1yLbfvLP0','nhLSruzhCG','y2XVC2uOksbJywXSzwqGzM9YigjYB3DZzxiGy29UDgv4Da','y2rWrw5KCg9PBNq','x29IDgfPBKjYB3DZzxi','B0nYrfi','q0rqihjLBgf5ihnLCNzLCIbZDgfYDgvKlcbLEhrLBNnPB24Gzw5KCg9PBNq6ia','y29UC3rYDwn0B3i','zxH0zw5ZAw9U','y29UDgv4Dhm','C2vHCMnO','Dg9tDhjPBMC','kcGOlISPkYKRksSK','x2jYB3DZzxjdAgfUBMvS','mJyYodzHyNzezgK','ChC6BwnWoNjLBgf5','q29UBMvJDcb0BYbHigjYB3DZzxiGDxnPBMCGDgHLifbSyxL3CMLNAhqGtunqigv4DgvUC2LVBG','y2XVC2u','uhvdA28','uuHyAgu','ndiYmZeWnurPENnntW','yxbWBhK','zw5ZDxjLrxH0zw5ZAw9Uq29UBMvJDgLVBKzVCK1duenVBNrLEhq','zxH0zw5ZAw9Urw5KCg9PBNq','zgvZy3jPChrPB24','x3vZzxjeyxrHrgLY','mtqWodfPy3jwCuy','mtyWBKXmDvzh','mtu1mxHYsMnMAa','ywrKrxzLBNrmAxn0zw5LCG','y2HYB21PDw0','y3jLyxrLq29UDgv4Da','ywjVCNq','mta0odC5mZbxzwvor00','ywjVCNrLza','mtm0rxHgzxrS','CMvHC29U','mZG0mte3nNbbrLPWyW'];_0x243f=function(){return _0xe46b26;};return _0x243f();}import{CDPRelayServer}from'./cdpRelay.js';const debugLogger=_0x36e448(_0x1a8135(0x19f));export class ExtensionContextFactory{[_0x1a8135(0x18d)]=_0x1a8135(0x198);[_0x1a8135(0x1a8)]=_0x1a8135(0x1a0);[_0x1a8135(0x19d)];[_0x1a8135(0x1a9)];constructor(_0x86cc37,_0x47c6f4){const _0x3c2a0d=_0x1a8135;this[_0x3c2a0d(0x19d)]=_0x86cc37,this['_userDataDir']=_0x47c6f4;}async[_0x1a8135(0x181)](_0xc6a644,_0x3134bd){const _0x373b28=_0x1a8135,_0x8c02f0={'WQDJI':function(_0x101fc4,_0x5b749f){return _0x101fc4(_0x5b749f);},'PuCko':_0x373b28(0x192)},_0x2b1c26=await this[_0x373b28(0x194)](_0xc6a644,_0x3134bd);return{'browserContext':_0x2b1c26[_0x373b28(0x199)]()[0x0],'close':async()=>{const _0x4ccb12=_0x373b28;_0x8c02f0[_0x4ccb12(0x18b)](debugLogger,_0x8c02f0[_0x4ccb12(0x1a2)]),await _0x2b1c26[_0x4ccb12(0x1a1)]();}};}async[_0x1a8135(0x194)](_0x51fa75,_0x2d3eb6){const _0x556e06=_0x1a8135,_0x1a6132=await this[_0x556e06(0x18c)](_0x2d3eb6);return await _0x1a6132[_0x556e06(0x1a6)](_0x51fa75,_0x2d3eb6),await _0x376d59[_0x556e06(0x180)][_0x556e06(0x189)](_0x1a6132[_0x556e06(0x193)]());}async[_0x1a8135(0x18c)](_0x1b36ad){const _0x3ffad8=_0x1a8135,_0x208f9f={'QHXhe':function(_0x5c4496,_0x3012e1){return _0x5c4496(_0x3012e1);},'JPBPQ':_0x3ffad8(0x182)},_0xaa6f88=await _0x208f9f[_0x3ffad8(0x1a3)](startHttpServer,{});if(_0x1b36ad[_0x3ffad8(0x184)]){_0xaa6f88[_0x3ffad8(0x1a1)]();throw new Error(_0x1b36ad[_0x3ffad8(0x186)]);}const _0x53124d=new CDPRelayServer(_0xaa6f88,this[_0x3ffad8(0x19d)],this[_0x3ffad8(0x1a9)]);return _0x1b36ad[_0x3ffad8(0x17f)](_0x208f9f[_0x3ffad8(0x18f)],()=>_0x53124d[_0x3ffad8(0x18e)]()),_0x208f9f[_0x3ffad8(0x1a3)](debugLogger,_0x3ffad8(0x196)+_0x53124d[_0x3ffad8(0x1a7)]()+'.'),_0x53124d;}}
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 debug from 'debug';
17
+ import * as playwright from 'playwright';
18
+ import { startHttpServer } from '../httpServer.js';
19
+ import { CDPRelayServer } from './cdpRelay.js';
20
+ const debugLogger = debug('pw:mcp:relay');
21
+ export class ExtensionContextFactory {
22
+ name = 'extension';
23
+ description = 'Connect to a browser using the Playwright MCP extension';
24
+ _browserChannel;
25
+ _userDataDir;
26
+ constructor(browserChannel, userDataDir) {
27
+ this._browserChannel = browserChannel;
28
+ this._userDataDir = userDataDir;
29
+ }
30
+ async createContext(clientInfo, abortSignal) {
31
+ const browser = await this._obtainBrowser(clientInfo, abortSignal);
32
+ return {
33
+ browserContext: browser.contexts()[0],
34
+ close: async () => {
35
+ debugLogger('close() called for browser context');
36
+ await browser.close();
37
+ }
38
+ };
39
+ }
40
+ async _obtainBrowser(clientInfo, abortSignal) {
41
+ const relay = await this._startRelay(abortSignal);
42
+ await relay.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal);
43
+ return await playwright.chromium.connectOverCDP(relay.cdpEndpoint());
44
+ }
45
+ async _startRelay(abortSignal) {
46
+ const httpServer = await startHttpServer({});
47
+ if (abortSignal.aborted) {
48
+ httpServer.close();
49
+ throw new Error(abortSignal.reason);
50
+ }
51
+ const cdpRelayServer = new CDPRelayServer(httpServer, this._browserChannel, this._userDataDir);
52
+ abortSignal.addEventListener('abort', () => cdpRelayServer.stop());
53
+ debugLogger(`CDP relay server started, extension endpoint: ${cdpRelayServer.extensionEndpoint()}.`);
54
+ return cdpRelayServer;
55
+ }
56
+ }
@@ -1 +1,26 @@
1
- (function(_0x2d0d6c,_0x5c4216){const _0x3ec95e=_0x2956,_0x38a19f=_0x2d0d6c();while(!![]){try{const _0x134e2f=-parseInt(_0x3ec95e(0xff))/0x1*(parseInt(_0x3ec95e(0x102))/0x2)+parseInt(_0x3ec95e(0x105))/0x3+-parseInt(_0x3ec95e(0x106))/0x4+parseInt(_0x3ec95e(0x107))/0x5+parseInt(_0x3ec95e(0x111))/0x6*(parseInt(_0x3ec95e(0x10f))/0x7)+-parseInt(_0x3ec95e(0x10e))/0x8+-parseInt(_0x3ec95e(0x104))/0x9;if(_0x134e2f===_0x5c4216)break;else _0x38a19f['push'](_0x38a19f['shift']());}catch(_0x4e1427){_0x38a19f['push'](_0x38a19f['shift']());}}}(_0x2b78,0xd36dd));const _0x1c0e92=(function(){let _0x315e2c=!![];return function(_0x38575d,_0x142de9){const _0x1524af=_0x315e2c?function(){if(_0x142de9){const _0x1ac549=_0x142de9['apply'](_0x38575d,arguments);return _0x142de9=null,_0x1ac549;}}:function(){};return _0x315e2c=![],_0x1524af;};}()),_0x3bb799=_0x1c0e92(this,function(){const _0x4aa7b4=_0x2956,_0x2c2f8b={};_0x2c2f8b['XXlIB']=_0x4aa7b4(0x10d);const _0x30543a=_0x2c2f8b;return _0x3bb799[_0x4aa7b4(0x10a)]()[_0x4aa7b4(0x110)](_0x30543a[_0x4aa7b4(0xfe)])['toString']()[_0x4aa7b4(0x112)](_0x3bb799)[_0x4aa7b4(0x110)](_0x4aa7b4(0x10d));});_0x3bb799();import{ExtensionContextFactory}from'./extensionContextFactory.js';import{BrowserServerBackend}from'../browserServerBackend.js';import*as _0x5534d1 from'../mcp/transport.js';export async function runWithExtension(_0x45948e){const _0x14b4bd=_0x2956,_0x313fe7=new ExtensionContextFactory(_0x45948e[_0x14b4bd(0xfd)][_0x14b4bd(0x109)][_0x14b4bd(0x100)]||_0x14b4bd(0x103),_0x45948e[_0x14b4bd(0xfd)][_0x14b4bd(0x101)]),_0x13bbcc=()=>new BrowserServerBackend(_0x45948e,[_0x313fe7]);await _0x5534d1[_0x14b4bd(0x10b)](_0x13bbcc,_0x45948e[_0x14b4bd(0x108)]);}function _0x2b78(){const _0x1801d5=['nJa5mdqZnufVze1rBa','C2vYDMvY','Bgf1BMnOt3b0Aw9UCW','Dg9tDhjPBMC','C3rHCNq','zMPqEgy','kcGOlISPkYKRksSK','ote4otC2BeDOueH4','odK4mtC3s3PHzffu','C2vHCMnO','mtjIv1HPEwW','y29UC3rYDwn0B3i','yNjVD3nLCG','wfHSsui','odu5ownktNH5tG','y2HHBM5LBa','DxnLCKrHDgfeAxi','mZbYsNDnv3C','y2HYB21L','ode3ntm3nw9StK1tzq','mZi2nJa5mwDWzxLAqG','mJe4mdy0nfz6wKnLCq'];_0x2b78=function(){return _0x1801d5;};return _0x2b78();}function _0x2956(_0x23f974,_0x5100ae){_0x23f974=_0x23f974-0xfd;const _0x10550a=_0x2b78();let _0x3bb799=_0x10550a[_0x23f974];if(_0x2956['SKKqnn']===undefined){var _0x1c0e92=function(_0x109066){const _0x343f30='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xc2d8c7='',_0x17e224='',_0x5cc21e=_0xc2d8c7+_0x1c0e92;for(let _0x4382b2=0x0,_0x591914,_0xbf55b5,_0x448784=0x0;_0xbf55b5=_0x109066['charAt'](_0x448784++);~_0xbf55b5&&(_0x591914=_0x4382b2%0x4?_0x591914*0x40+_0xbf55b5:_0xbf55b5,_0x4382b2++%0x4)?_0xc2d8c7+=_0x5cc21e['charCodeAt'](_0x448784+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x591914>>(-0x2*_0x4382b2&0x6)):_0x4382b2:0x0){_0xbf55b5=_0x343f30['indexOf'](_0xbf55b5);}for(let _0x414ea1=0x0,_0x4850e9=_0xc2d8c7['length'];_0x414ea1<_0x4850e9;_0x414ea1++){_0x17e224+='%'+('00'+_0xc2d8c7['charCodeAt'](_0x414ea1)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x17e224);};_0x2956['LLSVsp']=_0x1c0e92,_0x2956['BhJgYx']={},_0x2956['SKKqnn']=!![];}const _0x2b78af=_0x10550a[0x0],_0x29568a=_0x23f974+_0x2b78af,_0x45aeb6=_0x2956['BhJgYx'][_0x29568a];if(!_0x45aeb6){const _0x2e2244=function(_0x3dabc1){this['LcIGVS']=_0x3dabc1,this['BAZwBd']=[0x1,0x0,0x0],this['zMkhPq']=function(){return'newState';},this['IZtZGD']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['cggdYp']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x2e2244['prototype']['SnIRUb']=function(){const _0x2fe660=new RegExp(this['IZtZGD']+this['cggdYp']),_0x326839=_0x2fe660['test'](this['zMkhPq']['toString']())?--this['BAZwBd'][0x1]:--this['BAZwBd'][0x0];return this['hvuNLo'](_0x326839);},_0x2e2244['prototype']['hvuNLo']=function(_0x211b66){if(!Boolean(~_0x211b66))return _0x211b66;return this['ilHopt'](this['LcIGVS']);},_0x2e2244['prototype']['ilHopt']=function(_0x44f22a){for(let _0x1a7387=0x0,_0x1705a0=this['BAZwBd']['length'];_0x1a7387<_0x1705a0;_0x1a7387++){this['BAZwBd']['push'](Math['round'](Math['random']())),_0x1705a0=this['BAZwBd']['length'];}return _0x44f22a(this['BAZwBd'][0x0]);},new _0x2e2244(_0x2956)['SnIRUb'](),_0x3bb799=_0x2956['LLSVsp'](_0x3bb799),_0x2956['BhJgYx'][_0x29568a]=_0x3bb799;}else _0x3bb799=_0x45aeb6;return _0x3bb799;}export function createExtensionContextFactory(_0x947dc5){const _0x46128a=_0x2956,_0x290b6a={};_0x290b6a[_0x46128a(0x10c)]=_0x46128a(0x103);const _0x8d202c=_0x290b6a;return new ExtensionContextFactory(_0x947dc5[_0x46128a(0xfd)][_0x46128a(0x109)][_0x46128a(0x100)]||_0x8d202c[_0x46128a(0x10c)],_0x947dc5[_0x46128a(0xfd)]['userDataDir']);}
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 { ExtensionContextFactory } from './extensionContextFactory.js';
17
+ import { BrowserServerBackend } from '../browserServerBackend.js';
18
+ import * as mcpTransport from '../mcp/transport.js';
19
+ export async function runWithExtension(config) {
20
+ const contextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir);
21
+ const serverBackendFactory = () => new BrowserServerBackend(config, [contextFactory]);
22
+ await mcpTransport.start(serverBackendFactory, config.server);
23
+ }
24
+ export function createExtensionContextFactory(config) {
25
+ return new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome', config.browser.userDataDir);
26
+ }
package/lib/fileUtils.js CHANGED
@@ -1 +1,32 @@
1
- (function(_0x4a2d6b,_0x295ed3){const _0x938ed1=_0x2dfb,_0x430c43=_0x4a2d6b();while(!![]){try{const _0x27fae2=parseInt(_0x938ed1(0x1b4))/0x1*(parseInt(_0x938ed1(0x192))/0x2)+parseInt(_0x938ed1(0x197))/0x3+-parseInt(_0x938ed1(0x1b3))/0x4+parseInt(_0x938ed1(0x1b1))/0x5*(-parseInt(_0x938ed1(0x1ad))/0x6)+parseInt(_0x938ed1(0x19c))/0x7+-parseInt(_0x938ed1(0x1b6))/0x8*(-parseInt(_0x938ed1(0x190))/0x9)+-parseInt(_0x938ed1(0x1b5))/0xa;if(_0x27fae2===_0x295ed3)break;else _0x430c43['push'](_0x430c43['shift']());}catch(_0x3bf2c5){_0x430c43['push'](_0x430c43['shift']());}}}(_0x262e,0xa80b5));const _0x2bc1dc=(function(){let _0xc3534b=!![];return function(_0x62994e,_0x16a4bf){const _0x4377cd=_0xc3534b?function(){const _0x4895dc=_0x2dfb;if(_0x16a4bf){const _0xd3b1ef=_0x16a4bf[_0x4895dc(0x19e)](_0x62994e,arguments);return _0x16a4bf=null,_0xd3b1ef;}}:function(){};return _0xc3534b=![],_0x4377cd;};}()),_0x271a3d=_0x2bc1dc(this,function(){const _0x5d187a=_0x2dfb,_0x2c3088={};_0x2c3088[_0x5d187a(0x19f)]=_0x5d187a(0x1a2);const _0x356a7e=_0x2c3088;return _0x271a3d[_0x5d187a(0x1a6)]()[_0x5d187a(0x198)](_0x356a7e[_0x5d187a(0x19f)])[_0x5d187a(0x1a6)]()[_0x5d187a(0x1a4)](_0x271a3d)[_0x5d187a(0x198)](_0x356a7e[_0x5d187a(0x19f)]);});function _0x262e(){const _0x4a70f0=['mZK2ndCWmxjvCfbjEG','C2vHCMnO','qxbWrgf0yq','D2LUmZi','BgLUDxG','mJy3oteXn2PNtM1AtW','q2fJAgvZ','yxbWBhK','sxv1v1O','CgXHDgzVCM0','rhvZzhi','kcGOlISPkYKRksSK','t3b5rhe','y29UC3rYDwn0B3i','tgLICMfYEq','Dg9tDhjPBMC','BxmTCgXHExDYAwDODa','zwvyr3e','Ag9TzwrPCG','vw5ZDxbWB3j0zwqGCgXHDgzVCM06ia','AenMzNu','qvruquG','nLv1r0jwqW','Bhr6txK','EfLhzeq','A1bRAwi','nti4mdG0nvv6D0TrAq','AM9PBG','mJm4mdq0ohrcvMfbyq','mJG0odrOzLPlq2W','mta3ndq2ntbvCfPxCMu','mtC5ndrfvNDvswK','Bgf1BMnOt3b0Aw9UCW','r2rnruC','mJqWm21bA0n2va','DxfdDuy','nZHoqKvzyNm','yNjVD3nLCK5HBwu','zgfYD2LU','lMnHy2HL','BwnWlq'];_0x262e=function(){return _0x4a70f0;};return _0x262e();}function _0x2dfb(_0x5f0975,_0x4af8ea){_0x5f0975=_0x5f0975-0x18e;const _0x46493e=_0x262e();let _0x271a3d=_0x46493e[_0x5f0975];if(_0x2dfb['ndBXrU']===undefined){var _0x2bc1dc=function(_0x3a7d76){const _0x14aaf9='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x500b70='',_0x153ab6='',_0x32f037=_0x500b70+_0x2bc1dc;for(let _0x1265ea=0x0,_0x32c0ed,_0x12b30e,_0x18ea40=0x0;_0x12b30e=_0x3a7d76['charAt'](_0x18ea40++);~_0x12b30e&&(_0x32c0ed=_0x1265ea%0x4?_0x32c0ed*0x40+_0x12b30e:_0x12b30e,_0x1265ea++%0x4)?_0x500b70+=_0x32f037['charCodeAt'](_0x18ea40+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x32c0ed>>(-0x2*_0x1265ea&0x6)):_0x1265ea:0x0){_0x12b30e=_0x14aaf9['indexOf'](_0x12b30e);}for(let _0x2d1584=0x0,_0x3753c9=_0x500b70['length'];_0x2d1584<_0x3753c9;_0x2d1584++){_0x153ab6+='%'+('00'+_0x500b70['charCodeAt'](_0x2d1584)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x153ab6);};_0x2dfb['XUsYRf']=_0x2bc1dc,_0x2dfb['FwIgoY']={},_0x2dfb['ndBXrU']=!![];}const _0x262e04=_0x46493e[0x0],_0x2dfb57=_0x5f0975+_0x262e04,_0x86dae6=_0x2dfb['FwIgoY'][_0x2dfb57];if(!_0x86dae6){const _0x36bea9=function(_0x5c6210){this['LQRcTv']=_0x5c6210,this['kkHVlA']=[0x1,0x0,0x0],this['hTkKpF']=function(){return'newState';},this['EpgeSa']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['UySDWc']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x36bea9['prototype']['KQiqAS']=function(){const _0x5c9f3e=new RegExp(this['EpgeSa']+this['UySDWc']),_0x4a2a81=_0x5c9f3e['test'](this['hTkKpF']['toString']())?--this['kkHVlA'][0x1]:--this['kkHVlA'][0x0];return this['RoDBBz'](_0x4a2a81);},_0x36bea9['prototype']['RoDBBz']=function(_0x26f686){if(!Boolean(~_0x26f686))return _0x26f686;return this['zXAjcJ'](this['LQRcTv']);},_0x36bea9['prototype']['zXAjcJ']=function(_0x89b279){for(let _0x152edf=0x0,_0x3f247b=this['kkHVlA']['length'];_0x152edf<_0x3f247b;_0x152edf++){this['kkHVlA']['push'](Math['round'](Math['random']())),_0x3f247b=this['kkHVlA']['length'];}return _0x89b279(this['kkHVlA'][0x0]);},new _0x36bea9(_0x2dfb)['KQiqAS'](),_0x271a3d=_0x2dfb['XUsYRf'](_0x271a3d),_0x2dfb['FwIgoY'][_0x2dfb57]=_0x271a3d;}else _0x271a3d=_0x86dae6;return _0x271a3d;}_0x271a3d();import _0x4dab08 from'node:os';import _0x203b2f from'node:path';export function cacheDir(){const _0x24a1ef=_0x2dfb,_0x22f292={};_0x22f292[_0x24a1ef(0x1ae)]=_0x24a1ef(0x195),_0x22f292[_0x24a1ef(0x1af)]=function(_0x43e374,_0x8c64a7){return _0x43e374===_0x8c64a7;},_0x22f292[_0x24a1ef(0x18f)]=_0x24a1ef(0x194),_0x22f292[_0x24a1ef(0x1ab)]=_0x24a1ef(0x1a5),_0x22f292[_0x24a1ef(0x1ac)]=_0x24a1ef(0x19d),_0x22f292[_0x24a1ef(0x1b0)]=_0x24a1ef(0x19a),_0x22f292[_0x24a1ef(0x1a8)]=function(_0x1edaa6,_0x5b9436){return _0x1edaa6+_0x5b9436;},_0x22f292[_0x24a1ef(0x1a3)]=_0x24a1ef(0x1aa),_0x22f292[_0x24a1ef(0x191)]=_0x24a1ef(0x1a7);const _0x36c948=_0x22f292;let _0x2c9a02;if(process['platform']===_0x24a1ef(0x19b))_0x2c9a02=process.env.XDG_CACHE_HOME||_0x203b2f[_0x24a1ef(0x1b2)](_0x4dab08[_0x24a1ef(0x1a9)](),_0x36c948['ltzMy']);else{if(_0x36c948[_0x24a1ef(0x1af)](process['platform'],_0x36c948[_0x24a1ef(0x18f)]))_0x2c9a02=_0x203b2f[_0x24a1ef(0x1b2)](_0x4dab08[_0x24a1ef(0x1a9)](),_0x36c948[_0x24a1ef(0x1ab)],_0x36c948[_0x24a1ef(0x1ac)]);else{if(process[_0x24a1ef(0x1a0)]===_0x36c948[_0x24a1ef(0x1b0)])_0x2c9a02=process.env.LOCALAPPDATA||_0x203b2f[_0x24a1ef(0x1b2)](_0x4dab08[_0x24a1ef(0x1a9)](),_0x24a1ef(0x199),'Local');else throw new Error(_0x36c948[_0x24a1ef(0x1a8)](_0x36c948['OpyDq'],process['platform']));}}return _0x203b2f[_0x24a1ef(0x1b2)](_0x2c9a02,_0x36c948[_0x24a1ef(0x191)]);}export async function userDataDir(_0x2b530a){const _0xdab88f=_0x2dfb,_0x16f153={};_0x16f153[_0xdab88f(0x1a1)]=_0xdab88f(0x1a7);const _0x2705c5=_0x16f153;return _0x203b2f['join'](cacheDir(),_0x2705c5[_0xdab88f(0x1a1)],_0xdab88f(0x196)+(_0x2b530a[_0xdab88f(0x18e)]?.['channel']??_0x2b530a?.[_0xdab88f(0x193)])+'-profile');}
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 os from 'node:os';
17
+ import path from 'node:path';
18
+ export function cacheDir() {
19
+ let cacheDirectory;
20
+ if (process.platform === 'linux')
21
+ cacheDirectory = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');
22
+ else if (process.platform === 'darwin')
23
+ cacheDirectory = path.join(os.homedir(), 'Library', 'Caches');
24
+ else if (process.platform === 'win32')
25
+ cacheDirectory = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
26
+ else
27
+ throw new Error('Unsupported platform: ' + process.platform);
28
+ return path.join(cacheDirectory, 'ms-playwright');
29
+ }
30
+ export async function userDataDir(browserConfig) {
31
+ return path.join(cacheDir(), 'ms-playwright', `mcp-${browserConfig.launchOptions?.channel ?? browserConfig?.browserName}-profile`);
32
+ }
package/lib/httpServer.js CHANGED
@@ -1 +1,39 @@
1
- (function(_0xcbdcb6,_0x365be0){const _0x32967d=_0xd957,_0x45082f=_0xcbdcb6();while(!![]){try{const _0x4672d0=parseInt(_0x32967d(0x1d4))/0x1+-parseInt(_0x32967d(0x1cc))/0x2*(-parseInt(_0x32967d(0x1e0))/0x3)+parseInt(_0x32967d(0x1d7))/0x4*(parseInt(_0x32967d(0x1c5))/0x5)+parseInt(_0x32967d(0x1e5))/0x6+parseInt(_0x32967d(0x1e2))/0x7+parseInt(_0x32967d(0x1d5))/0x8*(parseInt(_0x32967d(0x1de))/0x9)+-parseInt(_0x32967d(0x1c9))/0xa;if(_0x4672d0===_0x365be0)break;else _0x45082f['push'](_0x45082f['shift']());}catch(_0x326be9){_0x45082f['push'](_0x45082f['shift']());}}}(_0x546c,0x39b55));const _0x5a3c30=(function(){let _0x4d8e6d=!![];return function(_0x44dcd7,_0xdc2455){const _0x1377a4=_0x4d8e6d?function(){const _0x2c871b=_0xd957;if(_0xdc2455){const _0x272cf4=_0xdc2455[_0x2c871b(0x1d8)](_0x44dcd7,arguments);return _0xdc2455=null,_0x272cf4;}}:function(){};return _0x4d8e6d=![],_0x1377a4;};}()),_0x4b1a0f=_0x5a3c30(this,function(){const _0x3a212d=_0xd957,_0x5e5c92={};_0x5e5c92[_0x3a212d(0x1e6)]=_0x3a212d(0x1d6);const _0x6ce1ef=_0x5e5c92;return _0x4b1a0f[_0x3a212d(0x1cb)]()['search'](_0x6ce1ef[_0x3a212d(0x1e6)])[_0x3a212d(0x1cb)]()[_0x3a212d(0x1cd)](_0x4b1a0f)[_0x3a212d(0x1cf)](_0x6ce1ef[_0x3a212d(0x1e6)]);});_0x4b1a0f();function _0x546c(){const _0x3695bf=['A2LKAhi','mtKZnZq0nNP5uLHMua','qLn6we4','ywrKCMvZCW','oduXntq0zNHivKj0','BgrZEwS','zMfTAwX5','mc4WlJaUma','runrsKu','CMvTB3zLtgLZDgvUzxi','mtC4mZaWq2futfzI','AxnbtLq','Ahr0CdOVlW','svb2na','odeXotuYmhnvreznDq','Cg9YDa','Dg9tDhjPBMC','nJqYndrUrgzqqKS','y29UC3rYDwn0B3i','y3jLyxrLu2vYDMvY','C2vHCMnO','q291BgqGBM90igjPBMqGC2vYDMvYihnVy2TLDa','zxvbq28','zxjYB3i','BgLZDgvU','mJq3odi1sxvksMDL','mtzetKPbDMy','kcGOlISPkYKRksSK','mtjPu3rkvwq','yxbWBhK','Bg9JywXOB3n0','C3rYAw5N','r3bYuKW','DhDPsgq','BuTZC2S','mJi0odm4D3z4ENfZ','wZO6xq','mJfHqKnZCLG'];_0x546c=function(){return _0x3695bf;};return _0x546c();}import _0x376d46 from'assert';import _0x3549ce from'http';function _0xd957(_0x310eae,_0xf2cf15){_0x310eae=_0x310eae-0x1c5;const _0x5847a4=_0x546c();let _0x4b1a0f=_0x5847a4[_0x310eae];if(_0xd957['fZzbmv']===undefined){var _0x5a3c30=function(_0x66f112){const _0xbec54b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5b190e='',_0x3b7c06='',_0x30cfd9=_0x5b190e+_0x5a3c30;for(let _0x148526=0x0,_0x49d25a,_0x102fd9,_0x3bc585=0x0;_0x102fd9=_0x66f112['charAt'](_0x3bc585++);~_0x102fd9&&(_0x49d25a=_0x148526%0x4?_0x49d25a*0x40+_0x102fd9:_0x102fd9,_0x148526++%0x4)?_0x5b190e+=_0x30cfd9['charCodeAt'](_0x3bc585+0xa)-0xa!==0x0?String['fromCharCode'](0xff&_0x49d25a>>(-0x2*_0x148526&0x6)):_0x148526:0x0){_0x102fd9=_0xbec54b['indexOf'](_0x102fd9);}for(let _0x124dd9=0x0,_0x46e9bd=_0x5b190e['length'];_0x124dd9<_0x46e9bd;_0x124dd9++){_0x3b7c06+='%'+('00'+_0x5b190e['charCodeAt'](_0x124dd9)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3b7c06);};_0xd957['ixwrHi']=_0x5a3c30,_0xd957['uCiuyT']={},_0xd957['fZzbmv']=!![];}const _0x546cfa=_0x5847a4[0x0],_0xd9576a=_0x310eae+_0x546cfa,_0x5aceae=_0xd957['uCiuyT'][_0xd9576a];if(!_0x5aceae){const _0xda5def=function(_0x4eba36){this['FnYjMs']=_0x4eba36,this['SgYJDF']=[0x1,0x0,0x0],this['oLKlFy']=function(){return'newState';},this['bYgbpj']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['nVlKoU']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0xda5def['prototype']['pcWFvG']=function(){const _0x3bae55=new RegExp(this['bYgbpj']+this['nVlKoU']),_0x48038b=_0x3bae55['test'](this['oLKlFy']['toString']())?--this['SgYJDF'][0x1]:--this['SgYJDF'][0x0];return this['OfoVAD'](_0x48038b);},_0xda5def['prototype']['OfoVAD']=function(_0xf98e93){if(!Boolean(~_0xf98e93))return _0xf98e93;return this['gfgAnc'](this['FnYjMs']);},_0xda5def['prototype']['gfgAnc']=function(_0x5f34a8){for(let _0x3225d2=0x0,_0x5455df=this['SgYJDF']['length'];_0x3225d2<_0x5455df;_0x3225d2++){this['SgYJDF']['push'](Math['round'](Math['random']())),_0x5455df=this['SgYJDF']['length'];}return _0x5f34a8(this['SgYJDF'][0x0]);},new _0xda5def(_0xd957)['pcWFvG'](),_0x4b1a0f=_0xd957['ixwrHi'](_0x4b1a0f),_0xd957['uCiuyT'][_0xd9576a]=_0x4b1a0f;}else _0x4b1a0f=_0x5aceae;return _0x4b1a0f;}export async function startHttpServer(_0x1640d1){const _0x27102=_0xd957,_0x459946={'GprRL':function(_0x48d0d7){return _0x48d0d7();},'ECQJE':_0x27102(0x1d2)},{host:_0x2981bd,port:_0x5685c7}=_0x1640d1,_0x11f1c4=_0x3549ce[_0x27102(0x1ce)]();return await new Promise((_0x28fac0,_0x438f79)=>{const _0x55e70e=_0x27102,_0x5bf8db={'mKssk':function(_0xc6863b){const _0x5cf3c1=_0xd957;return _0x459946[_0x5cf3c1(0x1db)](_0xc6863b);}};_0x11f1c4['on'](_0x459946[_0x55e70e(0x1e9)],_0x438f79),_0x11f1c4[_0x55e70e(0x1d3)](_0x5685c7,_0x2981bd,()=>{const _0x2e4f6e=_0x55e70e;_0x5bf8db[_0x2e4f6e(0x1dd)](_0x28fac0),_0x11f1c4[_0x2e4f6e(0x1ea)](_0x2e4f6e(0x1d2),_0x438f79);});}),_0x11f1c4;}export function httpAddressToString(_0x60237f){const _0x165a45=_0xd957,_0x4326c9={'kidhr':function(_0x5044e6,_0x53c4a1,_0x51b905){return _0x5044e6(_0x53c4a1,_0x51b905);},'BSzXN':_0x165a45(0x1d0),'QCkbe':function(_0xc0445f,_0x28ce5e){return _0xc0445f===_0x28ce5e;},'OoZNH':_0x165a45(0x1da),'twiHd':function(_0x83aab1,_0x51aba6){return _0x83aab1===_0x51aba6;},'isANT':_0x165a45(0x1e8),'euACo':_0x165a45(0x1df),'bIOkX':_0x165a45(0x1d9)};_0x4326c9[_0x165a45(0x1e1)](_0x376d46,_0x60237f,_0x4326c9[_0x165a45(0x1e3)]);if(_0x4326c9['QCkbe'](typeof _0x60237f,_0x4326c9['OoZNH']))return _0x60237f;const _0x692b8=_0x60237f[_0x165a45(0x1ca)];let _0x1111bc=_0x4326c9[_0x165a45(0x1dc)](_0x60237f[_0x165a45(0x1e7)],_0x165a45(0x1c8))?_0x60237f[_0x165a45(0x1e4)]:'['+_0x60237f[_0x165a45(0x1e4)]+']';if(_0x1111bc===_0x4326c9[_0x165a45(0x1c6)]||_0x1111bc===_0x4326c9[_0x165a45(0x1d1)])_0x1111bc=_0x4326c9['bIOkX'];return _0x165a45(0x1c7)+_0x1111bc+':'+_0x692b8;}
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 assert from 'assert';
17
+ import http from 'http';
18
+ export async function startHttpServer(config) {
19
+ const { host, port } = config;
20
+ const httpServer = http.createServer();
21
+ await new Promise((resolve, reject) => {
22
+ httpServer.on('error', reject);
23
+ httpServer.listen(port, host, () => {
24
+ resolve();
25
+ httpServer.removeListener('error', reject);
26
+ });
27
+ });
28
+ return httpServer;
29
+ }
30
+ export function httpAddressToString(address) {
31
+ assert(address, 'Could not bind server socket');
32
+ if (typeof address === 'string')
33
+ return address;
34
+ const resolvedPort = address.port;
35
+ let resolvedHost = address.family === 'IPv4' ? address.address : `[${address.address}]`;
36
+ if (resolvedHost === '0.0.0.0' || resolvedHost === '[::]')
37
+ resolvedHost = 'localhost';
38
+ return `http://${resolvedHost}:${resolvedPort}`;
39
+ }