File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
libs/@guardian/libs/src/consent-management-platform Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @guardian/libs ' : minor
3+ ---
4+
5+ Add pageshow event listener for pageshow event to ensure the Consent or Pay banner is shown after clicking the Browser's back button
Original file line number Diff line number Diff line change @@ -362,6 +362,14 @@ export const init = (
362362 }
363363 } ) ;
364364
365+ // Handle back navigation to ensure CMP messaging is shown when needed
366+ window . addEventListener ( 'pageshow' , ( event : PageTransitionEvent ) => {
367+ // Only re-execute messaging if the page is being loaded from cache i.e. via back/forward navigation
368+ if ( event . persisted ) {
369+ window . _sp_ ?. executeMessaging ?.( ) ;
370+ }
371+ } ) ;
372+
365373 spLib . src = `${ ENDPOINT } /unified/wrapperMessagingWithoutDetection.js` ;
366374
367375 document . body . appendChild ( spLib ) ;
You can’t perform that action at this time.
0 commit comments