How do I view the storage of a Chrome Extension I've installed?

人走茶凉 提交于 2019-12-02 15:43:32

There is a very helpful extension to work with both localStorage and chrome.storage that I recently discovered, that works as a Dev Tools panel.

Storage Area Explorer

I did not write this, but it was suggested by the author on some other SO question.

I will proceed to amalgamate the existing knowledge present in several answers, into a simple and comprehensive one. If you vote up this one, please do the same with the ones from @mwkwok and @chaohuang.

It is true that stuff saved using chrome.storage does not show up in developer tools, there you can only see stuff saved using regular localStorage API. Do this:

  1. Open your extension's background page by going to chrome://extensions/ ("Developer mode" needs to be checked to see background pages)

  2. Go to the Console tab and type this:

chrome.storage.local.get(function(result){console.log(result)})

This will spit the whole storage as a JSON object into the console.

You're right that chrome.storage does not show up in developer tools. The only way I've found to view all of it is by putting this into console:

chrome.storage.local.get(function(result){console.log(result)})

This will spit the JSON object into console.

Open the Chrome Devtool by clicking on the background page of an extension in Chrome://extensions/ (Developer mode needs to be checked to see background pages), then in resource panel you can see the local storage on the left.

This was actually two questions!

  1. How do I view localStorage of a Chrome Extension I've installed?

Open the Chrome Devtool by clicking on the background page of an extension in Chrome://extensions/ (Developer mode needs to be checked to see background pages), then in resource panel you can see the local storage on the left. (by chaohuang and Kil)

  1. How do I view chrome.storage of a Chrome Extension I've installed?

In the same console of the background page:

  • For storage.local (by mwkwok)

chrome.storage.local.get(function(result){console.log(result)})

  • For storage.sync

chrome.storage.sync.get(function(result){console.log(result)})

I didn't get any results using the provided code typed into console. But this code worked when put into the console.

chrome.storage.sync.get(null, function (data) { console.info(data) });

The difference here is that we pass a null value which will return all content in the storage. To back this up, and for additional reading, check out the official chrome page on this API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!