0

I have been struggling with following issue for a couple of days:

I would like to write to the local storage of the parent tab instead of the popup.

example screenshot

I tried many different approaches found on internet but when it comes to writing to the local storage value is always set to the local storage of the popup and not the parent tab.

Here is my (bad) piece of code:

document.addEventListener('DOMContentLoaded', function () {
    var checkPageButton = document.getElementById('clickIt')
    checkPageButton.addEventListener('click', function () {

        chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT},
            function (tabs) {
                localStorage.setItem('bgcolor', 'red');
            })
    })
})

I am very new to all this and above example is just the latest of so many things I tried.

Thanks a lot in advance for your help!

mmethod
  • 1
  • 1
  • Here is a description of your problem: https://stackoverflow.com/a/39322537/1145635 – Anton Mitsev Nov 04 '19 at 11:17
  • 1
    The popup is a separate page not related to the tab, and the tab is not in parent-child relation with the popup. You need to [declare or run](/a/4532567) a separate [content script](https://developer.chrome.com/extensions/content_scripts) to access the web page and its localStorage. – wOxxOm Nov 04 '19 at 11:32

0 Answers0