diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index 5d8424eb9c2..9ce4801e953 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -1652,7 +1652,7 @@ function amp_get_content_sanitizers( $post = null ) { // Mark the script output by wp_post_preview_js() as being in dev mode. if ( is_preview() && get_queried_object() instanceof WP_Post ) { $dev_mode_xpaths[] = sprintf( - '//script[ not( @src ) and contains( text(), "document.location.search" ) and contains( text(), "preview=true" ) and contains( text(), "unload" ) and contains( text(), "window.name" ) and contains( text(), "wp-preview-%d" ) ]', + '//script[ not( @src ) and contains( text(), "document.location.search" ) and contains( text(), "preview=true" ) and ( contains( text(), "pagehide" ) or contains( text(), "unload" ) ) and contains( text(), "window.name" ) and contains( text(), "wp-preview-%d" ) ]', get_queried_object_id() ); } diff --git a/tests/php/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php index f19f55b8292..096c4b873a1 100644 --- a/tests/php/test-amp-helper-functions.php +++ b/tests/php/test-amp-helper-functions.php @@ -1938,7 +1938,7 @@ static function () { '//*[ @id = "wpadminbar" ]', '//*[ @id = "wpadminbar" ]//*', '//style[ @id = "admin-bar-inline-css" ]', - '//script[ not( @src ) and contains( text(), "document.location.search" ) and contains( text(), "preview=true" ) and contains( text(), "unload" ) and contains( text(), "window.name" ) and contains( text(), "wp-preview-' . $post . '" ) ]', + '//script[ not( @src ) and contains( text(), "document.location.search" ) and contains( text(), "preview=true" ) and ( contains( text(), "pagehide" ) or contains( text(), "unload" ) ) and contains( text(), "window.name" ) and contains( text(), "wp-preview-' . $post . '" ) ]', '//link[@rel="manifest" and contains(@href, "web-app-manifest")]', ], $sanitizers[ AMP_Dev_Mode_Sanitizer::class ]['element_xpaths']