Recognize the (X)HTML namespace as a supported extension in requiredExtensions
Reported by
martin.f...@googlemail.com,
Nov 4 2016
|
|||||||||
Issue description
Chrome Version : Version 49.0.2623.75 (64-bit) Linux Mint 17.3
URLs (if applicable) :
Other browsers tested: Firefox
Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
Safari: Not tested
Firefox: OK 49.0.2
IE: Not tested
What steps will reproduce the problem?
(1) Well, this is probably not so simply to reproduce with a smaller code snippet :(
Will provide a code snippet under additional info below.
(2)
(3)
What is the expected result?
An SVG image is being converted to PNG and being rendered in the
summernote editor.
What happens instead?
Chrome renders just a blank image (due to shorter base64 string ?)
Please provide any additional information below. Attach a screenshot if
possible.
Basically i am trying to render html to an svg or png image. I decided to do this in 2 steps, first embedding the html into svg and converting to png afterwards.
Because i want to create non-editable images with a text on it inside the summernote editor, i cant embed the SVG directly... summernote will let me edit inside the "image" then...
So here a snippet from my code.
Furthermore when examining the base64 result strings, the chrome ones are much shorter than the firefox ones... Why is this ? is the image not drawn properly prior to doing canvas.toDataURL() or is there some issue with toDataURL() itself ?
var data = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"'+width+'\" height=\"'+height+'\">' +
// '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\">' +
'<switch>' +
'<foreignObject width=\"100%\" height=\"100%\" requiredExtensions=\"http://www.w3.org/1999/xhtml\">' +
'<div xmlns=\"http://www.w3.org/1999/xhtml\">' +
'<span style=\"$style\">My Span</span>' +
'</div>' +
'</foreignObject>' +
'<text x=\"0\" y=\"0\">Your SVG viewer cannot display html.</text>' +
'</switch>' +
'</svg>';
var blob = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
//attempt to convert to png here...
//because Htmlpurifier didnt let the img pass... :)
canv = document.createElement('canvas');
canv.width = width;
canv.height = height;
ctx = canv.getContext('2d');
img2 = new Image();
img2.crossOrigin='Anonymous';
var reader = new window.FileReader();
reader.onloadend = function () {
img2.onload = function() {
ctx.globalAlpha = 1.0;
ctx.drawImage(img2, 0, 0);
var img = new Image();
img.crossOrigin='Anonymous';
img.onload = function() {
//insert img to summernote editor here
}
img.src = canv.toDataURL('image/png;charset=utf-8');
// should be base64...
img.alt = 'alternative value'
img.setAttribute('class', 'myclass');
};
img2.crossOrigin='Anonymous';
img2.src = reader.result;
reader.readAsDataURL(blob);
,
Nov 9 2016
,
Nov 9 2016
martin.felke@: could you please attach a test file? Or maybe create a jsfiddle? Thank you.
,
Nov 9 2016
,
Nov 10 2016
Ok, i made a jsfiddle here: https://jsfiddle.net/f8q6oe5d/3/ I also added 2 screenshots, the first showing how it looks in firefox and the second how it looks in chrome. Note, in Firefox you will see a blue-ish Image with "My Span" label on it, and a longer base64 string as control output. In chrome you see no image and a shorter base64 string.
,
Nov 10 2016
In that fiddle, if you add img2 to the DOM, you'll see that it is coming out blank. It seems that the problem here is that the SVG is failing to render in Chrome. There is probably something about the svg that is not compatible with Chrome. Re-classifying this as an SVG issue. Also, even without the SVG rendering problem, the solution you are trying to implement will not work in Chrome, I think. SVG content with a <foreignObject> tag will taint the canvas as if it were cross-origin. Which means trying to call toDataURL or toBlob on the canvas to get a png will throw a SecurityError DOM exception. This is a longstanding limitation in Chrome. See issue 294129.
,
Nov 10 2016
The "primary" issue probably with 'requiredExtensions': If it's a non-empty list we'll fail the test on it and hence consider the next candidate in the <switch>. (And the <text> ought to have a y > 0 to give it a better chance of being visible in that case.)
,
Nov 10 2016
Ah ok, well i solved it fortunately a bit differently in the meantime... i pre-generate the base64 string like shown here in firefox and put it onto the server (inside a certain database column) and deliver the finished base64 string down to the client, embedded into the HTML (there are only a limited number of different images which need to be created this way, so its applicable there). Furthermore, with the FileReader approach i was trying to circumvent the tainted canvas stuff, which apparently doesnt work either. Thank you for the info anyway :)
,
Nov 10 2016
I guess we should make this a bug about whether or no to recognize (X)HTML like Gecko does.
,
Nov 10 2017
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue. Sorry for the inconvenience if the bug really should have been left as Available. If you change it back, also remove the "Hotlist-Recharge-Cold" label. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Nov 10 2017
This might be a good bug to fix, though not super important.
,
Jul 25
|
|||||||||
►
Sign in to add a comment |
|||||||||
Comment 1 by martin.f...@googlemail.com
, Nov 4 2016