获取Firefox的扩展页面大小

时间:2013-02-26 17:23:04

标签: firefox xpcom

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

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

从主线程调用时,

openCacheEntry失败,请使用asyncOpenCacheEntry