/** * Put the runtime in the document's head, before anything in the body runs. * * The probe injects the runtime by appending a ``; const head = /]*>/i.exec(html); if (head) { const at = head.index + head[0].length; return html.slice(0, at) + tag + html.slice(at); } // No head: get in before so body scripts still see the runtime. A // fragment with neither lands at the front, which is the same guarantee. const body = /]*>/i.exec(html); if (body) return html.slice(0, body.index) + tag + html.slice(body.index); const htmlTag = /]*>/i.exec(html); if (htmlTag) { const at = htmlTag.index + htmlTag[0].length; return html.slice(0, at) + tag + html.slice(at); } return tag + html; }