diff --git a/clipboard-apis/async-write-html-read-html.https.html b/clipboard-apis/async-write-html-read-html.https.html
index 2573916bd6af25..0e1984033491e6 100644
--- a/clipboard-apis/async-write-html-read-html.https.html
+++ b/clipboard-apis/async-write-html-read-html.https.html
@@ -19,12 +19,23 @@
// but when we are comparing for equality the spaces make a difference.
function reformatHtml(html) {
const parser = new DOMParser();
- const htmlString =
- parser.parseFromString(html, 'text/html').documentElement.innerHTML;
- const reformattedString = htmlString.replace(/\>\s*\ <');
+ const parsedHtml = parser.parseFromString(html, 'text/html')
+
+ // More canonical form
+ // Remove the head - not visible to users
+ const headElement = parsedHtml.head;
+ if (headElement) { headElement.remove(); }
+ // Remove the eventual style attributes
+ const elementsWithStyleAttribute = parsedHtml.querySelectorAll('[style]');
+ elementsWithStyleAttribute.forEach((element) => { element.removeAttribute('style'); });
+ const htmlString = parsedHtml.documentElement.innerHTML;
+ // Remove multiple spaces and returns and replacing by one
+ // trim leading and tailing white spaces
+ const reformattedString = htmlString.replace(/\>[\s\n]*\ <').trim();
return reformattedString;
}
+
async function readWriteTest(textInput) {
await tryGrantReadPermission();
await tryGrantWritePermission();