Get localStorage from within extension without loading a page

核能气质少年 提交于 2019-12-22 14:42:36

问题


I know how to get the localStorage from any open wep page by using content scripts. So I'm basically able to open a new tab with my own web page and read the storage data with a content script and message it to the background page.

But now I'd like to do this without loading an external page every time. Is there a way to access the localStorage of a page directly from within the extension? Maybe some query to chrome directly.


回答1:


I don't see any API for that.

Your options are:

  • Make a native messaging host application that would read database files directly from Local Storage directory in the browser user profile. An example: What's the best way to read Sqlite3 directly in Browser using Javascript?

  • Put the other page into an iframe: Is it possible to use HTML5 local storage to share data between pages from different sites?

P.S. "Ironic side note" quoted from Cross-domain localStorage article by Nicholas C. Zakas.

Who knew cross-domain client-side data storage would be useful? Actually, the WHAT-WG did. In the first draft of the Web Storage specification (at that time, part of HTML5), there was an object called globalStorage that allowed you to specify which domains could access certain data. [...] The globalStorage interface was implemented in Firefox 2 prematurely as the specification was still evolving. Due to security concerns, globalStorage was removed from the spec and replaced with the origin-specific localStorage.



来源:https://stackoverflow.com/questions/33550243/get-localstorage-from-within-extension-without-loading-a-page

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