Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
'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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!