summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-27 21:24:49 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-27 21:24:49 +0100
commitfbfddb02afc6f144b1255b677e0d4249adc10b89 (patch)
treef5bffea438147752f5219778491b5fdcd4960717 /content
parent5c58b3d65e370ebd3dadc1133157c73c6afc84af (diff)
downloadbrowser-extension-fbfddb02afc6f144b1255b677e0d4249adc10b89.tar.gz
browser-extension-fbfddb02afc6f144b1255b677e0d4249adc10b89.zip
add actual payload injection functionality to new content script
Diffstat (limited to 'content')
-rw-r--r--content/content.js39
1 files changed, 34 insertions, 5 deletions
diff --git a/content/content.js b/content/content.js
index 804a473..feef5db 100644
--- a/content/content.js
+++ b/content/content.js
@@ -48,16 +48,19 @@
#FROM common/policy.js IMPORT decide_policy
#FROM content/policy_enforcing.js IMPORT enforce_blocking
-let already_run = false, page_info;
+let already_run = false, resolve_page_info,
+ page_info_prom = new Promise(cb => resolve_page_info = cb);
function on_page_info_request([type], sender, respond_cb) {
if (type !== "page_info")
return;
- respond_cb(page_info);
+ page_info_prom.then(respond_cb);
+
+ return true;
}
-globalThis.haketilo_content_script_main = function() {
+globalThis.haketilo_content_script_main = async function() {
if (already_run)
return;
@@ -73,10 +76,36 @@ globalThis.haketilo_content_script_main = function() {
document.URL,
globalThis.haketilo_defualt_allow,
globalThis.haketilo_secret);
- page_info = Object.assign({url: document.URL}, policy);
+ const page_info = Object.assign({url: document.URL}, policy);
["csp", "nonce"].forEach(prop => delete page_info[prop]);
- enforce_blocking(policy);
+ if ("payload" in policy) {
+ const msg = ["indexeddb_files", policy.payload.identifier];
+ var scripts_prom = browser.runtime.sendMessage(msg);
+ }
+
+ await enforce_blocking(policy);
+
+ if ("payload" in policy) {
+ const script_response = await scripts_prom;
+
+ if ("error" in script_response) {
+ resolve_page_info(Object.assign(page_info, script_response));
+ return;
+ } else {
+ for (const script_contents of script_response) {
+ const html_ns = "http://www.w3.org/1999/xhtml";
+ const script = document.createElementNS(html_ns, "script");
+
+ script.innerText = script_contents;
+ script.setAttribute("nonce", policy.nonce);
+ document.documentElement.append(script);
+ script.remove();
+ }
+ }
+ }
+
+ resolve_page_info(page_info);
}
function main() {