Skip to content

Instantly share code, notes, and snippets.

@gullinbursti
Created October 21, 2023 16:39
Show Gist options
  • Save gullinbursti/1eca2c3ff41c532514af5801786a4c75 to your computer and use it in GitHub Desktop.
Save gullinbursti/1eca2c3ff41c532514af5801786a4c75 to your computer and use it in GitHub Desktop.
js page screenshot
[...document.querySelectorAll('div,main,body')].forEach((node)=> {
node.style.position = 'relative';
node.style.height = 'auto';
node.style.overflowY = 'visible';
});
[...document.querySelectorAll('button')].forEach((node)=> {
node.remove();
});
const { default: html2canvas } = await import('https://cdn.skypack.dev/html2canvas');
const canvas = await html2canvas(document.querySelector('main'));
const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
const link = document.createElement('a');
link.target = '_blank';
link.href = URL.createObjectURL(blob);
link.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment