Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
'html2canvas is not defined' after appending CDN

I am trying to use html2canvas as part of a script (see below). The script has been designed to be injected via the console as part of an experiment and so a script containing the CDN is being appended to the head.

Unfortunately, I keep receiving the error 'html2canvas is not defined'. Does anyone have an idea what might be causing the issue? Thank you in advance for any support you can provide.

$('head').append(`<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.0/html2canvas.min.js" integrity="sha512-UcDEnmFoMh0dYHu0wGsf5SKB7z7i5j3GuXHCnb3i4s44hfctoLihr896bxM0zL7jGkcHQXXrJsFIL62ehtd6yQ==" crossorigin="anonymous"
    referrerpolicy="no-referrer"></script>`);
    
html2canvas(document.querySelector("body")).then(canvas => {
document.querySelector("#capture-box").appendChild(canvas)
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

when you do

$('head').append(`<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.0/html2canvas.min.js" integrity="sha512-UcDEnmFoMh0dYHu0wGsf5SKB7z7i5j3GuXHCnb3i4s44hfctoLihr896bxM0zL7jGkcHQXXrJsFIL62ehtd6yQ==" crossorigin="anonymous"
    referrerpolicy="no-referrer"></script>`);

it dynamically adds* the script to head

*just adds, script is not loaded / executed.

before it could download and execute and set window.html2canvas your next line of code got executed. and it didnt find html2canvas so it failed

solution:

if you are running it via console. wait for script to load then run next set of code

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda