aboutsummaryrefslogtreecommitdiff
path: root/content/content.js
diff options
context:
space:
mode:
Diffstat (limited to 'content/content.js')
-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() {