|
52 | 52 | isolate |
53 | 53 | </span> |
54 | 54 |
|
55 | | - <span id=allow-scripts class=radio> |
56 | | - <input type=checkbox checked disabled> |
57 | | - allow-scripts |
58 | | - </span> |
59 | 55 | <span id=allow-modals class=radio> |
60 | 56 | <input type=checkbox checked> |
61 | 57 | allow-modals |
|
67 | 63 |
|
68 | 64 | <div style='flex:1'></div> |
69 | 65 |
|
70 | | - <span id=console-show class=radio> |
| 66 | + <span id=console class=radio> |
71 | 67 | <input type=checkbox checked> |
72 | 68 | console |
73 | 69 | </span> |
|
105 | 101 | version : 'v2.0', |
106 | 102 | }; |
107 | 103 |
|
108 | | - var df=false,did='output-console' |
| 104 | + var df=true,did='output-console' |
109 | 105 | ; |
110 | 106 |
|
111 | 107 |
|
|
144 | 140 | var sandbox_allow = `clipboard-write; clipboard-read; camera; microphone; geolocation; accelerometer; gyroscope; magnetometer; payment; usb; serial; bluetooth; |
145 | 141 | xr-spatial-tracking; autoplay; encrypted-media; picture-in-picture; screen-wake-lock; web-share`; |
146 | 142 |
|
147 | | - |
| 143 | + var fn = {}; |
148 | 144 | var chk = {}; |
149 | 145 | var btn = {}; |
| 146 | + var btn.console = {}; |
| 147 | + obj.on = {}; |
150 | 148 |
|
151 | 149 |
|
152 | 150 | //: |
|
174 | 172 | debug('initdom'); |
175 | 173 | shadow = host.shadowRoot; |
176 | 174 |
|
177 | | - chk.persist = $.chkbox(shadow,'#console-persist',false); |
178 | | - chk.log = $.chkbox(shadow,'#console-log',false); |
| 175 | + |
| 176 | + chk.isolate = $.chkbox(shadow,'#isolate'); |
| 177 | + |
| 178 | + chk['allow-modals'] = $.chkbox(shadow,'#allow-modals'); |
| 179 | + chk['allow-popups'] = $.chkbox(shadow,'#allow-popups'); |
| 180 | + |
| 181 | + chk.console = $.chkbox(shadow,'#console'); |
| 182 | + chk['console-echo'] = $.chkbox(shadow,'#console-echo'); |
| 183 | + chk['console-persist'] = $.chkbox(shadow,'#console-persist',false); |
| 184 | + $.chkbox(shadow,'#console-clear',btn.console.clear); |
| 185 | + |
179 | 186 | chk.wrap = $.chkbox(shadow,'#word-wrap',wrap); |
180 | 187 |
|
181 | | - $(shadow,'#clear').onclick = btn.clear; |
182 | 188 | $(shadow,'#kill').onclick = btn.kill; |
183 | 189 |
|
184 | 190 |
|
|
192 | 198 | }//initdom |
193 | 199 |
|
194 | 200 |
|
195 | | - btn.kill = function(){ |
196 | | - debug('btn.kill'); |
197 | | - kill(); |
198 | | - |
199 | | - }//kill |
200 | 201 |
|
201 | 202 |
|
202 | | - btn.clear = function(){ |
| 203 | + btn.console.clear = function(){ |
203 | 204 | debug('btn.clear'); |
204 | 205 | clear(); |
205 | 206 |
|
206 | 207 | }//clear |
207 | 208 |
|
208 | 209 |
|
209 | | - function wrap(chk){ |
| 210 | + btn.wrap = function(chk){ |
210 | 211 | //console.log('wrap',v); |
211 | 212 | if(chk.checked){ |
212 | 213 | output.style.whiteSpace = 'pre-wrap'; |
|
217 | 218 | }//wrap |
218 | 219 |
|
219 | 220 |
|
| 221 | + btn.kill = function(){ |
| 222 | + debug('btn.kill'); |
| 223 | + kill(); |
| 224 | + |
| 225 | + }//kill |
| 226 | + |
| 227 | + |
| 228 | + //: |
| 229 | + |
| 230 | + |
| 231 | + obj.on.message = function(json){ |
| 232 | + console.log('output.message',json); |
| 233 | + var {name,args} = json; |
| 234 | + //webconsole[name].apply(null,args); |
| 235 | + fn[name].apply(null,args); |
| 236 | + |
| 237 | + }//message |
| 238 | + |
| 239 | + |
| 240 | + //: |
| 241 | + |
| 242 | + |
220 | 243 | obj.run = async function(js,params={}){ |
221 | 244 | debug('run'); |
222 | 245 | var sandbox = (()=>{ |
|
310 | 333 | build.sandbox(); |
311 | 334 | iframe.setAttribute('allow',sandbox_allow); |
312 | 335 | iframe.src = sandbox_url; |
| 336 | + debug(sandbox_url); |
313 | 337 | iframe.style.cssText = 'display:none'; |
314 | 338 | iframe.onload = onload; |
315 | 339 |
|
|
323 | 347 | async function onload(){ |
324 | 348 |
|
325 | 349 |
|
326 | | - |
327 | | - if(!chk.persist){ |
| 350 | + if(!chk['console-persist'].checked){ |
328 | 351 | clear(); |
329 | 352 | } |
330 | 353 |
|
331 | 354 |
|
332 | 355 | if(params.async){ |
333 | 356 | js = '(async()=>{\n'+js+'\n})()'; |
334 | 357 | } |
335 | | - var result = await win.eval(js); |
| 358 | + |
| 359 | + iframe.contentWindow.postMessage({type:'run',js}); |
| 360 | + //var result = await win.eval(js); |
336 | 361 |
|
337 | 362 |
|
338 | 363 | resolve(result); |
|
389 | 414 |
|
390 | 415 |
|
391 | 416 | obj.clear = function(){return clear()} |
| 417 | + fn.clear = function(){return clear.apply(null,arguments)}; |
392 | 418 |
|
393 | 419 | function clear(){ |
394 | 420 |
|
|
402 | 428 |
|
403 | 429 |
|
404 | 430 | obj.log = function(){return log.apply(log,arguments)}; |
| 431 | + fn.log = function(){return log.apply(null,arguments)}; |
405 | 432 |
|
406 | 433 | function log(){ |
407 | 434 |
|
|
436 | 463 |
|
437 | 464 |
|
438 | 465 | obj.groupCollapsed = function(){return groupCollapsed.apply(null,arguments)} |
| 466 | + fn[groupCollapsed = function(){return groupCollapsed.apply(null,arguments)} |
439 | 467 |
|
440 | 468 | function groupCollapsed(...args){ |
441 | 469 |
|
|
451 | 479 |
|
452 | 480 |
|
453 | 481 | obj.error = function(){return error.apply(null,arguments)} |
| 482 | + fn.error = function(){return error.apply(null,arguments)} |
454 | 483 |
|
455 | 484 | function error(){ |
456 | 485 |
|
|
467 | 496 |
|
468 | 497 |
|
469 | 498 | obj.node = function(){return node.apply(null,arguments)} |
| 499 | + fn.node = function(){return node.apply(null,arguments)} |
470 | 500 |
|
471 | 501 | function node(node){ |
472 | 502 |
|
|
481 | 511 |
|
482 | 512 |
|
483 | 513 | obj.write = function(){return write.apply(null,arguments)} |
| 514 | + fn.write = function(){return write.apply(null,arguments)} |
484 | 515 |
|
485 | 516 | function write(){ |
486 | 517 |
|
|
0 commit comments