Handsontable and html2canvas - cannot set property 'id' of null

Tags: #<Tag:0x00007fbea5f094c8>

Hello,

I implemented html2canvas for downloading printscreen of handsontable by clicking on button. If I click first time everything is ok but after second time I got a following error:

Uncaught TypeError: Cannot set property 'id' of null
    at HTMLButtonElement.capture

at

   body.id = 'capture';`

so body is null I don’t understand why.
Demo https://jsfiddle.net/janzitniak/bn4Lrcy3/9/

Jan

Hi @jan.zitniak

I do not know how html2canvas works but it seems that it is recreating the table.
We can see that when

const body = document.querySelector('#example1');

is moved outside the capture method it adds additional instances of Handsontable https://jsfiddle.net/AMBudnik/wd3asLvh/

Dear @aleksandra_budnik,

thank you for you advice, I found a workaround for that (using index for added canvas), is available at https://jsfiddle.net/janzitniak/bn4Lrcy3/46/

Regards
Jan :slight_smile:

Great. Now it works as expected.
Thank you for sharing :slight_smile:

1 Like

You are welcome! :slight_smile: