File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ export const ScalingIframe = ({
99} ) => {
1010 const iframeRef = useRef < HTMLIFrameElement | null > ( null ) ;
1111 const [ scale , setScale ] = useState ( 1 ) ;
12+ const [ error , setError ] = useState ( false ) ;
13+
1214 useLayoutEffect ( ( ) => {
1315 const fitToParent = ( ) => {
1416 const iframe = iframeRef . current ;
@@ -24,10 +26,56 @@ export const ScalingIframe = ({
2426 return ( ) => window . removeEventListener ( "resize" , fitToParent ) ;
2527 } , [ width ] ) ;
2628
29+ const handleError = ( ) => {
30+ setError ( true ) ;
31+ } ;
32+
33+ if ( error ) {
34+ return (
35+ < div
36+ style = { {
37+ position : "absolute" ,
38+ top : 0 ,
39+ left : 0 ,
40+ right : 0 ,
41+ bottom : 0 ,
42+ display : "flex" ,
43+ alignItems : "center" ,
44+ justifyContent : "center" ,
45+ backgroundColor : "#f0f0f0" ,
46+ color : "#333" ,
47+ fontSize : "16px" ,
48+ textAlign : "center" ,
49+ padding : "20px" ,
50+ } }
51+ >
52+ < div >
53+ < p > Unable to load embedded content</ p >
54+ < p style = { { fontSize : "14px" , marginTop : "10px" } } >
55+ Please visit{ " " }
56+ < a
57+ href = { props . src ?. replace ( "/embed" , "" ) }
58+ target = "_blank"
59+ rel = "noopener noreferrer"
60+ style = { { color : "#d63384" } }
61+ >
62+ the original sketch
63+ </ a >
64+ { " " } on OpenProcessing
65+ </ p >
66+ </ div >
67+ </ div >
68+ ) ;
69+ }
70+
2771 return (
2872 < iframe
2973 width = { width }
3074 { ...props }
75+ sandbox = "allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
76+ allow = "fullscreen; clipboard-write"
77+ loading = "lazy"
78+ onError = { handleError }
3179 style = { {
3280 position : "absolute" ,
3381 top : 0 ,
Original file line number Diff line number Diff line change @@ -84,6 +84,9 @@ const iframeTitle = `OpenProcessing Sketch: ${title} by ${authorName}`;
8484 src = { makeSketchEmbedUrl (sketchIdNumber )}
8585 width = " 100%"
8686 height = " 100%"
87+ sandbox = " allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
88+ allow = " fullscreen; clipboard-write"
89+ loading = " lazy"
8790 style = { {
8891 position: " absolute" ,
8992 top: 0 ,
You can’t perform that action at this time.
0 commit comments