Skip to content

Commit 59c28e5

Browse files
committed
Bug fix: cache flag was not always correct
1 parent d02fedc commit 59c28e5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

bg.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var is_cache_disabled = false;
1212
// map of tabid -> requests
1313
var netList = {};
1414

15+
// list of requestIds that were cached
16+
var cachedList = {};
1517

1618
//--------------------------------------------------------------------------
1719
// chrome events
@@ -91,10 +93,12 @@ function tab_updated(tabid) {
9193

9294
// remove all network requests of this tab
9395
function clear_tab_data(tabid) {
94-
deb("cleared "+tabid);
96+
// deb("cleared "+tabid);
9597

9698
delete netList[tabid+"list"];
9799
delete netList[tabid];
100+
101+
cachedList = {};
98102
}
99103

100104
// add or get a single request item from list
@@ -121,6 +125,10 @@ function add_file(tabid, reqid, url, code, from_cache, type) {
121125

122126
var urlpart = url.split("/").pop();
123127

128+
// is request cached even though from_cache = false!?
129+
if (cachedList[reqid])
130+
from_cache = true;
131+
124132
// deb("add", reqid, urlpart, "cached:", from_cache);
125133

126134
var obj = get_item(tabid, reqid);
@@ -294,6 +302,9 @@ function onNetworkEvent(debuggeeId, message, params) {
294302
var resp = params.response;
295303
var reqid = params.requestId;
296304
// resp.encodedDataLength -1!
305+
306+
// resp.fromDiskCache may be false even though came from cache!
307+
// A Chrome bug? Double check with Network.requestServedFromCache
297308
add_file(tabid, reqid, resp.url, resp.status, resp.fromDiskCache,
298309
params.type);
299310

@@ -316,6 +327,12 @@ function onNetworkEvent(debuggeeId, message, params) {
316327
});
317328
}*/
318329

330+
} else if (message == "Network.requestServedFromCache") {
331+
// fired if request ended up loading from cache.
332+
//deb("fromcache" + params.requestId);
333+
334+
cachedList[params.requestId] = 1;
335+
319336
} else if (message == "Network.dataReceived") {
320337
// console.debug("data", params);
321338

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Page Size Inspector",
33
"short_name": "Page Size Inspector",
44
"description": "Reports page size, cache usage, network requests, load time.",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"permissions": [
77
"<all_urls>", "debugger", "webNavigation", "clipboardWrite"
88
],

0 commit comments

Comments
 (0)