jusio / storage-area-explorer

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

add ability for indexeddb #22

Open boggen opened 7 years ago

boggen commented 7 years ago

web-sql from understanding is getting dismantled some time in the future leaving indexeddb.

the default "chrome -> developer tools -> application" for indexeddb is rather poor.

jusio commented 7 years ago

Been wanting to do this for a long time, but indexeddb api makes it very hard to create an effective explorer. I promise to look into this if Observer API will make it into IndexedDB spec

tophf commented 5 years ago

@jusio, what about chrome.debugger API? The only drawback is that a warning is displayed at the top of the page about it being debugged by an extension so I guess it should be performed only after the user has clicked on some button in the extension UI.

Here's PoC:

(async () => {
  const {tabId} = chrome.devtools.inspectedWindow;
  const {url} = await browser.tabs.get(tabId);
  const securityOrigin = new URL(url).origin;

  const IDB = new Proxy({}, {
    get: (_, cmd) =>
      params => new Promise((resolve, reject) => {
        params = params && Object.assign({securityOrigin}, params);
        chrome.debugger.sendCommand({tabId}, 'IndexedDB.' + cmd, params, response => {
          if (!chrome.runtime.lastError) {
            resolve(response);
          } else {
            reject(chrome.runtime.lastError);
          }
        });
      })
  });

  await browser.debugger.attach({tabId}, '1.3');

  // to receive modification events
  await IDB.enable();

  const dbs = new Map();

  for (const databaseName of (await IDB.requestDatabaseNames({})).databaseNames) {
    const db = (await IDB.requestDatabase({databaseName})).databaseWithObjectStores;
    dbs.set(db.name, db);

    for (const store of db.objectStores) {
      store.data = await IDB.requestData({
        databaseName,
        indexName: '',
        objectStoreName: store.name,
        pageSize: 100,
        skipCount: 0
      });
    }
  }

  console.log(dbs);
})();

image

jusio commented 5 years ago

I think this is a good idea, which can be theoretically even better than official apis I was planning on using. Unfortunately I have pretty much abandoned Storage Area Explorer lately, so I can't promise if I will be ever able to implement this :(

tophf commented 5 years ago

Well, maybe add a "Help wanted" or "Pullrequests welcome" label to all the feature requests that you think are useful?

jusio commented 5 years ago

Ok, I'll do that over the weekend. I just never thought that somebody would be willing to do anything on this project:D

tophf commented 4 years ago

Chrome 71 added databases Promise, see MDN

const promise = indexedDB.databases()
promise.then(databases => {
  console.log(databases)
})