@@ -137,9 +137,11 @@ export class ClipperInject extends FrameInjectBase<ClipperInjectOptions> {
137137
138138 // Set focus to the iframe on initial invocation to ensure keyboard users can access it
139139 // immediately, regardless of how the extension was invoked (MAS 2.4.3 - Focus Order)
140- // Use requestAnimationFrame to ensure the iframe is rendered before focusing
140+ // Use both requestAnimationFrame and setTimeout to handle different browser behaviors
141141 requestAnimationFrame ( ( ) => {
142- this . frame . focus ( ) ;
142+ setTimeout ( ( ) => {
143+ this . frame . focus ( ) ;
144+ } , 50 ) ;
143145 } ) ;
144146 } catch ( e ) {
145147 this . handleConstructorError ( e ) ;
@@ -194,6 +196,15 @@ export class ClipperInject extends FrameInjectBase<ClipperInjectOptions> {
194196 this . frame . src = this . options . frameUrl ;
195197 // Set tabindex to make iframe focusable for keyboard accessibility (MAS 2.4.3 - Focus Order)
196198 this . frame . tabIndex = - 1 ;
199+
200+ // Add onload handler to focus the iframe once content is loaded
201+ // This ensures focus transfer works even when invoked from browser chrome
202+ this . frame . onload = ( ) => {
203+ // Small delay to ensure browser chrome has released focus
204+ setTimeout ( ( ) => {
205+ this . frame . focus ( ) ;
206+ } , 100 ) ;
207+ } ;
197208 }
198209
199210 protected handleConstructorError ( e : Error ) {
@@ -386,10 +397,10 @@ export class ClipperInject extends FrameInjectBase<ClipperInjectOptions> {
386397 this . frame . style . display = "" ;
387398 // Set focus to the iframe when showing it to ensure focus moves from browser chrome
388399 // This enables keyboard users to access the clipper immediately (MAS 2.4.3 - Focus Order)
389- // Use requestAnimationFrame to ensure the iframe is visible before focusing
390- requestAnimationFrame ( ( ) => {
400+ // Use setTimeout to ensure the iframe is fully visible before focusing
401+ setTimeout ( ( ) => {
391402 this . frame . focus ( ) ;
392- } ) ;
403+ } , 50 ) ;
393404 }
394405 this . uiCommunicator . callRemoteFunction ( Constants . FunctionKeys . toggleClipper ) ;
395406 }
0 commit comments