2013-02-26 189 views
1

我想要獲取Firefox擴展中的頁面大小。 之前,我用這個代碼:獲取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

openCacheEntry從主線程調用時失敗,請使用asyncOpenCacheEntry