Skip to content

Commit

Permalink
Fixes #6574 Display console message only in debug mode (#6595)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona authored Apr 26, 2024
1 parent 439ec0a commit a76706b
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 111 deletions.
35 changes: 18 additions & 17 deletions assets/js/lcp-beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ function main() {
});

if ( true === lcp_data_response.success ) {
console.log('Bailing out because data is already available');
if (rocket_lcp_data.debug) {
console.log('Bailing out because data is already available');
}

return;
}

Expand All @@ -178,7 +181,10 @@ function main() {
if ( ( rocket_lcp_data.is_mobile && ( screenWidth > rocket_lcp_data.width_threshold || screenHeight > rocket_lcp_data.height_threshold ) ) ||
( ! rocket_lcp_data.is_mobile && ( screenWidth < rocket_lcp_data.width_threshold || screenHeight < rocket_lcp_data.height_threshold ) ) )
{
console.log('Bailing out because screen size is not acceptable');
if (rocket_lcp_data.debug) {
console.log('Bailing out because screen size is not acceptable');
}

return;
}

Expand All @@ -193,7 +199,9 @@ function main() {
label: "lcp",
}];
} else {
console.log("No LCP candidate found.");
if (rocket_lcp_data.debug) {
console.log("No LCP candidate found.");
}
}

above_the_fold_images.forEach(({ element, elementInfo }) => {
Expand All @@ -206,14 +214,6 @@ function main() {

let performance_images_json = JSON.stringify(performance_images);
window.performance_images_json = performance_images_json;
const payload = {
action: 'rocket_lcp',
rocket_lcp_nonce: rocket_lcp_data.nonce,
url: rocket_lcp_data.url,
is_mobile: rocket_lcp_data.is_mobile,
images: performance_images_json,
status: 'success'
};

const data = new FormData();
data.append('action', 'rocket_lcp');
Expand All @@ -235,21 +235,22 @@ function main() {
.then((data) => {
const beaconscript = document.querySelector('[data-name="wpr-lcp-beacon"]');
beaconscript.setAttribute('beacon-completed', 'true');
console.log(data);

if (rocket_lcp_data.debug) {
console.log(data);
}
})
.catch((error) => {
console.error(error);
if (rocket_lcp_data.debug) {
console.error(error);
}
});
}

if (document.readyState !== 'loading') {
console.time("extract");
setTimeout(main, 500);
console.timeEnd("extract");
} else {
document.addEventListener("DOMContentLoaded", function () {
console.time("extract");
setTimeout(main, 500);
console.timeEnd("extract");
});
}
2 changes: 1 addition & 1 deletion assets/js/lcp-beacon.js.min.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a76706b

Please sign in to comment.