bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.69k stars 531 forks source link

node.classList.includes is not a function #324

Open lokomass opened 1 year ago

lokomass commented 1 year ago

Hi,

I'm trying to exclude a div from my component before converting in jpeg.

const filter = (node) =>{ const exclude = ['add-button'] return (!exclude.some(classname => node.classList.includes(classname))) }

And my export :

const input = document.getElementById('scheduler').firstElementChild.lastElementChild htmlToImage.toJpeg(input, { filter: filter, backgroundColor: '#fff' }).then(function(data) { ...

I have the error :

Uncaught (in promise) TypeError: node.classList.includes is not a function

Thanks for helping

vivcat[bot] commented 1 year ago

👋 @lokomass

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

jkl851 commented 1 year ago

Hello,

try this.

const filter = (node) =>{ const exclude = ['add-button'] return (!exclude.some(classname => node.classList.contains(classname))) }

lokomass commented 1 year ago

Yes it works ! Secondly, I want to replace a node (background of the node) without any visible change on HTML page. I've try this but its not work.

const Filter = (node) => {
    return(
      (node.classList)
        ? node.classList.contains('add-button')
          ? null
          : node.classList.contains('appointment-selected')
            ? node.cloneNode(true).style.removeProperty('background-color') //here I want remove property backgroundColor on clone's node, and return it...
            : node
        : node
    )
  }
...
htmlToImage.toJpeg(input, {
      filter: Filter,
    }).then(function(data) {
      ...
    })

Do you have an idea please ?

Thanks a lots

lokomass commented 1 year ago

any idea ? thx

lokomass commented 1 year ago

Does anybody can help me please ?