0

I'm using following code to retrieve all localstorage keys:

var myKeys=Object.keys(localStorage);

But this gives me only localstorage of main frame. How to get localstorage keys of frames? I'm using this code in popup.html in Chrome Extension.

Micheal Toru
  • 422
  • 4
  • 28
  • If source of frames is different origin you can't access them. If they are same origin as page then all will be in array you create above. Not much detail provided here – charlietfl Jun 30 '18 at 11:19
  • 2
    This is very simple. You need to declare a [content script](https://developer.chrome.com/extensions/content_scripts) that runs in `all_frames` + [messaging](https://developer.chrome.com/extensions/messaging). Or you can inject this content script via chrome.tabs.executeScript with `allFrames: true` and `code: 'Object.keys(localStorage)'` parameters which will give you the array for all frames in the callback's parameter. – wOxxOm Jun 30 '18 at 11:21
  • @charlietfl, this is a chrome extension so cross-origin stuff is not an issue. – wOxxOm Jun 30 '18 at 11:25
  • Thank you very much! I tried to do this with the solution: https://stackoverflow.com/questions/3937000/chrome-extension-accessing-localstorage-in-content-script but it didn't work. i'm not sure, if the api still exists. Do you have a minimal example to parse to message from content script to popup or panel ? – Micheal Toru Jun 30 '18 at 12:55
  • That answers are irrelevant here as you need the exact opposite. Make sure you understand the architecture of chrome extensions described in the overview, it's really simple. – wOxxOm Jul 01 '18 at 04:49

0 Answers0