Forem Creators and Builders 🌱

Discussion on: Is the browser extension working for anyone?

Collapse
 
link2twenty profile image
Andrew Bone • Edited

Got it working.

I went to here
forem.com/valid_forems.json
Then suddenly it appeared on all my sites

EDIT: This was a red herring the bar appeared after the data was loaded, it just so happened I was on that page when it did.

hacker arms

Collapse
 
ben profile image
Ben Halpern

So it took you visiting that endpoint manually before it worked? πŸ€”

Collapse
 
citizen428 profile image
Michael Kohl

That worked for me too in Chrome.

Collapse
 
ben profile image
Ben Halpern

Then suddenly it appeared on all my sites

And is that all your sites like alll your sites or just Forems?

Thread Thread
 
link2twenty profile image
Andrew Bone

Sorry just forem sites

Collapse
 
link2twenty profile image
Andrew Bone • Edited

Yes I went there manually, when I started looking though the code and saw the bars existed in Dev and Forem suddenly.

Collapse
 
link2twenty profile image
Andrew Bone

Did someone ask for an error?

Error handling response: TypeError: Cannot read property 'map' of undefined
    at myOrigins (chrome-extension://cobicbhlbogbkdcmgdhejghphaiofodb/content/content.js:204:19)
    at chrome-extension://cobicbhlbogbkdcmgdhejghphaiofodb/content/content.js:14:5
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
link2twenty profile image
Andrew Bone • Edited

I think I see it

chrome.storage.sync.get(['subscribedForems', 'allforems'], function (result) {
  const myForems = result.subscribedForems;
  const allForems = result.allforems;
  if (!myForems) {
    chrome.storage.sync.set({ subscribedForems: [] }); // Create empty array if not initialized.
  }
  if (!allForems) {
    chrome.storage.sync.set({ allforems: [] }); // Create empty array if not initialized.
  }
  // myOrigins(null) will break map on line 203
  if (
    myOrigins(myForems).includes(currentOrigin) ||
    validOrigins(allForems).includes(currentOrigin) ||
    currentOrigin === 'https://www.forem.com'
  ) {
    loadForemHTML(result.subscribedForems);
    document.addEventListener('add', handleAdd, false);
    document.addEventListener('remove', handleRemove, false);
    document.addEventListener('reorder', handleReorder, false);
  }
Enter fullscreen mode Exit fullscreen mode

This would remove the error though I've not thought the logic through yet

function myOrigins(myForems) {
  if(!myForems) return;
  return myForems.map(function (f) {
    return f.homePageUrl;
  });
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
link2twenty profile image
Andrew Bone

Another fix.

chrome.storage.sync.get(['subscribedForems', 'allforems'], function (result) {
  const myForems = result.subscribedForems ? result.subscribedForems : [];
  const allForems = result.allforems ? result.allforems : [];
  if (!result.subscribedForems) {
    chrome.storage.sync.set({ subscribedForems: [] }); // Create empty array if not initialized.
  }
  if (!result.allforems) {
    chrome.storage.sync.set({ allforems: [] }); // Create empty array if not initialized.
  }
  if (
    myOrigins(myForems).includes(currentOrigin) ||
    validOrigins(allForems).includes(currentOrigin) ||
    currentOrigin === 'https://www.forem.com'
  ) {
    loadForemHTML(result.subscribedForems);
    document.addEventListener('add', handleAdd, false);
    document.addEventListener('remove', handleRemove, false);
    document.addEventListener('reorder', handleReorder, false);
  }
Enter fullscreen mode Exit fullscreen mode