diff --git a/lib/frame.js b/lib/frame.js index f6dc2e2..6e72fe4 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -36,10 +36,21 @@ prefs }); } + var port = browser.runtime.connect(); + var tabId; + port.onMessage.addListener(function(data){ + if (data.hasOwnProperty("tabId")){ + console.log("my tab id is", data.tabId); + tabId = data.tabId; + } + }); + var notifications = []; function notify(data){ - browser.runtime.sendMessage({"canvasBlocker-notify": data}); + notifications.push(data); + port.postMessage({"canvasBlocker-notify": data}); } + const preferences = require("sdk/simple-prefs"); function prefs(name){ return preferences.prefs[name]; @@ -99,5 +110,11 @@ if (data["canvasBlocker-unload"]){ enabled = false; } + if (data["canvasBlocker-sendNotifications"] === tabId){ + browser.runtime.sendMessage({ + sender: tabId, + "canvasBlocker-notifications": notifications + }); + } }); }()); \ No newline at end of file diff --git a/lib/intercept.js b/lib/intercept.js index 91cd0ef..bf18cd4 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -81,7 +81,7 @@ case "fake": setRandomSupplyByType(prefs("rng")); var fake = changedFunction.fakeGenerator(prefs, function(messageId){ - notify({url, errorStack: error.stack, messageId}); + notify({url, errorStack: error.stack, messageId, timestamp: new Date()}); }, window, original); switch (fake){ case true: diff --git a/lib/main.js b/lib/main.js index 549db09..0b8551b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -10,8 +10,14 @@ console.log("got data", data); }); browser.runtime.onConnect.addListener(function(port){ - console.log("got port"); + console.log("got port", port); + port.postMessage({tabId: port.sender.tab.id}); + port.onMessage.addListener(function(data){ + browser.pageAction.show(port.sender.tab.id); + console.log("got data", data, "from port", port); + }); }); + console.log("end main script"); return null; require("./stylePreferencePane"); diff --git a/manifest.json b/manifest.json index 01c2a81..ce6488d 100644 --- a/manifest.json +++ b/manifest.json @@ -34,6 +34,14 @@ "browser_style": true, "page": "options/options.html" }, + "page_action": { + "browser_style": true, + "default_icon": { + "19": "pageAction/printed19.png", + "38": "pageAction/printed38.png" + }, + "default_popup": "pageAction/pageAction.html" + }, "author": "Korbinian Kapsner", "license": "MPL 2.0", "permissions": [ diff --git a/pageAction/pageAction.css b/pageAction/pageAction.css new file mode 100644 index 0000000..eb9bcb4 --- /dev/null +++ b/pageAction/pageAction.css @@ -0,0 +1,10 @@ +.template { + display: none; +} + +#prints { + min-width: 400px; +} +.print { + white-space: pre; +} \ No newline at end of file diff --git a/pageAction/pageAction.html b/pageAction/pageAction.html new file mode 100644 index 0000000..0dc3c84 --- /dev/null +++ b/pageAction/pageAction.html @@ -0,0 +1,12 @@ + + + + CanvasBlocker page action + + + + + + + diff --git a/pageAction/pageAction.js b/pageAction/pageAction.js new file mode 100644 index 0000000..9bfa3ba --- /dev/null +++ b/pageAction/pageAction.js @@ -0,0 +1,26 @@ +// console.log(window, browser, browser.runtime); +browser.tabs.query({active: true, currentWindow: true}).then(function(tabs){ + if (!tabs.length){ + throw new Error("noTabsFound"); + } + var tab = tabs[0]; + browser.runtime.onMessage.addListener(function(data){ + if (Array.isArray(data["canvasBlocker-notifications"])){ + var ul = document.getElementById("prints"); + data["canvasBlocker-notifications"].forEach(function(notification){ + var li = document.createElement("li"); + li.className = "print"; + li.textContent = notification.url + ": " + notification.messageId + " (" + notification.timestamp + ")" + "\n" + notification.errorStack; + ul.appendChild(li); + }); + } + }); + browser.tabs.sendMessage( + tab.id, + { + "canvasBlocker-sendNotifications": tab.id + } + ); +}).catch(function(e){ + console.error(e); +}); \ No newline at end of file diff --git a/pageAction/printed19.png b/pageAction/printed19.png new file mode 100644 index 0000000..47f97c0 Binary files /dev/null and b/pageAction/printed19.png differ diff --git a/pageAction/printed38.png b/pageAction/printed38.png new file mode 100644 index 0000000..2fd7368 Binary files /dev/null and b/pageAction/printed38.png differ diff --git a/releaseNotes.txt b/releaseNotes.txt index 7dac984..45bcbbb 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -2,8 +2,10 @@ Version 0.4.0: todos: - import settings in content script (have to wait for the new API to register content scripts) - check if webGL is still working + - add notification actions to page action popup changes: - switched to webExtension + - notifications are now done via page action new features: -