Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone node: Setting className for SVG element raises error #1868

Closed
2 tasks done
KagamiChan opened this issue Jun 1, 2019 · 31 comments
Closed
2 tasks done

Clone node: Setting className for SVG element raises error #1868

KagamiChan opened this issue Jun 1, 2019 · 31 comments

Comments

@KagamiChan
Copy link

Please make sure you are testing with the latest release of html2canvas.
Old versions are not supported and issues reported for them will be closed.

Please follow the general troubleshooting steps first:

  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

Setting className for SVG element will raise error, here's some stack trace, I'm using the non minified js version. I thinks the reason is probably I'm using fontawesome 5 SVG icon

MY_PROJECT_PATH/lib/html2canvas.js:5304 Uncaught (in promise) TypeError: Cannot assign to read only property 'className' of object '#<SVGSVGElement>'
    at DocumentCloner.resolvePseudoContent (VM4414 html2canvas.js:5304)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5200)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at DocumentCloner.cloneNode (VM4414 html2canvas.js:5207)
    at new DocumentCloner (VM4414 html2canvas.js:5006)
    at VM4414 html2canvas.js:6900
    at step (VM4414 html2canvas.js:83)
    at Object.next (VM4414 html2canvas.js:64)
    at VM4414 html2canvas.js:57
    at new Promise (<anonymous>)
    at __awaiter (VM4414 html2canvas.js:53)
    at renderElement (VM4414 html2canvas.js:6857)
    at html2canvas (VM4414 html2canvas.js:6854)

Specifications:

  • html2canvas version tested with: 1.0.0-rc3
  • Browser & version: Electron 4 / Chromium 69
  • Operating system: macOS
@bguyan
Copy link

bguyan commented Jun 5, 2019

Im getting the same problem

@NanChen6
Copy link

NanChen6 commented Jun 5, 2019

getting the same error
Uncaught (in promise) TypeError: Cannot assign to read only property 'className' of object '#'

@sunnyqinghuan
Copy link

getting the same problem
TypeError: Cannot assign to read only property 'className' of object '#'

@sagarp2901
Copy link

I updated html2canvas to latest version 1.0.0-rc3 and started seeing this issue.

Console Error:
core.js:1673 ERROR Error: Uncaught (in promise): TypeError: Cannot assign to read only property 'className' of object '[object SVGSVGElement]'
TypeError: Cannot assign to read only property 'className' of object '[object SVGSVGElement]'
at DocumentCloner.resolvePseudoContent (html2canvas.js:5304)
at DocumentCloner.cloneNode (html2canvas.js:5200)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at DocumentCloner.cloneNode (html2canvas.js:5207)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
at ZoneDelegate.push.../../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:3811)
at ZoneDelegate.push.../../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push.../../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
at push.../../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:502)
at ZoneTask.invoke (zone.js:487)

@eralvarez
Copy link

Hello guys, 1.0.0-alpha.12 works just fine

@nvgopi
Copy link

nvgopi commented Jun 18, 2019

Hello guys, 1.0.0-alpha.12 works just fine

Thanks. It worked for me.

@aosatinsky
Copy link

Same problem here

@DMPR-dev
Copy link

I caught this error with the text: Torten dekorieren mit Fondant - 6 süße Inspirationen

Probably it's related to this word -> süße, got fixed once I removed it

@moosetunes
Copy link

moosetunes commented Jul 15, 2019

Latest non-min doesn't work for me regarding same issue. 1.0.0-alpha.12 didn't help either.

Update: Removing references to modernizr allowed me to get latest html2canvas to work. Cheers.

@ahardin13
Copy link

This issue occurs for me when there is a <rect> element. I've linked a possible fix I'm trying.

@KyleTraynor
Copy link

I'm having the same problem. I tried 1.0.0-alpha.12 and v1.0.0-rc.3

@subramanya4shenoy
Copy link

Did not work for me, any solutions will be appreciated

@nora-white
Copy link

I'm also receiving the same error. Only seems to occur with rc.2 and rc.3 releases. I want to update to rc.3 to fix an issue with font-family not displaying correctly, but then exporting svgs breaks with certain elements. I've reverted to rc.1. Running Chrome on Mac.

@subramanya4shenoy
Copy link

As it was beta and alpha, I took their js file and included it in my angular project. + before calling the html2canvas method I ran this method out side the ngZone.
Kind of fixed the issue, U can try as well u can change the code as per your need

@FabioGuerreiro
Copy link

