SOY NV AI commited on
Commit
12d93bf
ยท
1 Parent(s): a233557

Fix: Add Permissions-Policy header and replace autofocus with JavaScript to fix iframe warnings

Browse files
Files changed (2) hide show
  1. app/__init__.py +15 -0
  2. templates/login.html +20 -1
app/__init__.py CHANGED
@@ -107,6 +107,21 @@ def create_app() -> Flask:
107
  def log_response_info(response):
108
  """๊ฐ HTTP ์‘๋‹ต ์ •๋ณด๋ฅผ ๋กœ๊น…"""
109
  logger.info(f"[์‘๋‹ต] {request.method} {request.path} - ์ƒํƒœ: {response.status_code}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  return response
111
 
112
  # ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ดˆ๊ธฐํ™” ๋ฐ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜
 
107
  def log_response_info(response):
108
  """๊ฐ HTTP ์‘๋‹ต ์ •๋ณด๋ฅผ ๋กœ๊น…"""
109
  logger.info(f"[์‘๋‹ต] {request.method} {request.path} - ์ƒํƒœ: {response.status_code}")
110
+
111
+ # Permissions-Policy ํ—ค๋” ์ถ”๊ฐ€ (iframe ์ž„๋ฒ ๋“œ ์‹œ ๊ฒฝ๊ณ  ๋ฐฉ์ง€)
112
+ # Hugging Face Spaces์—์„œ iframe์œผ๋กœ ์ž„๋ฒ ๋“œ๋  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ๊ณ ๋ฅผ ๋ฐฉ์ง€
113
+ permissions_policy = (
114
+ "ambient-light-sensor=(), "
115
+ "battery=(), "
116
+ "document-domain=(), "
117
+ "layout-animations=(), "
118
+ "legacy-image-formats=(), "
119
+ "oversized-images=(), "
120
+ "vr=(), "
121
+ "wake-lock=()"
122
+ )
123
+ response.headers['Permissions-Policy'] = permissions_policy
124
+
125
  return response
126
 
127
  # ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ดˆ๊ธฐํ™” ๋ฐ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜
templates/login.html CHANGED
@@ -155,7 +155,7 @@
155
  <form method="POST" action="{{ url_for('main.login') }}">
156
  <div class="form-group">
157
  <label for="username">์‚ฌ์šฉ์ž๋ช…</label>
158
- <input type="text" id="username" name="username" required autofocus>
159
  </div>
160
 
161
  <div class="form-group">
@@ -166,6 +166,25 @@
166
  <button type="submit" class="login-button">๋กœ๊ทธ์ธ</button>
167
  </form>
168
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  </body>
170
  </html>
171
 
 
155
  <form method="POST" action="{{ url_for('main.login') }}">
156
  <div class="form-group">
157
  <label for="username">์‚ฌ์šฉ์ž๋ช…</label>
158
+ <input type="text" id="username" name="username" required>
159
  </div>
160
 
161
  <div class="form-group">
 
166
  <button type="submit" class="login-button">๋กœ๊ทธ์ธ</button>
167
  </form>
168
  </div>
169
+
170
+ <script>
171
+ // iframe ๋‚ด๋ถ€์—์„œ๋„ ์ž‘๋™ํ•˜๋„๋ก JavaScript๋กœ autofocus ์ฒ˜๋ฆฌ
172
+ // Cross-origin iframe์—์„œ autofocus๊ฐ€ ์ฐจ๋‹จ๋˜๋Š” ๋ฌธ์ œ ํ•ด๊ฒฐ
173
+ document.addEventListener('DOMContentLoaded', function() {
174
+ const usernameInput = document.getElementById('username');
175
+ if (usernameInput) {
176
+ // ์•ฝ๊ฐ„์˜ ์ง€์—ฐ์„ ๋‘์–ด iframe ๋กœ๋”ฉ ์™„๋ฃŒ ํ›„ ํฌ์ปค์Šค
177
+ setTimeout(function() {
178
+ try {
179
+ usernameInput.focus();
180
+ } catch (e) {
181
+ // iframe์—์„œ ํฌ์ปค์Šค๊ฐ€ ์ฐจ๋‹จ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ฌด์‹œ
182
+ console.debug('Autofocus blocked in iframe (expected behavior)');
183
+ }
184
+ }, 100);
185
+ }
186
+ });
187
+ </script>
188
  </body>
189
  </html>
190