From 9d77cd5b48dd3baccf15c7071abd917ab99be456 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Thu, 25 Jun 2020 13:53:58 +1000 Subject: [PATCH] Safari compatibility --- src/drivers/webextension/js/content.js | 1 - src/drivers/webextension/js/driver.js | 2 +- src/drivers/webextension/js/lib/iframe.js | 43 ++++++++-------------- src/drivers/webextension/js/lib/network.js | 30 +++++++-------- src/drivers/webextension/js/options.js | 8 +++- src/drivers/webextension/manifest.json | 2 +- 6 files changed, 38 insertions(+), 48 deletions(-) diff --git a/src/drivers/webextension/js/content.js b/src/drivers/webextension/js/content.js index 946100513..71dfbd994 100644 --- a/src/drivers/webextension/js/content.js +++ b/src/drivers/webextension/js/content.js @@ -97,7 +97,6 @@ const Content = { * @param {Array} technologies */ onGetTechnologies(technologies = []) { - console.log({ technologies }) // Inject a script tag into the page to access methods of the window object const script = document.createElement('script') diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index 6e22ea295..9427f5f3a 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -72,7 +72,7 @@ const Driver = { if (previous === null) { open('https://www.wappalyzer.com/installed') } else if (version !== previous && upgradeMessage) { - // open(`https://www.wappalyzer.com/upgraded?v${version}`, false) + open(`https://www.wappalyzer.com/upgraded?v${version}`, false) } await setOption('version', version) diff --git a/src/drivers/webextension/js/lib/iframe.js b/src/drivers/webextension/js/lib/iframe.js index 5fc1ef0ef..d36e22baa 100644 --- a/src/drivers/webextension/js/lib/iframe.js +++ b/src/drivers/webextension/js/lib/iframe.js @@ -163,24 +163,15 @@ * @param {String} responseMessage */ sendToBackground: function(message, event, responseMessage) { - if (typeof chrome !== 'undefined') { - var port = chrome.runtime.connect({ name: 'adparser' }) - - port.onMessage.addListener((message) => { - if (message && typeof message.tracking_enabled !== 'undefined') { - if (message.tracking_enabled) { - utilCallback() - } else { - utilElseCallback() - } - } - }) - - port.postMessage(message) - } else if (window.self.port) { - window.self.port.on(responseMessage, onResponse) - window.self.port.emit(event, message) - } + chrome.runtime.sendMessage(message, (message) => { + if (message && typeof message.tracking_enabled !== 'undefined') { + if (message.tracking_enabled) { + utilCallback() + } else { + utilElseCallback() + } + } + }) }, /** @@ -1446,15 +1437,11 @@ * @param {Function} callback */ function addBackgroundListener(event, callback) { - if (typeof chrome !== 'undefined') { - chrome.runtime.onMessage.addListener(function(msg) { - if (msg.event === event) { - callback(msg) - } - }) - } else if (window.self.port) { - window.self.port.on(event, callback) - } + chrome.runtime.onMessage.addListener(function(msg) { + if (msg.event === event) { + callback(msg) + } + }) } exports.coordinator = { @@ -1541,7 +1528,7 @@ ;(function(adparser, pageUrl) { function onAdFound(log) { adparser.sendToBackground( - { func: 'onAd', args: [log] }, + { source: 'iframe.js', func: 'onAd', args: [log] }, 'onAd', '', function() {} diff --git a/src/drivers/webextension/js/lib/network.js b/src/drivers/webextension/js/lib/network.js index f9f58d843..3e0c8d46a 100644 --- a/src/drivers/webextension/js/lib/network.js +++ b/src/drivers/webextension/js/lib/network.js @@ -730,20 +730,18 @@ } ); - chrome.runtime.onConnect.addListener((port) => { - port.onMessage.addListener((message) => { - if ( message === 'is_tracking_enabled' ) { - ifTrackingEnabled( - port.sender.tab, - function() { - try {port.postMessage({'tracking_enabled': true});} - catch(err) {} }, - function() { - try {port.postMessage({'tracking_enabled': false});} - catch(err) {} } - ); - } - return true; - }); - }); + chrome.runtime.onMessage.addListener((message, sender, callback) => { + if ( message === 'is_tracking_enabled' ) { + ifTrackingEnabled( + sender.tab, + function() { + try {callback({'tracking_enabled': true});} + catch(err) {} }, + function() { + try {callback({'tracking_enabled': false});} + catch(err) {} } + ); + } + return true; + }); })(); diff --git a/src/drivers/webextension/js/options.js b/src/drivers/webextension/js/options.js index 12d67dcfd..26f066c59 100644 --- a/src/drivers/webextension/js/options.js +++ b/src/drivers/webextension/js/options.js @@ -1,6 +1,6 @@ 'use strict' /* eslint-env browser */ -/* globals Utils */ +/* globals chrome, Utils */ const { i18n, getOption, setOption } = Utils @@ -36,6 +36,12 @@ const Options = { }) }) + if (!chrome.pageAction.show) { + document + .querySelector('[data-i18n="optionDynamicIcon"]') + .parentNode.remove() + } + i18n() } } diff --git a/src/drivers/webextension/manifest.json b/src/drivers/webextension/manifest.json index d78581eb6..a1ee31340 100644 --- a/src/drivers/webextension/manifest.json +++ b/src/drivers/webextension/manifest.json @@ -68,4 +68,4 @@ "https://*/*" ], "content_security_policy": "script-src 'self'; object-src 'self'" -} \ No newline at end of file +}