我想在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);
如何解决这个问题?
答案 0 :(得分:0)
openCacheEntry
失败,请使用asyncOpenCacheEntry