0

I'm creating a Chrome extension similar to the Pinterest Save button, which attaches a pin to every image on a page to easily save to a board.

My question is a two part question:

  1. Currently all my logic happens in the content script. To my knowledge, the content script gets injected on page refresh so with single page apps, it doesn't detect that the page changed if you click some routes.

I was thinking of keeping a cache of the last visited URL and comparing that. However, this would need to be automatically updated in the background so is there a way to check using Javascript or the Chrome API in the background page?

  1. If I implement this cache, I would want the state to persist on a per-tab basis and not globally. I see that localStorage and chrome.storage are basically the two solutions for keeping state with extensions.

Both methods are global storage to my understanding so the first solution that comes to mind is keeping a map of tabId to last URL visited in either storage method. I was wondering if there was an easier method to keep the storage scoped by tab.

Thank you!

cheng
  • 1,264
  • 2
  • 18
  • 41
  • Specifically, you want both the general answers and the answer: [Is there a JavaScript/jQuery DOM change listener?](https://stackoverflow.com/a/39508954), which provides the specific additional methods available in a Chrome extension, including those available in the background context. – Makyen Jul 27 '17 at 02:02
  • Related: [window.localStorage vs chrome.storage.local](https://stackoverflow.com/q/24279495) – Makyen Jul 27 '17 at 02:09
  • 1
    Avoid asking multiple questions in a single post - it makes it too broad to answer. Read up on the answer Makyen linked and try it out first. – Samuel Liew Jul 27 '17 at 02:14

0 Answers0