I want to get the size of the page in my extension for Firefox. Before, I used this code:
var pageSize = null,
cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService),
httpCacheSession = cacheService.createSession("HTTP", 0, true),
cacheEntryDescriptor;
httpCacheSession.doomEntriesIfExpired = false;
cacheEntryDescriptor = httpCacheSession.openCacheEntry(content.document.location.toString().replace(/#.*$/, ""), Components.interfaces.nsICache.ACCESS_READ, false);
if ( cacheEntryDescriptor ) {
pageSize = Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100;
}
But after update browser, I get the error:
NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsICacheSession.openCacheEntry]
In line:
cacheEntryDescriptor = httpCacheSession.openCacheEntry(content.document.location.toString().replace(/#.*$/, ""), Components.interfaces.nsICache.ACCESS_READ, false);
How to solve this problem?
openCacheEntry
fails when called from the main thread, use asyncOpenCacheEntry
User contributions licensed under CC BY-SA 3.0