Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

HTMLElement or SVGElement in Chrome #250

Open
canonex opened this issue Jun 16, 2020 · 1 comment
Open

HTMLElement or SVGElement in Chrome #250

canonex opened this issue Jun 16, 2020 · 1 comment

Comments

@canonex
Copy link

canonex commented Jun 16, 2020

hi,
I have in the HTML:

<object id="myid" data="mySvg.svg" height="100%" ></object>

Then, to get the element:

let svgObject = document.getElementById( "myid" );
let svgDom = svgObject.contentDocument.querySelector("svg");

saveSvgAsPng(svgDom, "myname.png");

This works in Firefox but in Chrome I receive an error:
Error: an HTMLElement or SVGElement is required; got [object SVGSVGElement]

svgDom should be an Element...

I don't understand if it's my mistake, a browser problem or a problem with saveSvgAsPng. How can I solve the problem?

Thank you,
Riccardo

@canonex
Copy link
Author

canonex commented Jun 16, 2020

After further investigation I noticed that SVGSVGElement is fully compatible with saveSvgAsPng.

The only real problem is on the preliminary check:
const isElement = obj => obj instanceof HTMLElement || obj instanceof SVGElement;

Of course [object SVGSVGElement] will fail the test.
I can't figure out what this object is instance of but adding a check on nodeName:
const isElement = obj => obj instanceof HTMLElement || obj instanceof SVGElement || obj.nodeName == "svg";

Probably this is not the best way but makes the same code works for Firefox and Chrome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant