diff --git a/lib/main.js b/lib/main.js index 49f49ba..d1df954 100644 --- a/lib/main.js +++ b/lib/main.js @@ -820,6 +820,27 @@ class PolyfillService { return newHeader; } + getScriptInsertPoint(data, lookForMeta = false) { + const pHead = data.indexOf("", pCharset+16); + if (pPoint < 0) + return false; + return pPoint + 1; + } + } + // just insert directly after head + const pPoint = data.indexOf(">", pHead+5); + if (pPoint < 0) + return false; + return pPoint + 1; + } + modifyRequestData(data, activeFixes) { activeFixes.ensureCompiled(); if (activeFixes.contentReplace) { @@ -828,12 +849,10 @@ class PolyfillService { } } if (activeFixes.scripts) { - const p1 = data.indexOf("=0) { - const p2 = data.indexOf(">", p1+5); - if (p2 >= 0) { - data = data.slice(0, p2 + 1) + activeFixes.scripts + data.slice(p2 + 1); - } + const splicePos = this.getScriptInsertPoint(data.slice(0, 1024), true) || + this.getScriptInsertPoint(data); + if (splicePos >= 0) { + data = data.slice(0, splicePos) + activeFixes.scripts + data.slice(splicePos); } } return data;