1

我想在我的 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);

如何解决这个问题呢?

4

1 回答 1

0

openCacheEntry从主线程调用时失败,请使用asyncOpenCacheEntry

于 2013-02-26T21:26:02.433 回答