<commit_before>// This file is executed via Puppeteer's page.evaluate on a document to wrap it
// with an <iframe>, so that we can perform viewport-constrained visual diff
// tests.

// The texts __WIDTH__ and __HEIGHT__ will be replaced at execution time with
// the viewport's size from the visual test's config.

const pageContents = document.documentElement.outerHTML;

while (document.head.firstChild) {
  document.head.removeChild(document.head.firstChild);
}

while (document.body.firstChild) {
  document.body.removeChild(document.body.firstChild);
}

const iframe = document.createElement('iframe');
iframe.width = __WIDTH__;
iframe.height = __HEIGHT__;<commit_msg>Add <meta charset> tag to visual diff tests that are wrapped in an iframe (#17118)<commit_after>// This file is executed via Puppeteer's page.evaluate on a document to wrap it
// with an <iframe>, so that we can perform viewport-constrained visual diff
// tests.

// The texts __WIDTH__ and __HEIGHT__ will be replaced at execution time with
// the viewport's size from the visual test's config.

const pageContents = document.documentElement.outerHTML;

const metaCharset = document.querySelector('head meta[charset]')
    || document.createElement('meta');
if (!metaCharset.hasAttribute('charset')) {
  metaCharset.setAttribute('charset', 'utf-8');
}

while (document.head.firstChild) {
  document.head.removeChild(document.head.firstChild);
}
document.head.appendChild(metaCharset);

while (document.body.firstChild) {
  document.body.removeChild(document.body.firstChild);
}

const iframe = document.createElement('iframe');
iframe.width = __WIDTH__;
iframe.height = __HEIGHT__;
{'fraction_non_alphanumeric': 0.10748792270531402, 'fraction_numerical': 0.0036231884057971015, 'mean_word_length': 5.159851301115242, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5706770', 'n_tokens_mistral': 497, 'n_tokens_neox': 465, 'n_words': 147}