changeset 46:586eebf8efb7

Work around race condition in feed reader subscription script execution browser.tabs.executeScript() should only run the script once the feed preview page is completely loaded but there seems to be a race condition where it is run too early resulting in disabled feed reader subscription.
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Wed, 03 Jul 2019 15:51:36 +0200
parents cc328d4662dd
children b68880838990
files js/background.js
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/js/background.js	Fri Apr 12 12:17:47 2019 +0200
+++ b/js/background.js	Wed Jul 03 15:51:36 2019 +0200
@@ -192,8 +192,7 @@
 });
 
 browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
-    if (typeof changeInfo.url === 'undefined') {
-        // filter out updates which do not change the URL
+    if (changeInfo.status !== 'complete') {
         return;
     }
 
@@ -202,13 +201,13 @@
     browser.pageAction.hide(tabId);
 
     // inject content script once if the requested URL is a feed preview
-    if (tabsFeedPreviews.get(tabId) === changeInfo.url) {
+    if (tabsFeedPreviews.get(tabId) === tab.url) {
         browser.tabs.executeScript(tabId, {
             file: 'content_scripts/feed-readers.js'
         });
         tabsFeedPreviews.delete(tabId);
     }
-});
+}, {properties: ["status"]});
 
 browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
     tabsFeeds.delete(tabId);