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

Commit

Permalink
Incorporate Osmose's feedback
Browse files Browse the repository at this point in the history
Also added the cookie pref from Issue #183, so background updates occur in Nightly.
  • Loading branch information
biancadanforth committed Oct 22, 2018
1 parent 707b078 commit 4b0060a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/background/price_updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ export async function updatePrices() {
const products = getAllProducts(state);
const now = new Date();
const priceCheckInterval = await config.get('priceCheckInterval');

const delay = await config.get('iframeTimeout');
for (const product of products) {
const priceEntry = getLatestPriceForProduct(state, product.id);
if (now - priceEntry.date > priceCheckInterval) {
fetchLatestPrice(product);
// Don't load another iframe until the previous one has been removed.
await wait(delay); // eslint-disable-line no-await-in-loop
// Cleanup previous product's iframe whether it is finished or not.
document.getElementById(product.id).remove();
await fetchLatestPrice(product, delay); // eslint-disable-line no-await-in-loop
}
}
}
Expand All @@ -61,7 +56,7 @@ export async function updatePrices() {
* to updateProductWithExtracted.
* @param {Product} product
*/
async function fetchLatestPrice(product) {
async function fetchLatestPrice(product, delay) {
// Do nothing if there's already a fetch in progress.
if (document.getElementById(product.id)) {
return;
Expand All @@ -77,6 +72,11 @@ async function fetchLatestPrice(product) {
iframe.height = 950;
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms');
document.body.appendChild(iframe);

// Don't load another iframe until the previous one has been removed.
await wait(delay);
// Cleanup product's iframe whether it is finished or not.
document.getElementById(product.id).remove();
}

/**
Expand Down
1 change: 1 addition & 0 deletions web-ext-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
'[email protected]=30000',
'[email protected]=30000',
'[email protected]=10000',
'network.cookie.cookieBehavior=3', // See Issue #183
],
startUrl: [
'http://www.mkelly.me/fake-product-page/',
Expand Down

0 comments on commit 4b0060a

Please sign in to comment.