Sha256: 296ac07b8fff6e9322dfa60545d7d575380f366001d193bf621edc40e015b8fb
Contents?: true
Size: 1.18 KB
Versions: 8
Compression:
Stored size: 1.18 KB
Contents
import { Controller } from 'stimulus' import axios from '../utils/axios' export default class extends Controller { static targets = ['source', 'output'] static values = { url: String } connect() { this.sourceTarget.addEventListener('load', () => { const html2canvasScript = document.createElement('script') html2canvasScript.setAttribute( 'src', 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.3/html2canvas.min.js', ) this.sourceTarget.contentDocument.head.appendChild(html2canvasScript) }) } take() { const realSource = this.sourceTarget.contentDocument.querySelector( '[data-maglev-dropzone]', ) this.sourceTarget.contentWindow .html2canvas(realSource, { allowTaint: true, logging: true, useCORS: true, }) .then((canvas) => { this.outputTarget.src = canvas.toDataURL() // for debugging purpose axios .post(this.urlValue, { screenshot: { base64_image: canvas.toDataURL() }, }) .then(() => { alert('Screenshot done!') }) .catch((error) => console.log('ERROR!', error)) }) } }
Version data entries
8 entries across 8 versions & 1 rubygems