steveyehtw commited on
Commit
bcbe624
Β·
1 Parent(s): 90b9514

Open external projects without blocked iframe embeds

Browse files
Files changed (1) hide show
  1. static/js/player.js +26 -11
static/js/player.js CHANGED
@@ -245,21 +245,36 @@
245
  // Hide side controls and console log panel, render full viewport width
246
  sidePanel.style.display = "none";
247
  layout.style.gridTemplateColumns = "1fr";
248
- statusWrapper.style.display = "none"; // Iframe handles itself
249
-
250
- viewportFrame.classList.add("iframe-mode");
251
-
252
- const iframe = document.createElement("iframe");
253
- iframe.className = "iframe-viewport";
254
- iframe.allow = "autoplay; fullscreen; microphone; camera";
255
-
256
  if (projectType === "html") {
 
 
 
 
257
  iframe.src = `/static_projects/${encodeURIComponent(studentToken)}/${encodeURIComponent(projectName)}/index.html`;
 
258
  } else if (projectType === "external") {
259
- iframe.src = formatEmbedUrl(externalUrl);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  }
261
-
262
- viewportFrame.appendChild(iframe);
263
  }
264
  }
265
 
 
245
  // Hide side controls and console log panel, render full viewport width
246
  sidePanel.style.display = "none";
247
  layout.style.gridTemplateColumns = "1fr";
248
+ statusWrapper.style.display = "none";
249
+
 
 
 
 
 
 
250
  if (projectType === "html") {
251
+ viewportFrame.classList.add("iframe-mode");
252
+ const iframe = document.createElement("iframe");
253
+ iframe.className = "iframe-viewport";
254
+ iframe.allow = "autoplay; fullscreen; microphone; camera";
255
  iframe.src = `/static_projects/${encodeURIComponent(studentToken)}/${encodeURIComponent(projectName)}/index.html`;
256
+ viewportFrame.appendChild(iframe);
257
  } else if (projectType === "external") {
258
+ // External sites (MakeCode/Scratch/etc.) may send restrictive
259
+ // frame headers. Open them directly instead of embedding an
260
+ // iframe, which avoids COEP/CSP "frame blocked" errors.
261
+ const card = document.createElement("div");
262
+ card.style.cssText = "display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1rem;min-height:18rem;padding:2rem;text-align:center;color:#e5eefb;";
263
+ const title = document.createElement("h2");
264
+ title.textContent = projectName;
265
+ title.style.margin = "0";
266
+ const note = document.createElement("p");
267
+ note.textContent = "ζ­€δ½œε“δ½ζ–Όε€–ιƒ¨ηΆ²η«™οΌŒθ«‹ι»žζ“ŠζŒ‰ιˆ•ι–‹ε•Ÿγ€‚";
268
+ note.style.cssText = "margin:0;color:#94a3b8;";
269
+ const link = document.createElement("a");
270
+ link.href = formatEmbedUrl(externalUrl);
271
+ link.target = "_blank";
272
+ link.rel = "noopener noreferrer";
273
+ link.className = "btn-launch btn-launch-html";
274
+ link.textContent = "ι–‹ε•Ÿδ½œε“ β†—";
275
+ card.append(title, note, link);
276
+ viewportFrame.appendChild(card);
277
  }
 
 
278
  }
279
  }
280