Solved | Uncaught (in promise) Provided element is not within a Document

While working on web-page and creating featured elements. We might have come requirement of sharing widget on social media like attached image or create screenshot of current screen for proctoring purpose.

In both scenario we need to create image on run time as data coming on page is dynamic. To take snapshot or screen capture we use html2canvas JS plugin.

While using html2canvas plugin most of user mostly who is upgrading their core from older version to newer face issue of “Uncaught (in promise) Provided element is not within a Document” 

Why it’s coming?

There are mainly 3 reasons why this issue can arise.

  1. Class or ID you are using not exist in current page DOM
  2. You are upgrading your html2canvas core.

Solution

To solve issue 1 just verify your CLASS or ID name in DOM or correct your name

If you are using latest version of html2canvas script just ensure don’t not use jQuery object in code.


Like instead of using

$(“.capture”) use document.querySelector(“#capture”) 
Seems like html2canvas has remove the support of jQuery in their latest core and added support for jqlite commands, to use jqlite you don’t require any external plugin.

Most browser have inbuilt support for jqlite commands. for more jqlite commands.

Comments Your Suggestions