File tree Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @browserbasehq/stagehand-lib " : patch
3
+ ---
4
+
5
+ Fixed small issue with module-level state guard for the Playwright selectors.register call
Original file line number Diff line number Diff line change @@ -38,9 +38,6 @@ async function getCurrentRootFrameId(session: CDPSession): Promise<string> {
38
38
return frameTree . frame . id ;
39
39
}
40
40
41
- /** ensure we register the custom selector only once per process */
42
- let stagehandSelectorRegistered = false ;
43
-
44
41
export class StagehandPage {
45
42
private stagehand : Stagehand ;
46
43
private rawPage : PlaywrightPage ;
@@ -197,10 +194,7 @@ ${scriptContent} \
197
194
198
195
/** Register the custom selector engine that pierces open/closed shadow roots. */
199
196
private async ensureStagehandSelectorEngine ( ) : Promise < void > {
200
- if ( stagehandSelectorRegistered ) return ;
201
- stagehandSelectorRegistered = true ;
202
-
203
- await selectors . register ( "stagehand" , ( ) => {
197
+ const registerFn = ( ) => {
204
198
type Backdoor = {
205
199
getClosedRoot ?: ( host : Element ) => ShadowRoot | undefined ;
206
200
} ;
@@ -299,7 +293,20 @@ ${scriptContent} \
299
293
return out ;
300
294
} ,
301
295
} ;
302
- } ) ;
296
+ } ;
297
+
298
+ try {
299
+ await selectors . register ( "stagehand" , registerFn ) ;
300
+ } catch ( err ) {
301
+ if (
302
+ err instanceof Error &&
303
+ err . message . match ( / s e l e c t o r e n g i n e h a s b e e n a l r e a d y r e g i s t e r e d / )
304
+ ) {
305
+ // ignore
306
+ } else {
307
+ throw err ;
308
+ }
309
+ }
303
310
}
304
311
305
312
/**
You can’t perform that action at this time.
0 commit comments