Skip to content

Commit

Permalink
fix: remove document.write (#2019)
Browse files Browse the repository at this point in the history
* fix: remove document.write

* fixes

---------

Co-authored-by: Shane Osbourne <sosbourne@duckduckgo.com>
  • Loading branch information
shakyShane and Shane Osbourne committed Feb 27, 2023
1 parent 3b0581e commit 019f8ea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/browser-sync/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module.exports = {
baseDir: path.join(__dirname, "control-panel")
},
templates: {
scriptTag: path.join(__dirname, "..", "templates/script-tags.tmpl"),
scriptTag: path.join(__dirname, "..", "templates/script-tags.html"),
scriptTagSimple: path.join(
__dirname,
"..",
"templates/script-tags-simple.tmpl"
"templates/script-tags-simple.html"
),
connector: path.join(__dirname, "..", "templates/connector.tmpl")
},
Expand Down
16 changes: 16 additions & 0 deletions packages/browser-sync/templates/script-tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script id="__bs_script__">//<![CDATA[
(function() {
try {
var script = document.createElement('script');
if ('%async%') {
script.async = true;
}
script.src = '%script%'.replace("HOST", location.hostname);
if (document.body) {
document.body.appendChild(script);
}
} catch (e) {
console.error("Browsersync: could not append script tag", e);
}
})()
//]]></script>
3 changes: 0 additions & 3 deletions packages/browser-sync/templates/script-tags.tmpl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("E2E script with/without async attribute", function() {
}
};
browserSync(config, function(err, bs) {
assert.notInclude(bs.options.get("snippet"), "async");
assert.notInclude(bs.options.get("snippet"), "'async'");
bs.cleanup();
done();
});
Expand Down

0 comments on commit 019f8ea

Please sign in to comment.