fix: config not reaching content.js — race condition with script removal
The data-ss-config attribute on the script tag was being removed (via script.onload) before content.js could read it. Changed approach: inject config as a separate <script type="application/json" id="ss-config-data"> element that persists in the DOM until content.js reads and removes it. This eliminates the race condition between script execution and onload removal. Bump 0.9.20. https://claude.ai/code/session_01KF4i7Ra7zCEDskxDBaNtcT
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user