I'm also receiving the same error. Only seems to occur with rc.2 and rc.3 releases. I want to update to rc.3 to fix an issue with font-family not displaying correctly, but then exporting svgs breaks with certain elements. I've reverted to rc.1. Running Chrome on Mac.

I confirm that reverting to rc.1 fixed it for me as well, tested with Chrome on win10.

@kevalForever
Copy link

kevalForever commented Aug 30, 2019

Hello guys, 1.0.0-alpha.12 works just fine.
There is Issue in 1.0.0-rc.0 to 1.0.0-rc.3.
Then don't go for Latest version.

@FrantisekVrab
Copy link

FrantisekVrab commented Sep 3, 2019

Well, i dont have any SVG that is used in canvas, however i'm getting this error... (this behaviour is on chrome, it works on FF). - 1.0.0-rc.3

tibdevelopment pushed a commit to TIBHannover/orkg-frontend that referenced this issue Sep 27, 2019
because the latest version raise this issue niklasvh/html2canvas#1868
@ngspinu
Copy link

ngspinu commented Oct 3, 2019

This is still an issue on: 1.0.0-rc.5.
Any chance of getting it fixed?

@subramanya4shenoy
Copy link

subramanya4shenoy commented Oct 3, 2019 via email

@CoveMB
Copy link

CoveMB commented Oct 7, 2019

Hey!

I had the same problem in a React app.

I had some FontAwesomeIcon on my page, removing them fixed the problem.

(even if the font icons were not in the selected element that I wanted to canvas)

@hal1984
Copy link

hal1984 commented Oct 15, 2019

I have created a pull request that fix this error.

#2034

@rafaelncarvalho
Copy link

Any news about the PR?

@maxaqquepucho
Copy link

maxaqquepucho commented Dec 17, 2019

I have the same issue with html2canvas: 1.0.0-rc.5" in chrome Version 78.0.3904.108 (Official Build) (64-bit)

html2canvas.js?c0e9:5333 Uncaught (in promise) TypeError: Cannot assign to read only property 'className' of object '#<SVGSVGElement>'
    at DocumentCloner.resolvePseudoContent (html2canvas.js?c0e9:5333)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5228)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)
    at DocumentCloner.cloneNode (html2canvas.js?c0e9:5235)

@kevalForever
Copy link

use dom-to-image API For JS,Angular Which is better than this.

@KagamiChan
Copy link
Author

@maxaqquepucho It's because the fix is not shipped

@niklasvh could you help create a new release?

@lemmingapex
Copy link

@niklasvh, will you please release v1.0.0-rc.6 with this fix? What do you need to make this happen soon?

@lemmingapex
Copy link

lemmingapex commented Feb 26, 2020

@niklasvh, the community using this library expects more frequent updates than you are providing. (>3 months of inactivity) If you are unable to maintain this library on your own, please add some prominent contributors such as @andyedinborough and @cobexer as collaborators: https://github.com/niklasvh/html2canvas/settings/access. Maybe they can provide the maintenance and releases that this library needs. Thank you.

@mhmdtshref
Copy link

@niklasvh This guy has been cloned the repo of the package, modify it, and he deployed it here: https://www.npmjs.com/package/@trainiac/html2canvas

Thank you @niklasvh <3

@BlackHacks
Copy link

BlackHacks commented Mar 24, 2020

Thank you @mhmdtshref
Moving to https://www.npmjs.com/package/@trainiac/html2canvas works fine and solves this problem.
@niklasvh seems to refuse or is unwilling to fix this package.

@Krishank-Tripathi
Copy link

@niklasvh Sir please note that this issue is still raising for version ^1.0.0-rc.5 please open this issue or resolve it by your side
Env...
React @16+
Google Chrome
Cause of issue : while rendering dom
use case :

`printDocument(e){
e.preventDefault();
const input = document.getElementById('releaseDiv');
html2canvas(input)
.then((canvas) => {
.........
});
}

// init
this.printDocument.bind(this);

`

@lzhoucs
Copy link

lzhoucs commented Jun 30, 2020

I ran into the same issue and can confirm the fix in the latest master branch works for me. Hopefully 1.0.0-rc.6 can be released soon, in the meanwhile I published my fork on npm containing the fix to unblock myself. If anyone is interested, use yarn add @lzhoucs/html2canvas to install, and import html2canvas from "@lzhoucs/html2canvas"; to import.

oliveira-gust pushed a commit to oliveira-gust/html2canvas that referenced this issue May 24, 2021
…es error (niklasvh#2079)

* fix: niklasvh#1868 Clone node, Setting className for SVG element raises error

* fix: svg element type information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.