Get page size in extension for Firefox

1

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?

firefox
xpcom
asked on Stack Overflow Feb 26, 2013 by tryasko • edited Feb 26, 2013 by tryasko

1 Answer

0

openCacheEntry fails when called from the main thread, use asyncOpenCacheEntry

answered on Stack Overflow Feb 26, 2013 by paa

User contributions licensed under CC BY-SA 3.0