(options)
| 18 | |
| 19 | export class Sandbox { |
| 20 | static async create(options) { |
| 21 | this.emptyPath = options.emptyPath || "./" |
| 22 | let frame = document.createElement("iframe") |
| 23 | frame.src = this.emptyPath + "empty.html" |
| 24 | if (options.place) { |
| 25 | options.place(frame) |
| 26 | } else { |
| 27 | frame.style.height = "0px" |
| 28 | frame.style.border = "none" |
| 29 | document.body.appendChild(frame) |
| 30 | } |
| 31 | await awaitEvent(frame, "load") |
| 32 | |
| 33 | let box = new Sandbox(frame) |
| 34 | let scripts = (options.loadFiles || []).map(file => { |
| 35 | let script = box.win.document.createElement("script") |
| 36 | script.src = file |
| 37 | box.win.document.body.appendChild(script) |
| 38 | return awaitEvent(script, "load") |
| 39 | }) |
| 40 | await Promise.all(scripts) |
| 41 | return box |
| 42 | } |
| 43 | |
| 44 | constructor(frame) { |
| 45 | this.startedAt = null |
no test coverage detected