@@ -4,7 +4,7 @@ import { ServerUnaryCall, sendUnaryData } from 'grpc';
44import { PlaywrightState } from './playwright-state' ;
55import { Request , Response , Types } from './generated/playwright_pb' ;
66import { boolResponse , intResponse , stringResponse } from './response-util' ;
7- import { invokeOnPage , invokePlaywrightMethod , waitUntilElementExists } from './playwirght-invoke' ;
7+ import { determineElement , invokeOnPage , invokePlaywrightMethod , waitUntilElementExists } from './playwirght-invoke' ;
88
99export async function getTitle ( callback : sendUnaryData < Response . String > , page ?: Page ) {
1010 const title = await invokeOnPage ( page , callback , 'title' ) ;
@@ -122,3 +122,18 @@ export async function getViewportSize(
122122 const result = await invokeOnPage ( page , callback , 'viewportSize' ) ;
123123 callback ( null , stringResponse ( JSON . stringify ( result ) ) ) ;
124124}
125+
126+ export async function getBoundingBox (
127+ call : ServerUnaryCall < Request . ElementSelector > ,
128+ callback : sendUnaryData < Response . String > ,
129+ state : PlaywrightState ,
130+ ) : Promise < void > {
131+ const selector = call . request . getSelector ( ) ;
132+ const elem = await determineElement ( state , selector , callback ) ;
133+ if ( ! elem ) {
134+ callback ( new Error ( `No element matching ${ elem } found` ) , null ) ;
135+ return ;
136+ }
137+ const boundingBox = await elem . boundingBox ( ) ;
138+ callback ( null , stringResponse ( JSON . stringify ( boundingBox ) ) ) ;
139+ }
0 commit comments