New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 662373 link

Starred by 2 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

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);

 
Argh, some typos in the code ... this is to be supposed a nested reader.onloadend function with a nested img2.onload containing an img.onload function.
Components: Blink>Canvas
Labels: Needs-Feedback
martin.felke@: could you please attach a test file? Or maybe create a jsfiddle? Thank you.
Cc: xidac...@chromium.org
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.
firefox_test.png
290 KB View Download
chrome_test.png
141 KB View Download

Comment 6 by junov@chromium.org, Nov 10 2016

Cc: pdr@chromium.org junov@chromium.org
Components: -Blink>Canvas Blink>SVG
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.


Comment 7 by f...@opera.com, 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.)
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 :)

Comment 9 by f...@opera.com, Nov 10 2016

Labels: -Needs-Feedback
Status: Available (was: Unconfirmed)
Summary: Recognize the (X)HTML namespace as a supported extension in requiredExtensions (was: Result of canvas.toDataURL() seems to be a truncated base64 string)
I guess we should make this a bug about whether or no to recognize (X)HTML like Gecko does.
Project Member

Comment 10 by sheriffbot@chromium.org, Nov 10 2017

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
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
Cc: mrunal.k...@intel.com
Labels: -Hotlist-Recharge-Cold
Status: Available (was: Untriaged)
This might be a good bug to fix, though not super important.
Cc: -junov@chromium.org

Sign in to add a comment