Remove direct HelloSkip script from index.html
cgen-088b8f2d60504ed59c3b69404fbcfea3
This commit is contained in:
parent
c550e59854
commit
807aeae5d6
2 changed files with 37 additions and 1 deletions
|
|
@ -16,3 +16,40 @@ root.render(
|
|||
</ErrorBoundary>
|
||||
</StrictMode>,
|
||||
);
|
||||
|
||||
// Safely load HelloSkip agent: fetch the script first and only evaluate if fetching succeeds.
|
||||
// This prevents the external script from executing its runtime network checks when the host
|
||||
// environment blocks cross-origin requests, avoiding uncaught "Failed to fetch" errors.
|
||||
(async function loadHelloSkipAgent() {
|
||||
try {
|
||||
if (!('fetch' in window) || !navigator.onLine) return;
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const res = await fetch('https://helloskip.com/agent.js', { signal: controller.signal });
|
||||
clearTimeout(timeout);
|
||||
|
||||
if (!res.ok) throw new Error('Failed to download HelloSkip agent script');
|
||||
|
||||
const scriptText = await res.text();
|
||||
const blob = new Blob([scriptText], { type: 'application/javascript' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const s = document.createElement('script');
|
||||
s.src = url;
|
||||
s.dataset.agentId = 'vVEuropu5l7xvT4Swwif';
|
||||
s.async = true;
|
||||
s.onload = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
s.onerror = (e) => {
|
||||
console.warn('HelloSkip agent failed to execute', e);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
document.body.appendChild(s);
|
||||
} catch (err) {
|
||||
console.warn('Skipped loading HelloSkip agent:', err);
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -173,6 +173,5 @@
|
|||
<div id="root"></div>
|
||||
|
||||
<script type="module" src="/client/main.tsx"></script>
|
||||
<script src="https://helloskip.com/agent.js" data-agent-id="vVEuropu5l7xvT4Swwif"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue