| <!DOCTYPE html> |
| <html> |
| <head> |
| <script> |
| let loadedContent = []; |
| onmessage = function (event) { |
| if (event.data.type == 'paste') { |
| document.body.focus(); |
| document.execCommand('selectAll'); |
| if (window.testRunner) |
| document.execCommand('paste'); |
| } else if (event.data.type == 'contentLoaded') { |
| loadedContent.push(event.data); |
| checkIfLoadCompleted(); |
| } |
| } |
| |
| let frames = []; |
| function doPaste(event) { |
| top.postMessage({type: 'pasted', html: event.clipboardData.getData('text/html')}, '*'); |
| } |
| |
| function checkIfLoadCompleted() { |
| const frames = Array.from(document.body.querySelectorAll('iframe')); |
| if (loadedContent.length < frames.length) |
| return; |
| |
| top.postMessage({ |
| type: 'checkedState', |
| html: document.body.innerHTML, |
| frames: frames.map((frame, i) => { |
| return { |
| src: frame.src, |
| class: frame.className, |
| canAccessContentDocument: !!frame.contentDocument, |
| imageSrc: loadedContent[i].imageSrc, |
| imageWidth: loadedContent[i].imageWidth, |
| } |
| })}, '*'); |
| } |
| |
| </script> |
| <body onpaste="doPaste(event)" contenteditable> |
| Paste here. |
| </body> |
| </html> |