我想在我的 Firefox 扩展中获取页面的大小。之前,我使用了这段代码:
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;
}
但是更新浏览器后,我得到了错误:
NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsICacheSession.openCacheEntry]
排队:
cacheEntryDescriptor = httpCacheSession.openCacheEntry(content.document.location.toString().replace(/#.*$/, ""), Components.interfaces.nsICache.ACCESS_READ, false);
如何解决这个问题呢?