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:
- 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?
- 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!