Index: background.js |
diff --git a/background.js b/background.js |
index cb7a861be117f6a390b74ffa1370bb9de50ba33f..1ef27a2a2af6eff21491c1e782fc4d3e603d75da 100644 |
--- a/background.js |
+++ b/background.js |
@@ -21,9 +21,12 @@ const {RegExpFilter} = require("filterClasses"); |
const {ElemHide} = require("elemHide"); |
const {checkWhitelisted} = require("whitelisting"); |
const {extractHostFromFrame} = require("url"); |
+const {hideElements} = require("css"); |
const {port} = require("messaging"); |
const devtools = require("devtools"); |
+let tryInsertCSS = true; |
+ |
port.on("get-selectors", (msg, sender) => |
{ |
let selectors; |
@@ -45,7 +48,35 @@ port.on("get-selectors", (msg, sender) => |
selectors = []; |
} |
- return {selectors, trace}; |
+ if (!tryInsertCSS) |
+ return {selectors, trace, inject: true}; |
+ |
+ return new Promise(resolve => |
+ { |
+ hideElements(sender.page.id, sender.frame.id, selectors, error => |
+ { |
+ if (error && /\bError processing cssOrigin\b/.test(error.message) != -1) |
+ tryInsertCSS = false; |
+ |
+ let response = {trace, inject: !!error}; |
+ |
+ if (trace || error) |
+ response.selectors = selectors; |
+ |
+ resolve(response); |
+ }); |
+ }); |
+}); |
+ |
+port.on("hide-elements", (msg, sender) => |
+{ |
+ return new Promise(resolve => |
+ { |
+ hideElements(sender.page.id, sender.frame.id, msg.selectors, error => |
+ { |
+ resolve({success: !error}); |
+ }); |
+ }); |
}); |
port.on("forward", (msg, sender) => |