Fix PII mapping add (plus button) not persisting and not dismissing notification
The plus button handler in the pre-send PII warning had two bugs: 1. It read/wrote mappings directly via the storage bridge (api.storage.local), bypassing the Storage module's encryption layer. When at-rest encryption was enabled, getStorageData returned an encrypted blob instead of an array, causing .push() to throw a TypeError that silently aborted the handler — the mapping was never saved and replaceInInput never ran. 2. Unlike the ignore button which immediately removes the DOM item, the plus button relied on a re-scan at 150ms to dismiss the notification. If replaceInInput didn't stick (e.g. React-controlled inputs), the re-scan found PII again and the notification persisted. Fix: Route mapping creation through the background service worker via a new 'add:mapping' message handler (which uses Storage.addMapping with proper encryption support), and immediately dismiss the notification item from the DOM like the ignore button does. https://claude.ai/code/session_01RfzvB5sHah326acr8Xa7Jn
This commit is contained in:
@@ -138,6 +138,12 @@ const messageHandlers = {
|
|||||||
sendResponse({ mappings });
|
sendResponse({ mappings });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async 'add:mapping'(message, _sender, sendResponse) {
|
||||||
|
const newMapping = await Storage.addMapping(message.mapping);
|
||||||
|
const mappings = await Storage.getMappings();
|
||||||
|
sendResponse({ mapping: newMapping, mappings });
|
||||||
|
},
|
||||||
|
|
||||||
async 'get:settings'(_message, _sender, sendResponse) {
|
async 'get:settings'(_message, _sender, sendResponse) {
|
||||||
const settings = await Storage.getSettings();
|
const settings = await Storage.getSettings();
|
||||||
sendResponse({ settings });
|
sendResponse({ settings });
|
||||||
|
|||||||
+25
-19
@@ -1406,21 +1406,17 @@
|
|||||||
const fake = decodeURIComponent(btn.dataset.fake);
|
const fake = decodeURIComponent(btn.dataset.fake);
|
||||||
const cat = btn.dataset.cat || 'general';
|
const cat = btn.dataset.cat || 'general';
|
||||||
|
|
||||||
// Add to mappings via storage
|
// Immediately dismiss this notification item (same as ignore)
|
||||||
const result = await getStorageData('ss_mappings');
|
btn.closest('.ss-ps-item').remove();
|
||||||
const currentMappings = result || [];
|
if (!preSendWarningEl.querySelector('.ss-ps-item')) {
|
||||||
currentMappings.push({
|
preSendWarningEl.classList.remove('visible');
|
||||||
id: crypto.randomUUID(),
|
}
|
||||||
real, substitute: fake,
|
|
||||||
category: cat,
|
|
||||||
caseSensitive: false,
|
|
||||||
enabled: true,
|
|
||||||
createdAt: Date.now(),
|
|
||||||
});
|
|
||||||
await setStorageData('ss_mappings', currentMappings);
|
|
||||||
|
|
||||||
// Update local mappings so the fetch interceptor uses them immediately
|
// Add to mappings via background script (handles encryption)
|
||||||
mappings = currentMappings;
|
addMappingViaBackground({ real, substitute: fake, category: cat })
|
||||||
|
.then(updatedMappings => {
|
||||||
|
if (updatedMappings.length) mappings = updatedMappings;
|
||||||
|
});
|
||||||
|
|
||||||
// Replace the PII value in the current input right now
|
// Replace the PII value in the current input right now
|
||||||
if (inputEl) {
|
if (inputEl) {
|
||||||
@@ -1429,11 +1425,6 @@
|
|||||||
if (inputScanTimer) clearTimeout(inputScanTimer);
|
if (inputScanTimer) clearTimeout(inputScanTimer);
|
||||||
inputScanTimer = setTimeout(() => scanInputForPII(inputEl), 150);
|
inputScanTimer = setTimeout(() => scanInputForPII(inputEl), 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visual feedback
|
|
||||||
btn.textContent = '\u2714';
|
|
||||||
btn.style.color = '#4ade80';
|
|
||||||
btn.disabled = true;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1493,6 +1484,21 @@
|
|||||||
window.postMessage({ type: 'ss:storage-set', key, value }, '*');
|
window.postMessage({ type: 'ss:storage-set', key, value }, '*');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addMappingViaBackground(mapping) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const id = 'ss-add-' + Math.random();
|
||||||
|
const handler = (event) => {
|
||||||
|
if (event.data?.type === 'ss:add-mapping-result' && event.data.id === id) {
|
||||||
|
window.removeEventListener('message', handler);
|
||||||
|
resolve(event.data.mappings || []);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener('message', handler);
|
||||||
|
window.postMessage({ type: 'ss:add-mapping', mapping, id }, '*');
|
||||||
|
setTimeout(() => { window.removeEventListener('message', handler); resolve([]); }, 2000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Scan input on type and paste
|
// Scan input on type and paste
|
||||||
let inputScanTimer = null;
|
let inputScanTimer = null;
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,26 @@
|
|||||||
if (event.data?.type === 'ss:storage-set') {
|
if (event.data?.type === 'ss:storage-set') {
|
||||||
await api.storage.local.set({ [event.data.key]: event.data.value });
|
await api.storage.local.set({ [event.data.key]: event.data.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.data?.type === 'ss:add-mapping') {
|
||||||
|
try {
|
||||||
|
const response = await api.runtime.sendMessage({
|
||||||
|
type: 'add:mapping',
|
||||||
|
mapping: event.data.mapping,
|
||||||
|
});
|
||||||
|
window.postMessage({
|
||||||
|
type: 'ss:add-mapping-result',
|
||||||
|
id: event.data.id,
|
||||||
|
mappings: response?.mappings || [],
|
||||||
|
}, '*');
|
||||||
|
} catch {
|
||||||
|
window.postMessage({
|
||||||
|
type: 'ss:add-mapping-result',
|
||||||
|
id: event.data.id,
|
||||||
|
mappings: [],
|
||||||
|
}, '*');
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user