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

inlineResources not working (fetchResource() Error: No URL passed) #170

Open
eckynde opened this issue Dec 2, 2021 · 5 comments · May be fixed by #183
Open

inlineResources not working (fetchResource() Error: No URL passed) #170

eckynde opened this issue Dec 2, 2021 · 5 comments · May be fixed by #183

Comments

@eckynde
Copy link

eckynde commented Dec 2, 2021

Before I begin, thank you for this awesome library.

inlineResources is not working:
Error stack

This error was introduced in version 0.11.5 (issue #113, fix #116). Version 0.11.4 works fine. See screenshots below.
I suspect that fetchURL doesn't know to look in xlink:href instead of href.
Therefore element.href.baseVal is undefined and it outputs No URL passed (inline.ts, line 27)

JavaScript code used
I'm using the CDN version as recommended in #135. I've tested both versions.

async function takeSVGScreenshot(){
	console.log('[IK SVG] Importing dependencies...');
	const { elementToSVG, inlineResources } = await import('https://cdn.skypack.dev/[email protected]'); // or 0.11.4
	console.log('[IK SVG] Taking snapshot...');
	const svgDocument = elementToSVG(document.querySelector('#qtlw13'));
	console.log('[IK SVG] Inlining resources...');
	await inlineResources(svgDocument.documentElement); // <-- this is where the error occurs
	console.log('[IK SVG] Serializing...');
	const svgString = new XMLSerializer().serializeToString(svgDocument);
	console.log('[IK SVG] Sending data back to server...');
	callHTMLClient( '{"Sender":"TakeSVGScreenshot", "Data":"' + svgString.replace(/\"/g, '\\"') + '"}');	
	console.log('[IK SVG] Done');
}

Version 0.11.4
image

Version 0.11.5
image
don't mind the impossible geometry :)

@eckynde
Copy link
Author

eckynde commented Dec 2, 2021

This is on Google Chrome 95. It's not an issue on Firefox 94 yet.
xlink:href was deprechated in SVG 2 (MDN, spec from 2018)

Using element.getAttribute('xlink:href') instead of element.href.baseVal works.
Using element.getAttributeNS('http://www.w3.org/1999/xlink', 'href')also works. Tested both on Chrome and Firefox.
Assigning the url to both the xlink:href and href attribute could probably also fix it (messy though).

Sadly I'm currently unable to make and test a pull request :/

@iolh
Copy link

iolh commented May 13, 2022

谢谢,这很有帮助。

@eckynde
Copy link
Author

eckynde commented Aug 2, 2022

This issue on the Inkscape issue tracker

@eckynde
Copy link
Author

eckynde commented Jul 19, 2023

@BoutValentin Thank you for writing a workaround (#183) - that would certainly work.

The original issue within Inkscape has been fixed by now (inkscape issue 620) and will be part of their release 1.3, which is going to render #113 and the corresponding pull request #116 obsolete.

Therefore I suggest undoing the changes in #116 to confirm to the SVG2.0 spec again as soon as Inkscape 1.3 has been released.

@jduvk
Copy link

jduvk commented Mar 11, 2024

Inkscape 1.3 has been released on July 23, 2023.

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.

3 participants