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 #220 from Osmose/toolbar-cleared-again
Browse files Browse the repository at this point in the history
Fix #192: Resend product data after a delay to reset toolbar icon.
  • Loading branch information
Osmose authored Oct 30, 2018
2 parents 871cca7 + 75c6c17 commit 0190c72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
15 changes: 0 additions & 15 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,6 @@ import {registerEvents, handleWidgetRemoved} from 'commerce/telemetry/extension'
['blocking', 'responseHeaders'],
);

// Workaround for bug 1493470: Resend product info when subframe loads
// accidentally clear the browser action URL.
// 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: [
'*://*.walmart.com/*',
'*://*.homedepot.com/*',
],
types: ['sub_frame'],
});

// Make sure the store is loaded before we check prices.
await store.dispatch(loadStateFromStorage());

Expand Down
24 changes: 15 additions & 9 deletions src/extraction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ async function attemptExtraction() {
// If we're in an iframe, don't bother extracting a product EXCEPT if we were
// started by the background script for a price check.
const isInIframe = window !== window.top;
const isBackgroundUpdate = window.top.location.href.startsWith(
browser.runtime.getURL('/'), // URL is unique per-install / hard to forge
);
let isBackgroundUpdate = false;
try {
isBackgroundUpdate = window.top.location.href.startsWith(
browser.runtime.getURL('/'), // URL is unique per-install / hard to forge
);
} catch (err) {
// Non-background updates may throw a cross-origin error
}

if (isInIframe && !isBackgroundUpdate) {
return;
}
Expand Down Expand Up @@ -103,10 +109,10 @@ async function attemptExtraction() {
extractedProduct = await attemptExtraction();
});

// Re-send the extracted product to the background script if requested
browser.runtime.onMessage.addListener(async (message) => {
if (message.type === 'resend-product' && extractedProduct) {
await sendProductToBackground(extractedProduct);
}
});
// 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);
}());

0 comments on commit 0190c72

Please sign in to comment.