Reading localStorage in another context script expansion Chrome



  • Hello.
    To read localStorage data from context_script_1.js in another context_script_2.js

    file: context_script_1.js

    window.localStorage.tabs_1_data = 'данные';
    

    file: context_script_2.js

    alert( window.localStorage.tabs_1_data );
    


  • You can't read it straight, but you can say that:

    context_script_1.js

    chrome.runtime.sendMessage({
        from:'script_1',
        data:window.localStorage
    });
    

    context_script_2.js

    chrome.runtime.onMessage.addListener(function(request,sender,callback){
        if(request.from == 'script_1'){
            alert(request.data);
        }
    });
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2