diff --git a/src/toolbar/preview/screenshot.js b/src/toolbar/preview/screenshot.js index af30e89..565ad60 100644 --- a/src/toolbar/preview/screenshot.js +++ b/src/toolbar/preview/screenshot.js @@ -1,25 +1,11 @@ -let html2canvasPromise; - const screenshot = async () => { document.getElementById('prismic-toolbar-v2').setAttribute('data-html2canvas-ignore', true); - if (!html2canvasPromise) html2canvasPromise = script('https://html2canvas.hertzen.com/dist/html2canvas.min.js'); - await html2canvasPromise; - - const canvas = await window.html2canvas(document.body, { - logging: false, - width: '100%', - height: window.innerHeight, - }); - return new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.6)); -}; -function script(src) { - return new Promise(resolve => { - const el = document.createElement('script'); - el.src = src; - document.head.appendChild(el); - el.addEventListener('load', () => resolve(el)); - }); + const options = { logging: false, width: '100%', height: window.innerHeight }; + + return import('https://html2canvas.hertzen.com/dist/html2canvas.esm.js') + .then(html2canvas => html2canvas(document.body, options)) + .then(canvas => new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg', 0.6))); } export default screenshot;