storage-helpers.js (1666B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // This file assumes head.js is loaded in the global scope. 5 /* import-globals-from head.js */ 6 7 /* exported openTabAndSetupStorage, clearStorage */ 8 9 "use strict"; 10 11 /** 12 * This generator function opens the given url in a new tab, then sets up the 13 * page by waiting for all cookies, indexedDB items etc. to be created. 14 * 15 * @param url {String} The url to be opened in the new tab 16 * 17 * @return {Promise} A promise that resolves after storage inspector is ready 18 */ 19 async function openTabAndSetupStorage(url) { 20 await addTab(url); 21 22 // Setup the async storages in main window and for all its iframes 23 const browsingContexts = 24 gBrowser.selectedBrowser.browsingContext.getAllBrowsingContextsInSubtree(); 25 for (const browsingContext of browsingContexts) { 26 await SpecialPowers.spawn(browsingContext, [], async function () { 27 if (content.wrappedJSObject.setup) { 28 await content.wrappedJSObject.setup(); 29 } 30 }); 31 } 32 33 // selected tab is set in addTab 34 const commands = await CommandsFactory.forTab(gBrowser.selectedTab); 35 await commands.targetCommand.startListening(); 36 const target = commands.targetCommand.targetFront; 37 return { commands, target }; 38 } 39 40 async function clearStorage() { 41 const browsingContexts = 42 gBrowser.selectedBrowser.browsingContext.getAllBrowsingContextsInSubtree(); 43 for (const browsingContext of browsingContexts) { 44 await SpecialPowers.spawn(browsingContext, [], async function () { 45 if (content.wrappedJSObject.clear) { 46 await content.wrappedJSObject.clear(); 47 } 48 }); 49 } 50 }