File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,12 +43,15 @@ export const GoogleAdSense = ({
4343 existing . remove ( ) ;
4444 }
4545
46- // Re-insert the script
47- const script = document . createElement ( "script" ) ;
48- script . src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${ _publisherId } ` ;
49- script . async = true ;
50- script . crossOrigin = "anonymous" ;
51- document . head . appendChild ( script ) ;
46+ // Delay a frame to make sure the DOM is fully updated
47+ requestAnimationFrame ( ( ) => {
48+ // Insert the Google AdSense script
49+ const script = document . createElement ( "script" ) ;
50+ script . src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-${ _publisherId } ` ;
51+ script . async = true ;
52+ script . crossOrigin = "anonymous" ;
53+ document . head . appendChild ( script ) ;
54+ } ) ;
5255 } , [ pathname , _publisherId ] ) ;
5356
5457 return null ;
You can’t perform that action at this time.
0 commit comments