BoxOfColors Claude Sonnet 4.6 commited on
Commit
110c8ab
·
1 Parent(s): c71e56e

fix: revert to document.body for toast — window.top blocked cross-origin

Browse files

When the Space runs embedded on huggingface.co, window.top is the HF
parent page (different origin), so accessing window.top.document throws
a SecurityError. The _GLOBAL_JS already runs in the Space's own iframe
context so plain document.body is correct and always accessible.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -2130,10 +2130,7 @@ _GLOBAL_JS = """
2130
 
2131
  // Toast notification — styled like ZeroGPU quota warnings.
2132
  function _showRegenToast(message, isError) {
2133
- // Use window.top.document so the toast always lands on the visible page,
2134
- // regardless of whether this JS runs inside a Gradio shadow context.
2135
- var doc = (window.top && window.top.document) ? window.top.document : document;
2136
- var t = doc.createElement('div');
2137
  t.style.cssText = 'position:fixed;bottom:24px;left:50%;transform:translateX(-50%);' +
2138
  'z-index:2147483647;padding:12px 20px;border-radius:8px;font-family:sans-serif;' +
2139
  'font-size:13px;max-width:520px;text-align:center;box-shadow:0 4px 20px rgba(0,0,0,.6);' +
@@ -2141,7 +2138,7 @@ _GLOBAL_JS = """
2141
  'border:1px solid ' + (isError ? '#c0392b' : '#27ae60') + ';' +
2142
  'pointer-events:none;';
2143
  t.textContent = message;
2144
- doc.body.appendChild(t);
2145
  setTimeout(function() {
2146
  t.style.transition = 'opacity 0.5s';
2147
  t.style.opacity = '0';
 
2130
 
2131
  // Toast notification — styled like ZeroGPU quota warnings.
2132
  function _showRegenToast(message, isError) {
2133
+ var t = document.createElement('div');
 
 
 
2134
  t.style.cssText = 'position:fixed;bottom:24px;left:50%;transform:translateX(-50%);' +
2135
  'z-index:2147483647;padding:12px 20px;border-radius:8px;font-family:sans-serif;' +
2136
  'font-size:13px;max-width:520px;text-align:center;box-shadow:0 4px 20px rgba(0,0,0,.6);' +
 
2138
  'border:1px solid ' + (isError ? '#c0392b' : '#27ae60') + ';' +
2139
  'pointer-events:none;';
2140
  t.textContent = message;
2141
+ document.body.appendChild(t);
2142
  setTimeout(function() {
2143
  t.style.transition = 'opacity 0.5s';
2144
  t.style.opacity = '0';