summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-20 08:47:22 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-20 08:47:22 +0100
commitc54a900cdd876edb9aad7123c1c89adb874586aa (patch)
treea1e47265153b71913c769d4e3eb12a0916149912 /src
parent3f3ae0634dcd809410a1ddf09211406f28cfdde1 (diff)
downloadwallet-core-c54a900cdd876edb9aad7123c1c89adb874586aa.tar.gz
wallet-core-c54a900cdd876edb9aad7123c1c89adb874586aa.tar.bz2
wallet-core-c54a900cdd876edb9aad7123c1c89adb874586aa.zip
prevent injecting wallet detection on unwanted pages
Diffstat (limited to 'src')
-rw-r--r--src/wxBackend.ts65
1 files changed, 43 insertions, 22 deletions
diff --git a/src/wxBackend.ts b/src/wxBackend.ts
index 0fd07ab58..dc3045e3b 100644
--- a/src/wxBackend.ts
+++ b/src/wxBackend.ts
@@ -463,35 +463,56 @@ export function wxMain() {
}
});
+ const tabTimers: {[n: number]: number[]} = {};
+
+ chrome.tabs.onRemoved.addListener((tabId, changeInfo) => {
+ let tt = tabTimers[tabId] || [];
+ for (let t of tt) {
+ chrome.extension.getBackgroundPage().clearTimeout(t);
+ }
+ });
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (changeInfo.status != 'complete') {
return;
}
- chrome.tabs.get(tabId, (tab) => {
- if (!tab.url || !tab.id) {
- return;
- }
- let uri = URI(tab.url);
- if (!(uri.protocol() == "http" || uri.protocol() == "https")) {
- return;
- }
- let code = `
- if (("taler" in window) || document.documentElement.getAttribute("data-taler-nojs")) {
- document.dispatchEvent(new Event("taler-probe-result"));
+ const timers: number[] = [];
+
+ const addRun = (dt: number) => {
+ const id = chrome.extension.getBackgroundPage().setTimeout(run, dt);
+ timers.push(id);
+ }
+
+ const run = () => {
+ timers.shift();
+ chrome.tabs.get(tabId, (tab) => {
+ if (chrome.runtime.lastError) {
+ return;
}
- `;
- let run = () => {
+ if (!tab.url || !tab.id) {
+ return;
+ }
+ let uri = URI(tab.url);
+ if (!(uri.protocol() == "http" || uri.protocol() == "https")) {
+ return;
+ }
+ let code = `
+ if (("taler" in window) || document.documentElement.getAttribute("data-taler-nojs")) {
+ document.dispatchEvent(new Event("taler-probe-result"));
+ }
+ `;
chrome.tabs.executeScript(tab.id!, { code, runAt: "document_start" });
- };
- run();
- chrome.extension.getBackgroundPage().setTimeout(run, 50);
- chrome.extension.getBackgroundPage().setTimeout(run, 300);
- chrome.extension.getBackgroundPage().setTimeout(run, 2000);
- chrome.extension.getBackgroundPage().setTimeout(run, 4000);
- chrome.extension.getBackgroundPage().setTimeout(run, 8000);
- chrome.extension.getBackgroundPage().setTimeout(run, 16000);
- });
+ });
+ };
+ addRun(0);
+ addRun(50);
+ addRun(300);
+ addRun(1000);
+ addRun(2000);
+ addRun(4000);
+ addRun(8000);
+ addRun(16000);
+ tabTimers[tabId] = timers;
});
chrome.extension.getBackgroundPage().setInterval(clearRateLimitCache, 5000);