aboutsummaryrefslogtreecommitdiffstats
path: root/background.js
diff options
context:
space:
mode:
authorTeddy Wing2018-10-05 16:33:01 +0200
committerTeddy Wing2018-10-05 16:33:01 +0200
commit4792514bbcf4aa0c1b102a3afc25c8c0ae4636b5 (patch)
tree9bcbb467d2f119b7d51a408faaaa8495a626bb9b /background.js
parentd6af5af47db7690bfbec476f0f2944cd0b204f07 (diff)
downloadLegibility-4792514bbcf4aa0c1b102a3afc25c8c0ae4636b5.tar.bz2
Fix CSS not loading in background tabs
When opening tabs in the background, for example when clicking links, custom CSS wouldn't get properly loaded in those tabs. It turns out that the CSS was actually getting loaded into the current tab, which I hadn't realised. Thanks to Niklas Gollenstede's answer here for clueing me into this: https://discourse.mozilla.org/t/inject-css-with-webextension/16877/3 To fix the problem, we specify the `tabId` in which to load the CSS. We get the `tabId` from the `webNavigation.onCompleted` event, which tells us the page is basically ready.
Diffstat (limited to 'background.js')
-rw-r--r--background.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/background.js b/background.js
index 57a2870..7510556 100644
--- a/background.js
+++ b/background.js
@@ -22,5 +22,10 @@ if (chrome) {
}
browser.runtime.onMessage.addListener(function(message) {
- browser.tabs.insertCSS({ file: '/css/' + message.domain + '.css' });
+ browser.webNavigation.onCompleted.addListener(function(details) {
+ browser.tabs.insertCSS(
+ details.tabId,
+ { file: '/css/' + message.domain + '.css' }
+ );
+ });
});