问题
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 Storagedirectory 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
globalStoragethat 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