aboutsummaryrefslogtreecommitdiff
path: root/main_background.js
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2018-09-02 18:06:36 +0200
committerhackademix <giorgio@maone.net>2018-09-02 18:06:36 +0200
commita8d4d4b9ff1076e0755fa357870845323ae6c4a7 (patch)
treec54e21ba5c2e63509e13eed3df10295f1cb90fd3 /main_background.js
parent35daafa5e5f7d094698933816e812d666c739982 (diff)
Fixes serialization of modified HTML documents erases DOCTYPE and root element information, possibly causing rendering issues.
Diffstat (limited to 'main_background.js')
-rw-r--r--main_background.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/main_background.js b/main_background.js
index e2c3635..8e4665a 100644
--- a/main_background.js
+++ b/main_background.js
@@ -931,6 +931,22 @@ async function handle_script(response, whitelisted){
}
/**
+* Serializes HTMLDocument objects including the root element and
+* the DOCTYPE declaration
+*/
+function doc2HTML(doc) {
+ let s = doc.documentElement.outerHTML;
+ if (doc.doctype) {
+ let dt = doc.doctype;
+ let sDoctype = `<!DOCTYPE ${dt.name || "html"}`;
+ if (dt.publicId) sDoctype += ` PUBLIC "${dt.publicId}"`;
+ if (dt.systemId) sDoctype += ` "${dt.systemId}"`;
+ s = `${sDoctype}>\n${s}`;
+ }
+ return s;
+}
+
+/**
* Removes noscript tags with name "librejs-path" leaving the inner content to load.
*/
function remove_noscripts(html_doc){
@@ -940,7 +956,7 @@ function remove_noscripts(html_doc){
}
}
- return html_doc.documentElement.innerHTML;
+ return doc2HTML(html_doc);
}
/**