From a8f35f70d275069f629f3747e6cd12bbebc4e65d Mon Sep 17 00:00:00 2001 From: Shaoor Munir Date: Tue, 28 May 2024 01:20:07 -0700 Subject: [PATCH 1/2] added a custom metric to store the number of localstorage and sessionStorage accesses by each response body --- dist/local_storage_api_calls.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 dist/local_storage_api_calls.js diff --git a/dist/local_storage_api_calls.js b/dist/local_storage_api_calls.js new file mode 100644 index 0000000..5b5cd54 --- /dev/null +++ b/dist/local_storage_api_calls.js @@ -0,0 +1,18 @@ +const response_bodies = $WPT_BODIES; +const storagePattern = /\b(localStorage|sessionStorage)\b/g; + +return Object.fromEntries(response_bodies.filter(har => { + return storagePattern.test(har.response_body); +}).map(har => { + const matches = Array.from(har.response_body.matchAll(storagePattern)); + const counts = matches.reduce((acc, match) => { + const key = match[0]; + if (!acc[key]) { + acc[key] = 0; + } + acc[key]++; + return acc; + }, { numLocalStorage: 0, numSessionStorage: 0 }); + + return [har.url, { numLocalStorage: counts.localStorage || 0, numSessionStorage: counts.sessionStorage || 0 }]; +})); \ No newline at end of file From 265c5a7233afd9871f520616e2e581953c8bf493 Mon Sep 17 00:00:00 2001 From: Shaoor Munir Date: Fri, 7 Jun 2024 00:05:34 -0700 Subject: [PATCH 2/2] updated to only account for API calls and not for checking the permissions and object assignments --- dist/local_storage_api_calls.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/dist/local_storage_api_calls.js b/dist/local_storage_api_calls.js index 5b5cd54..8a209cf 100644 --- a/dist/local_storage_api_calls.js +++ b/dist/local_storage_api_calls.js @@ -1,18 +1,23 @@ const response_bodies = $WPT_BODIES; -const storagePattern = /\b(localStorage|sessionStorage)\b/g; +const storagePattern = /\b(localStorage|sessionStorage)\b(\.\w+)?/g; return Object.fromEntries(response_bodies.filter(har => { return storagePattern.test(har.response_body); }).map(har => { const matches = Array.from(har.response_body.matchAll(storagePattern)); const counts = matches.reduce((acc, match) => { - const key = match[0]; - if (!acc[key]) { - acc[key] = 0; + const key = match[1]; + const access = match[2]; + + if (access && (access.startsWith('.getItem') || access.startsWith('.setItem') || access.startsWith('.removeItem'))) { + if (!acc[key]) { + acc[key] = 0; + } + acc[key]++; } - acc[key]++; + return acc; - }, { numLocalStorage: 0, numSessionStorage: 0 }); + }, { localStorage: 0, sessionStorage: 0 }); return [har.url, { numLocalStorage: counts.localStorage || 0, numSessionStorage: counts.sessionStorage || 0 }]; })); \ No newline at end of file