Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #247 from Osmose/toolbar-icon
Browse files Browse the repository at this point in the history
Fix #237, fix #242: Re-add toolbar icon reset workaround.
  • Loading branch information
Osmose authored Nov 7, 2018
2 parents 538268a + 578eb0c commit 5589d8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ import {registerEvents, handleWidgetRemoved} from 'commerce/telemetry/extension'
['blocking', 'responseHeaders'],
);

// Workaround for bug 1493470: Resend product info to the background
// script in case subframe loads clear the toolbar icon.
// TODO(osmose): Remove once Firefox 64 hits the release channel.
browser.webRequest.onCompleted.addListener(
(details) => {
if (details.tabId) {
browser.tabs.sendMessage(details.tabId, {type: 'resend-product'});
}
},
{urls: ['https://*/*', 'http://*/*'], types: ['sub_frame']},
);

// Set up listener to trigger re-extraction when a page changes the URL via
// the history API.
browser.webNavigation.onHistoryStateUpdated.addListener(
Expand Down
16 changes: 8 additions & 8 deletions src/extraction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ function extractProduct() {
}

async function sendProductToBackground(extractedProduct) {
if (!extractedProduct) {
return null;
}

return browser.runtime.sendMessage({
type: 'extracted-product',
extractedProduct: {
Expand Down Expand Up @@ -147,18 +151,14 @@ async function attemptExtraction() {
extractedProduct = await attemptExtraction();
});

// Messy workaround for bug 1493470: Resend product info to the background
// script twice in case subframe loads clear the toolbar icon.
// TODO(osmose): Remove once Firefox 64 hits the release channel
const resend = () => sendProductToBackground(extractedProduct);
setTimeout(resend, 5000);
setTimeout(resend, 10000);

browser.runtime.onMessage.addListener(async (message) => {
// Re-extract the product if requested
if (message.type === 'reextract-product') {
// Re-extract the product if requested
extractedProduct = await attemptExtraction();
await sendProductToBackground(extractedProduct);
} else if (message.type === 'resend-product') {
// Re-send the already-extracted product if requested
await sendProductToBackground(extractedProduct);
}
});
}());

0 comments on commit 5589d8c

Please sign in to comment.