fix: restore working injector.js + add missing get:decrypted-config handler

Restored injector.js from v2.0.14 (commit 9a11896) which:
- Requests decrypted config from background via get:decrypted-config
  message instead of passing empty arrays when data is encrypted
- Handles the identity.profiles merge correctly for background responses
- Passes ss_settings directly (not checking _ssLocalEncrypted which
  caused settings loss)

Added missing get:decrypted-config message handler to service-worker.js
which returns decrypted mappings, identity, and settings via Storage
module.

https://claude.ai/code/session_01KF4i7Ra7zCEDskxDBaNtcT
This commit is contained in:
Claude
2026-03-29 18:06:51 +00:00
parent 2a1bd88dd6
commit b622d5abd4
6 changed files with 54 additions and 21 deletions
+39 -17
View File
@@ -57,18 +57,45 @@
// Load mappings and settings, then inject into page
async function init() {
let mappings, identity, settings;
const result = await api.storage.local.get(['ss_mappings', 'ss_identity', 'ss_settings']);
const settings = result.ss_settings || { enabled: true };
const isEncrypted = result.ss_mappings?._ssLocalEncrypted ||
result.ss_identity?._ssLocalEncrypted;
// Check if data is encrypted (locked) — pass empty config
// The background will send decrypted data via vault:unlocked when ready
const isLocked = result.ss_mappings?._ssLocalEncrypted ||
result.ss_identity?._ssLocalEncrypted;
const mappings = isLocked ? [] : (result.ss_mappings || []);
const identityData = isLocked ? {} : (result.ss_identity || {});
if (isEncrypted) {
// Data is encrypted — ask the background script for decrypted config.
// The background has access to the Storage module which can decrypt.
try {
const response = await api.runtime.sendMessage({ type: 'get:decrypted-config' });
if (response?.mappings) {
mappings = response.mappings;
identity = response.identity || {};
settings = response.settings || { enabled: true };
} else {
// Background couldn't decrypt (locked) — inject with empty config
// and wait for vault:unlocked message later
mappings = [];
identity = {};
settings = result.ss_settings || { enabled: true };
}
} catch {
mappings = [];
identity = {};
settings = result.ss_settings || { enabled: true };
}
} else {
// Data is plaintext — read directly
mappings = result.ss_mappings || [];
const identityData = result.ss_identity || {};
identity = mergeProfiles(identityData);
settings = result.ss_settings || { enabled: true };
}
// Merge active profiles into a flat identity object for the content script
const identity = mergeProfiles(identityData);
// Ensure identity is merged if it came from background
if (identity.profiles) {
identity = mergeProfiles(identity);
}
// Inject the main interception script into the page's world
const script = document.createElement('script');
@@ -91,8 +118,6 @@
// Also log directly from the injector (content script world)
// in case the background worker is asleep
const replacements = event.data.replacements || [];
const settingsResult = await api.storage.local.get('ss_settings');
const maxLog = settingsResult.ss_settings?.maxLogEntries || 100;
for (const r of replacements) {
const log = (await api.storage.local.get('ss_activity_log')).ss_activity_log || [];
log.unshift({
@@ -106,8 +131,8 @@
pattern: r.pattern || '',
url: location.href,
});
// Trim to user-configured max
if (log.length > maxLog) log.length = maxLog;
// Trim
if (log.length > 200) log.length = 200;
await api.storage.local.set({ ss_activity_log: log });
}
}
@@ -127,10 +152,7 @@
const val = changes.ss_identity.newValue;
if (!val?._ssLocalEncrypted) msg.identity = mergeProfiles(val);
}
if (changes.ss_settings) {
const val = changes.ss_settings.newValue;
if (!val?._ssLocalEncrypted) msg.settings = val;
}
if (changes.ss_settings) msg.settings = changes.ss_settings.newValue;
// Only post if we have something meaningful to send
if (msg.mappings || msg.identity || msg.settings) {