Skip to content

Commit

Permalink
Add custom metric to measure generated content (size and percent) (#108)
Browse files Browse the repository at this point in the history
* Add custom metric to measure generated content (size and percent)

* Removed trailing whitespace

* Apply suggestions from code review

Co-authored-by: Rick Viscomi <[email protected]>

---------

Co-authored-by: Rick Viscomi <[email protected]>
  • Loading branch information
kevinfarrugia and rviscomi authored Jan 26, 2024
1 parent 6728ed1 commit be6cbbb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dist/generated-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let generatedContentPercent = 0;
let generatedContent = 0;

const byteSize = (str) => new Blob([str]).size;

let htmlInitial = $WPT_BODIES[0].response_body;
let htmlAfter = document.documentElement.outerHTML;

if (htmlInitial && htmlAfter) {
let htmlInitialSize = byteSize(htmlInitial);
let htmlAfterSize = byteSize(htmlAfter);
generatedContentPercent = 1 - (htmlInitialSize / htmlAfterSize);
generatedContent = (htmlAfterSize - htmlInitialSize) / 1024;
}

return {
percent: generatedContentPercent.toFixed(4),
sizeInKB: generatedContent.toFixed(2),
};

0 comments on commit be6cbbb

Please sign in to comment.