Skip to content

Commit

Permalink
update background.js
Browse files Browse the repository at this point in the history
  • Loading branch information
RootUp authored Oct 17, 2024
1 parent 035c68d commit 80dfcd1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions SmuggleShield/background.js
Original file line number Diff line number Diff line change
@@ -85,13 +85,12 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.warn(request.message);
break;
case "analyzeURL":
const cachedResult = urlCache.get(request.url);
if (cachedResult && (Date.now() - cachedResult.timestamp < config.cacheDurationMs)) {
sendResponse({isSuspicious: cachedResult.isSuspicious});
const result = memoizedAnalyzeURL(request.url);
if (Date.now() - result.timestamp < config.cacheDurationMs) {
sendResponse({isSuspicious: result.isSuspicious});
} else {
const isSuspicious = checkSuspiciousURL(request.url);
urlCache.set(request.url, {isSuspicious, timestamp: Date.now()});
sendResponse({isSuspicious});
const newResult = memoizedAnalyzeURL(request.url);
sendResponse({isSuspicious: newResult.isSuspicious});
}
return true;
case "exportLogs":
@@ -147,3 +146,8 @@ chrome.webRequest.onHeadersReceived.addListener(
{urls: ["<all_urls>"]},
["responseHeaders"]
);

const memoizedAnalyzeURL = memoize((url) => {
const isSuspicious = checkSuspiciousURL(url);
return {isSuspicious, timestamp: Date.now()};
}, (url) => url);

0 comments on commit 80dfcd1

Please sign in to comment.