-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor: updated screenshot.js to use dynamic module imports"
This reverts commit 2e6fc1e.
- Loading branch information
1 parent
2e6fc1e
commit 75b807c
Showing
1 changed file
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
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)); | ||
}; | ||
|
||
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))); | ||
function script(src) { | ||
return new Promise(resolve => { | ||
const el = document.createElement('script'); | ||
el.src = src; | ||
document.head.appendChild(el); | ||
el.addEventListener('load', () => resolve(el)); | ||
}); | ||
} | ||
|
||
export default screenshot; |