与this类似,我想要注入html外部的js文件。
我的问题的背景 - 我使用cobertura为我的Angular6应用程序生成代码覆盖。在我的vsts构建中,我发布了代码覆盖率结果,但是当需要触发.js文件时单步执行文件链接时,我在浏览器中出现错误:
Blocked script execution in '<URL>' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.
我认为最好的解决方案是执行一个脚本将javascript代码直接注入html而不是外部链接到它。
所以例如说html是这样的:
<html>
<script src="code.js"></script>
...
</html>
然后运行像injector.js
这样的脚本:node ./injector.js
html将成为:
<html>
<script>
function hello() {
console.log('hello');
}
</script>
</html>
你怎么能这样做?
还是有更好的解决方案来解决这个问题?
由于您的开发完全基于NodeJs。
您只需编写nodejs脚本即可
以下NPM模块确实完成了内联工作,几乎没有优化https://www.npmjs.com/package/vsts-coverage-styles
免责声明:我写了上面提到的简单可重用的npm包。