Skip to content

v3.3.0 Add adjustClonedNode and useCredentialsFilters

Latest
Compare
Choose a tag to compare
@IDisposable IDisposable released this 14 Feb 18:04
dd1de93

What's Changed

  • Expose ability to adjust the cloned node before generating image via adjustClonedNode option. by @IDisposable in #164

  • Add ability to select what external resources require useCredentials via listing URLs in useCredentialsFilters option by @tmmschmit in #156

  • Bumps dev packages up to current

  • Cleaned a bit of lint

adjustClonedNode Hook

You may now specify a call-back to be invoked on each node as we clone them so you can adjust the nodes in any way needed before the conversion. The handler is passed in the options as adjustClonedNode which is a function that gets the original node, the cloned node, and a boolean that says if we've cloned the children already (so you can handle either before or after)

Sample use (with this package source inlined) in this fiddle:

const adjustClone = (node, clone, after) => {
  if (!after && clone.id === 'element') {
    clone.style.transform = 'translateY(100px)';
  }
  return clone;                   
}

const wrapper = document.getElementById('wrapper');
const blob =  domtoimage.toBlob(wrapper, { adjustClonedNode: adjustClone});

useCredentialsFilters URL list

Added a new option useCredentialsFilters which will take a string/Regex array and only share the credentials with the URLs that match an entry in this array. This helps avoid CORS errors.

Full Changelog: v3.2.0...v3.3.0