@@ -17,11 +17,7 @@ export class WebMidsceneTools extends BaseMidsceneTools {
1717 ) ;
1818
1919 protected createTemporaryDevice ( ) {
20- // Import PuppeteerWebPage class using dynamic ESM import
21- // This is intentionally synchronous despite the async nature of createTemporaryDevice
22- // because we need the class constructor immediately for tool initialization
23- // The alternative would be to make all tool initialization async, which is a larger refactor
24- // eslint-disable-next-line @typescript-eslint/no-var-requires
20+ // Synchronous require needed for tool initialization
2521 const { PuppeteerWebPage } = require ( '@midscene/web' ) ;
2622
2723 // Create minimal mock page object that satisfies the interface
@@ -48,11 +44,9 @@ export class WebMidsceneTools extends BaseMidsceneTools {
4844 // Re-init if URL provided
4945 if ( this . agent && openNewTabWithUrl ) {
5046 try {
51- if ( this . agent . destroy ) {
52- await this . agent . destroy ( ) ;
53- }
54- } catch ( e ) {
55- console . debug ( 'Failed to destroy agent during re-init:' , e ) ;
47+ await this . agent ?. destroy ?.( ) ;
48+ } catch ( error ) {
49+ console . debug ( 'Failed to destroy agent during re-init:' , error ) ;
5650 }
5751 this . agent = undefined ;
5852 }
@@ -67,7 +61,7 @@ export class WebMidsceneTools extends BaseMidsceneTools {
6761 'Bridge mode requires a URL. Use web_connect tool to connect to a page first.' ,
6862 ) ;
6963 }
70- this . agent = ( await this . initAgentByBridgeMode (
64+ this . agent = ( await this . initBridgeModeAgent (
7165 openNewTabWithUrl ,
7266 ) ) as unknown as BaseAgent ;
7367 } else {
@@ -80,7 +74,7 @@ export class WebMidsceneTools extends BaseMidsceneTools {
8074 return this . agent ;
8175 }
8276
83- private async initAgentByBridgeMode (
77+ private async initBridgeModeAgent (
8478 url ?: string ,
8579 ) : Promise < AgentOverChromeBridge > {
8680 const agent = new AgentOverChromeBridge ( { closeConflictServer : true } ) ;
@@ -133,20 +127,13 @@ export class WebMidsceneTools extends BaseMidsceneTools {
133127 } ;
134128 }
135129
136- const { parseBase64 } = await import ( '@midscene/shared/img' ) ;
137- const { mimeType, body } = parseBase64 ( screenshot ) ;
138-
139130 return {
140131 content : [
141132 {
142133 type : 'text' ,
143134 text : `Connected to: ${ url } ` ,
144135 } ,
145- {
146- type : 'image' ,
147- data : body ,
148- mimeType,
149- } ,
136+ ...this . buildScreenshotContent ( screenshot ) ,
150137 ] ,
151138 } ;
152139 } ,
0 commit comments