@@ -10,6 +10,7 @@ import { useEffect, useMemo, useState, type FormEvent } from "react";
1010import faviconUrl from "../favicon.svg" ;
1111import type { OwnedArtifact , ViewedArtifact } from "../shared/api" ;
1212import { client } from "./api" ;
13+ import { prepareArtifactPreview } from "./artifact-preview" ;
1314import { AuthProvider , SignInWithGoogle , signOut , useAuth } from "./auth" ;
1415import { RequestFailure } from "./request-failure" ;
1516import {
@@ -26,7 +27,6 @@ import {
2627
2728const DEFAULT_DOCUMENT_TITLE = "Codex Artifacts" ;
2829const KNOWN_EMAILS_KEY = "codex-artifacts:known-emails" ;
29- const SRCDOC_BASE = '<base href="about:srcdoc">' ;
3030const EXPIRATION_OPTIONS = [
3131 { label : "1 hour" , value : "3600" } ,
3232 { label : "1 day" , value : "86400" } ,
@@ -65,28 +65,6 @@ function messageFromError(error: unknown): string {
6565 return error instanceof Error ? error . message : "Something went wrong." ;
6666}
6767
68- function withSrcdocBase ( html : string ) : string {
69- const head = / < h e a d (?: \s [ ^ > ] * ) ? > / i. exec ( html ) ;
70- if ( head ) {
71- const insertionPoint = head . index + head [ 0 ] . length ;
72- return `${ html . slice ( 0 , insertionPoint ) } ${ SRCDOC_BASE } ${ html . slice ( insertionPoint ) } ` ;
73- }
74-
75- const documentElement = / < h t m l (?: \s [ ^ > ] * ) ? > / i. exec ( html ) ;
76- if ( documentElement ) {
77- const insertionPoint = documentElement . index + documentElement [ 0 ] . length ;
78- return `${ html . slice ( 0 , insertionPoint ) } <head>${ SRCDOC_BASE } </head>${ html . slice ( insertionPoint ) } ` ;
79- }
80-
81- const doctype = / < ! d o c t y p e (?: \s [ ^ > ] * ) ? > / i. exec ( html ) ;
82- if ( doctype ) {
83- const insertionPoint = doctype . index + doctype [ 0 ] . length ;
84- return `${ html . slice ( 0 , insertionPoint ) } <head>${ SRCDOC_BASE } </head>${ html . slice ( insertionPoint ) } ` ;
85- }
86-
87- return `<head>${ SRCDOC_BASE } </head>${ html } ` ;
88- }
89-
9068function readKnownEmails ( ) : string [ ] {
9169 try {
9270 const value = JSON . parse ( window . localStorage . getItem ( KNOWN_EMAILS_KEY ) ?? "[]" ) ;
@@ -662,7 +640,7 @@ function ArtifactFrame({ slug }: { slug: string }) {
662640 return ( ) => URL . revokeObjectURL ( url ) ;
663641 } , [ artifact ?. html ] ) ;
664642 const previewHtml = useMemo (
665- ( ) => artifact ? withSrcdocBase ( artifact . html ) : "" ,
643+ ( ) => artifact ? prepareArtifactPreview ( artifact . html ) : "" ,
666644 [ artifact ?. html ]
667645 ) ;
668646
@@ -854,7 +832,7 @@ function ArtifactFrame({ slug }: { slug: string }) {
854832 < iframe
855833 className = "min-h-[700px] flex-1 border-0 bg-white"
856834 referrerPolicy = "no-referrer"
857- sandbox = "allow-downloads allow-forms allow-modals allow-popups allow-scripts"
835+ sandbox = "allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow- scripts"
858836 srcDoc = { previewHtml }
859837 title = { artifact . title }
860838 />
0 commit comments