addons/firefox-addons/feed-preview

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 Jul 03 15:51:36 2019 +0200 (11 months ago)
parents cc328d4662dd
children b68880838990
files js/background.js
line diff
     1.1 --- a/js/background.js	Fri Apr 12 12:17:47 2019 +0200
     1.2 +++ b/js/background.js	Wed Jul 03 15:51:36 2019 +0200
     1.3 @@ -192,8 +192,7 @@
     1.4  });
     1.5  
     1.6  browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
     1.7 -    if (typeof changeInfo.url === 'undefined') {
     1.8 -        // filter out updates which do not change the URL
     1.9 +    if (changeInfo.status !== 'complete') {
    1.10          return;
    1.11      }
    1.12  
    1.13 @@ -202,13 +201,13 @@
    1.14      browser.pageAction.hide(tabId);
    1.15  
    1.16      // inject content script once if the requested URL is a feed preview
    1.17 -    if (tabsFeedPreviews.get(tabId) === changeInfo.url) {
    1.18 +    if (tabsFeedPreviews.get(tabId) === tab.url) {
    1.19          browser.tabs.executeScript(tabId, {
    1.20              file: 'content_scripts/feed-readers.js'
    1.21          });
    1.22          tabsFeedPreviews.delete(tabId);
    1.23      }
    1.24 -});
    1.25 +}, {properties: ["status"]});
    1.26  
    1.27  browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
    1.28      tabsFeeds.delete(tabId);