Merge pull request #57 from outis1one/claude/read-repo-YMu21

fix: config race condition — use persistent JSON element, bump 0.9.20
This commit is contained in:
Outis
2026-03-29 14:25:47 -04:00
committed by GitHub
6 changed files with 16 additions and 7 deletions
+3 -2
View File
@@ -26,12 +26,13 @@
let settings = { enabled: true, revealMode: false, showHighlights: false };
try {
const configEl = document.querySelector('script[data-ss-config]');
const configEl = document.getElementById('ss-config-data');
if (configEl) {
const config = JSON.parse(configEl.getAttribute('data-ss-config'));
const config = JSON.parse(configEl.textContent);
mappings = config.mappings || [];
identity = config.identity || {};
settings = { ...settings, ...(config.settings || {}) };
configEl.remove(); // clean up
}
} catch (e) {
console.warn('[Silent Send] Failed to parse initial config:', e);
+9 -1
View File
@@ -97,9 +97,17 @@
identity = mergeProfiles(identity);
}
// Inject config as a global variable before loading content.js
// Using a separate inline-data element ensures content.js can read it
// even if there's a race condition with script.onload removal
const configEl = document.createElement('script');
configEl.type = 'application/json';
configEl.id = 'ss-config-data';
configEl.textContent = JSON.stringify({ mappings, identity, settings });
(document.head || document.documentElement).appendChild(configEl);
// Inject the main interception script into the page's world
const script = document.createElement('script');
script.setAttribute('data-ss-config', JSON.stringify({ mappings, identity, settings }));
script.src = api.runtime.getURL('src/content/content.js');
(document.head || document.documentElement).appendChild(script);
script.onload = () => script.remove();