Fix P2/P3 review findings: DNR redirect format, runtime type guard, cache test setup
This commit is contained in:
@@ -25,7 +25,7 @@ chrome.runtime.onInstalled.addListener(async () => {
|
||||
chrome.declarativeNetRequest.onRuleMatchedDebug.addListener((details) => {
|
||||
chrome.storage.local.get('blockedRequests').then((data) => {
|
||||
const blocked = data.blockedRequests || [];
|
||||
blocked.push({ ruleId: details.ruleId, url: details.requestUrl, timestamp: Date.now() });
|
||||
blocked.push({ ruleId: details.rule?.ruleId || 0, url: details.request?.url || '', timestamp: Date.now() });
|
||||
if (blocked.length > 100) blocked.shift();
|
||||
chrome.storage.local.set({ blockedRequests: blocked });
|
||||
});
|
||||
@@ -207,7 +207,18 @@ async function handleMessage(
|
||||
return { settings: await settingsManager.update(message.payload as Partial<ExtensionSettings>) };
|
||||
|
||||
case MessageType.REPORT_PHISHING: {
|
||||
const report = message.payload as PhishingReport;
|
||||
const payload = message.payload as Record<string, unknown> | undefined;
|
||||
if (!payload || typeof payload.url !== 'string' || typeof payload.pageTitle !== 'string') {
|
||||
return { success: false, error: 'Missing url or pageTitle' };
|
||||
}
|
||||
const report: PhishingReport = {
|
||||
url: payload.url,
|
||||
pageTitle: payload.pageTitle,
|
||||
tabId: (payload.tabId as number) || 0,
|
||||
timestamp: (payload.timestamp as number) || Date.now(),
|
||||
reason: (payload.reason as string) || 'Manual report',
|
||||
heuristics: (payload.heuristics as Record<string, unknown>) || {},
|
||||
};
|
||||
const success = await shieldApiClient.submitPhishingReport(report);
|
||||
return { success };
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class UrlCache {
|
||||
}
|
||||
|
||||
async loadFromStorage(): Promise<void> {
|
||||
const data = await chrome.storage.local.get('urlCache');
|
||||
const data = await chrome.storage.local.get('urlCache') as { urlCache: Record<string, { result: UrlCheckResult; expiresAt: number }> };
|
||||
if (data.urlCache) {
|
||||
const now = Date.now();
|
||||
for (const [key, entry] of Object.entries(data.urlCache)) {
|
||||
|
||||
Reference in New Issue
Block a user