|
13 | 13 | {display:flex} |
14 | 14 |
|
15 | 15 | .radio |
16 | | - {border:1px solid lightgray;padding:2px 10px;border-radius:5px;cursor:pointer} |
| 16 | + {border:1px solid lightgray;padding:2px 10px;border-radius:5px;cursor:pointer;display:flex;align-items:center} |
| 17 | + #isolate |
| 18 | + {margin-right:10px} |
| 19 | + #allow-scripts |
| 20 | + {color:gray} |
| 21 | + #console-clear |
| 22 | + {margin-right:20px} |
17 | 23 |
|
18 | 24 | #hldr |
19 | 25 | {flex:1;box-sizing:border-box;position:relative} |
|
22 | 28 | #glass |
23 | 29 | {position:absolute;left:0;top:0;width:100%;height:100%;display:none} |
24 | 30 |
|
| 31 | + #slider |
| 32 | + {height:10px;cursor:ns-resize} |
| 33 | + |
| 34 | + #kill |
| 35 | + {padding:5px 10px;min-width:60px} |
| 36 | + |
25 | 37 | </style> |
26 | 38 |
|
27 | 39 | <div id=hdr> |
| 40 | + <span id=isolate class=radio> |
| 41 | + <input type=checkbox> |
| 42 | + isolate |
| 43 | + </span> |
| 44 | + |
28 | 45 | <span id=allow-scripts class=radio> |
29 | | - <input type=checkbox checked> |
| 46 | + <input type=checkbox checked disabled> |
30 | 47 | allow-scripts |
31 | 48 | </span> |
32 | 49 | <span id=allow-modals class=radio> |
33 | 50 | <input type=checkbox checked> |
34 | 51 | allow-modals |
35 | 52 | </span> |
36 | | - <span id=allow-popups class=radio> |
| 53 | + <span id=allow-popups class=radio style='margin-right:30px'> |
37 | 54 | <input type=checkbox checked> |
38 | 55 | allow-popups |
39 | 56 | </span> |
40 | 57 |
|
41 | 58 | <div style='flex:1'></div> |
42 | | - <button id=kill style='margin-right:20px'>kill</button> |
| 59 | + |
| 60 | + <span id=console-show class=radio> |
| 61 | + <input type=checkbox checked> |
| 62 | + console |
| 63 | + </span> |
| 64 | + <span id=console-echo class=radio> |
| 65 | + <input type=checkbox checked> |
| 66 | + echo |
| 67 | + </span> |
| 68 | + <span id=console-persist class=radio> |
| 69 | + <input type=checkbox> |
| 70 | + persist |
| 71 | + </span> |
| 72 | + <span id=console-clear class=radio> |
| 73 | + clear |
| 74 | + </span> |
| 75 | + |
| 76 | + <button id=kill>kill</button> |
43 | 77 | </div> |
44 | 78 |
|
| 79 | + |
| 80 | + <!-- |
| 81 | + https://sandbox-ext-code-com-1024713184986.us-central1.run.app/html-sandbox/html-sandbox.html |
| 82 | + https://ext-code-test.com/html-sandbox/html-sandbox.html |
| 83 | + --> |
45 | 84 | <div id=hldr> |
46 | | - <iframe sandbox='allow-forms allow-downloads allow-pointer-lock allow-popups-to-escape-sandbox'></iframe> |
| 85 | + <iframe></iframe> |
47 | 86 | <div id=glass></div> |
48 | 87 | </div> |
49 | 88 |
|
| 89 | + <div id=slider></div> |
| 90 | + |
| 91 | + <web-console component h=150></web-console> |
| 92 | + |
50 | 93 | </template> |
51 | 94 |
|
52 | 95 | <script> |
|
74 | 117 |
|
75 | 118 | //vars:- |
76 | 119 |
|
77 | | - var allow_same_origin = false; |
| 120 | + |
| 121 | + var webconsole; |
| 122 | + |
78 | 123 |
|
79 | 124 | var chk = {}; |
80 | 125 |
|
|
84 | 129 | var glass; |
85 | 130 |
|
86 | 131 |
|
87 | | - var btn = {}; |
| 132 | + var sandbox_url; |
| 133 | + var iframe_src = 'https://sandbox.ext-code.com/html-sandbox/html-sandbox.html'; |
| 134 | + var iframe_sandbox = 'allow-scripts allow-same-origin allow-forms';//allow-downloads allow-pointer-lock';//allow-popups-to-escape-sandbox |
| 135 | + var iframe_allow = `clipboard-write; clipboard-read; camera; microphone; geolocation; accelerometer; gyroscope; magnetometer; payment; usb; serial; bluetooth; |
| 136 | + xr-spatial-tracking; autoplay; encrypted-media; picture-in-picture; screen-wake-lock; web-share`; |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + var btn = {}; |
| 141 | + btn.console = {}; |
| 142 | + obj.on = {}; |
| 143 | + var build = {}; |
88 | 144 |
|
89 | 145 |
|
90 | 146 | //: |
91 | 147 |
|
92 | 148 |
|
93 | 149 | obj.init = async function(){ |
| 150 | + |
| 151 | + await mod.auto(); |
| 152 | + |
| 153 | + webconsole = mod['web-console']; |
| 154 | + |
| 155 | + |
94 | 156 | }//init |
95 | 157 |
|
96 | 158 |
|
97 | 159 | //: |
98 | 160 |
|
99 | 161 |
|
100 | | - obj.initdom = function(rootnode){ |
| 162 | + obj.initdom = function(){ |
101 | 163 |
|
102 | | - shadow = host.shadowRoot; |
| 164 | + shadow = host.shadowRoot; |
103 | 165 |
|
104 | | - var style = $(shadow,'style'); |
| 166 | + var style = $(shadow,'style'); |
105 | 167 | $.stylesheet.insert(style,'button','.icon'); |
106 | 168 |
|
107 | 169 |
|
108 | | - var hdr = $(shadow,'#hdr'); |
109 | | - chk['allow-scripts'] = $.chkbox(hdr,'#allow-scripts'); |
110 | | - chk['allow-modals'] = $.chkbox(hdr,'#allow-modals'); |
111 | | - chk['allow-popups'] = $.chkbox(hdr,'#allow-popups'); |
| 170 | + var hdr = $(shadow,'#hdr'); |
112 | 171 |
|
113 | | - $(hdr,'#kill').onclick = btn.kill; |
| 172 | + chk.isolate = $.chkbox(hdr,'#isolate'); |
| 173 | + chk.isolate.checked = window.crossOriginIsolated; |
114 | 174 |
|
| 175 | + chk['allow-scripts'] = $.chkbox(hdr,'#allow-scripts'); |
| 176 | + chk['allow-modals'] = $.chkbox(hdr,'#allow-modals'); |
| 177 | + chk['allow-popups'] = $.chkbox(hdr,'#allow-popups'); |
115 | 178 |
|
116 | | - hldr = $(shadow,'#hldr'); |
117 | | - iframe = $(shadow,'iframe'); |
118 | | - if(allow_same_origin){ |
119 | | - var attr = iframe.getAttribute('sandbox'); |
120 | | - attr += ' allow-same-origin'; |
121 | | - } |
122 | | - def_sandbox = iframe.getAttribute('sandbox'); |
123 | | - glass = $(shadow,'#glass'); |
| 179 | + chk['console-show'] = $.chkbox(hdr,'#console-show',btn.console.show); |
| 180 | + chk['console-echo'] = $.chkbox(hdr,'#console-echo'); |
| 181 | + chk['console-persist'] = $.chkbox(hdr,'#console-persist'); |
| 182 | + $(shadow,'#console-clear').onclick = btn.console.clear; |
| 183 | + |
| 184 | + $(hdr,'#kill').onclick = btn.kill; |
124 | 185 |
|
125 | 186 |
|
| 187 | + hldr = $(shadow,'#hldr'); |
| 188 | + iframe = $(shadow,'iframe'); |
| 189 | + glass = $(shadow,'#glass'); |
| 190 | + |
| 191 | + |
| 192 | + $.slider(hldr,'#slider',webconsole.host,null,{root:shadow,mode:'horiz'}); |
| 193 | + |
126 | 194 | }//initdom |
127 | 195 |
|
128 | 196 |
|
|
135 | 203 |
|
136 | 204 | }//kill |
137 | 205 |
|
| 206 | +/* |
| 207 | + btn.isolate = function(chk){ |
| 208 | + |
| 209 | + var url = new URL(sandbox_url); |
| 210 | + if(chk.checked){ |
| 211 | + sanbox_url += '?isolate'; |
| 212 | + }else{ |
| 213 | + var i = sandbox_url.indexOf('?'); |
| 214 | + sandbox_url = sandbox_url.slice(0,i); |
| 215 | + } |
| 216 | + |
| 217 | + }//isolate |
| 218 | +*/ |
| 219 | + |
| 220 | + |
| 221 | + btn.console.show = function(chk){ |
| 222 | + |
| 223 | + if(chk.checked){ |
| 224 | + webconsole.host.style.display = ''; |
| 225 | + }else{ |
| 226 | + webconsole.host.style.display = 'none'; |
| 227 | + } |
| 228 | + |
| 229 | + }//show |
| 230 | + |
| 231 | + |
| 232 | + btn.console.clear = function(){ |
| 233 | + |
| 234 | + webconsole.clear(); |
| 235 | + if(chk['console-echo'].checked){ |
| 236 | + console.clear(); |
| 237 | + } |
| 238 | + |
| 239 | + }//clear |
| 240 | + |
| 241 | + |
138 | 242 |
|
139 | 243 | obj.glass = function(show=true){ |
140 | 244 |
|
|
164 | 268 |
|
165 | 269 |
|
166 | 270 |
|
167 | | - obj.srcdoc = function(html){ |
| 271 | + //: |
| 272 | + |
| 273 | + |
| 274 | + obj.run = function(html){ |
| 275 | + }//run |
| 276 | + |
| 277 | + |
| 278 | + build.sandbox = function(){ |
168 | 279 |
|
169 | | - var attr = def_sandbox; |
170 | | - console.log(attr); |
| 280 | + var attr = iframe_sandbox; |
| 281 | + //console.log(attr); |
171 | 282 | var tokens = new Set(attr.split(/\s+/).filter(Boolean)); |
172 | 283 |
|
173 | | - if(chk['allow-scripts'].checked){ |
174 | | - tokens.add('allow-scripts'); |
| 284 | + if(!chk['allow-scripts'].checked){ |
| 285 | + tokens.delete('allow-scripts'); |
175 | 286 | } |
176 | 287 | if(chk['allow-modals'].checked){ |
177 | 288 | tokens.add('allow-modals'); |
|
181 | 292 | } |
182 | 293 |
|
183 | 294 | var attr = [...tokens].join(' '); |
184 | | - console.log(attr); |
| 295 | + debug(attr); |
185 | 296 | iframe.setAttribute('sandbox',attr); |
186 | 297 |
|
| 298 | + }//sandbox |
| 299 | + |
| 300 | + |
| 301 | + obj.sandbox = function(html){ |
| 302 | + debug('sandbox'); |
| 303 | + iframe.remove(); |
| 304 | + iframe = iframe.cloneNode(); |
| 305 | + debug(sandbox_url); |
| 306 | + build.sandbox(); |
| 307 | + |
| 308 | + iframe.setAttribute('allow',iframe_allow); |
| 309 | + debug(iframe_allow); |
| 310 | + var src = iframe_src; |
| 311 | + if(chk.isolate.checked){ |
| 312 | + src += '?isolate'; |
| 313 | + } |
| 314 | + iframe.src = src; |
| 315 | + debug(src); |
| 316 | + iframe.onload = onload; |
| 317 | + hldr.append(iframe); |
| 318 | + |
| 319 | + |
| 320 | + function onload(){ |
| 321 | + debug('onload'); |
| 322 | + iframe.onload = null; |
| 323 | + |
| 324 | + if(!chk['console-persist'].checked){ |
| 325 | + webconsole.clear(); |
| 326 | + if(chk['console-echo'].checked){ |
| 327 | + console.clear(); |
| 328 | + } |
| 329 | + } |
| 330 | + |
| 331 | + var echo = chk['console-echo'].checked; |
| 332 | + iframe.contentWindow.postMessage({type:'run',html,echo},'*'); |
| 333 | + |
| 334 | + }//onload |
| 335 | + |
| 336 | + }//sandbox |
| 337 | + |
| 338 | + |
| 339 | +/* |
| 340 | + obj.srcdoc = function(html){ |
| 341 | + |
| 342 | + iframe.remove(); |
| 343 | + iframe = iframe.cloneNode(); |
| 344 | + |
| 345 | + build.sandbox(); |
| 346 | + |
| 347 | + hldr.append(iframe); |
| 348 | + |
| 349 | + |
| 350 | + if(!chk['console-persist'].checked){ |
| 351 | + webconsole.clear(); |
| 352 | + if(chk['console-echo'].checked){ |
| 353 | + console.clear(); |
| 354 | + } |
| 355 | + } |
| 356 | + |
187 | 357 | iframe.srcdoc = html; |
188 | 358 | |
189 | 359 | }//srcdoc |
| 360 | +*/ |
| 361 | + |
| 362 | + |
| 363 | +/* |
| 364 | + obj.blob = function(html){ |
190 | 365 | |
191 | | - |
| 366 | + var blob=new Blob([html],{type:'text/html'}); |
| 367 | + var url=URL.createObjectURL(blob); |
| 368 | + iframe.src=url; |
| 369 | + |
| 370 | + }//blob |
| 371 | +*/ |
| 372 | + |
192 | 373 | obj.kill = function(){return kill()} //d |
193 | 374 |
|
194 | 375 | function kill(){ |
195 | 376 |
|
196 | 377 | var niframe = iframe.cloneNode(true); |
197 | | - niframe.srcdoc = null; |
| 378 | + //niframe.srcdoc = null; |
198 | 379 | hldr.replaceChild(niframe,iframe); |
199 | 380 | iframe = niframe; |
200 | 381 |
|
201 | 382 | }//kill |
202 | 383 |
|
203 | 384 |
|
| 385 | + //: |
| 386 | + |
| 387 | + |
| 388 | + obj.on.message = function(json){ |
| 389 | + console.log('output.message',json); |
| 390 | + var {name,args} = json; |
| 391 | + webconsole[name].apply(null,args); |
| 392 | + |
| 393 | + }//message |
| 394 | + |
| 395 | + |
204 | 396 | //: |
205 | 397 |
|
206 | 398 |
|
|
0 commit comments