jusio / storage-area-explorer

Extension for Chrome with allows to inspect storage area of Chrome Packages Apps
Other
174 stars 33 forks source link

How can you get the inspected extension's chrome.storage? #34

Closed kangzoel closed 4 years ago

kangzoel commented 4 years ago

Can you tell me how did you get the chrome.storage of another extension? I am not an angular developer, so I can barely understand the code. I've tried this code on my own devtools extension:

chrome.devtools.inspectedWindow.eval(
  `
    inspect(chrome.storage)
  `,
  function (result, isException) {
    console.log(result);
  }
);

but it returns only the empty objects of set and get. Not the function itself. image What should I learn to inspect the target extension's storage? I am sorry for asking this question here. I can't find any other resource besides your code.

jusio commented 4 years ago

That code is overly complicated unfortunately. Unfortunately, you can't just get a reference to storageArea object from one extension into another, since they run in different processes. So instead I use devtools.inspectedWindow.eval to inject this script: https://github.com/jusio/storage-area-explorer/blob/master/app/injects/extension-page-inject.js into the target extension. This code runs inside inspected extension context, so the only way it can communicate with my extension, is by using chrome ports API. E.g. I just open a port from inspected extension into my own extension, and in order to get or send anything from inspected extension, I just send message to it via port, and sends responses back via same port. Hope this helps.

kangzoel commented 4 years ago

Thank you so much for the explanation 😁