<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>dekstop weblog : CSS-Bug in Safari&#39;s Canvas Implementation?</title>
    <link>http://dekstop.de/weblog/2005/09/safari_canvas_bug/</link>
    <description><![CDATA[While playing around with the cool new &lt;canvas&gt;-tag, I found that Safari seems to have a bug in its canvas implementation -- it stops working as soon as you link an external style sheet to the HTML, even if the style sheet is empty. I'm not sure yet if this]]> ...</description>
    <dc:language>en-us</dc:language>
    <dc:rights>Copyright 2005 Martin Dittus</dc:rights>
    <lastBuildDate>Wed, 07 Sep 2005 22:17:43 GMT</lastBuildDate>
    <generator>MicroLinks 5.6 (dekstop.de)</generator>
    <managingEditor>public&#64;dekstop&#46;de</managingEditor>
    <webMaster>public&#64;dekstop&#46;de</webMaster>



    <item>
      <title>CSS-Bug in Safari&apos;s Canvas Implementation?</title>
      <link>http://dekstop.de/weblog/2005/09/safari_canvas_bug/</link> 
      <description><![CDATA[<p>While playing around with the cool new <a href="http://www.whatwg.org/specs/web-apps/current-work/#canvas">&lt;canvas&gt;-tag</a>, I found that Safari seems to have a bug in its canvas implementation -- it stops working as soon as you link an external style sheet to the HTML, even if the style sheet is empty.</p>

<p>I'm not sure yet if this is an actual bug or if I'm overlooking something; but then, nobody is actually using &lt;canvas&gt; on styled production sites, and all the demos I saw online are using unstyled HTML, so it's not that unreasonable that it's not a well-known bug.</p>

<p><b>Update:</b> I <a href="http://www.opendarwin.org/pipermail/webkit-dev/2005-September/000414.html">posted</a> this to the webkit-dev mailing list and got a reply from Dave Hyatt:</p>

<blockquote>
<p>Yeah, clearly a bug in our code because we defer renderobject
creation until stylesheets are loaded.  Firefox doesn't exhibit the
bug because it blocks its HTML parser while waiting for stylesheets
to load.  We don't.  File it in bugzilla.</p>
</blockquote>

<p>So here it is: my first webkit bug, #<a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=4884">4884</a>. (Note the palindromic nature of the bug ID.)</p>

<p><b>Update:</b> 2006-04-10 -- it's <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=4884">fixed</a>!</p>


<h3>Test Cases</h3>

<p>I created three simple test cases:</p>

<ul>
<li><a href="http://dekstop.de/weblog/2005/09/safari_canvas_bug/test1.html">Test 1</a> - simple page with external CSS, and all canvas drawing done inline</li>
<li><a href="http://dekstop.de/weblog/2005/09/safari_canvas_bug/test2.html">Test 2</a> - simple page without external CSS, and all canvas drawing done inline</li>
<li><a href="http://dekstop.de/weblog/2005/09/safari_canvas_bug/test3.html">Test 3</a> - simple page with external CSS, and all canvas drawing done via <tt>onload()</tt></li>
</ul>

<p>Both Safari 2.0.1 (412.5) and the most recent <a href="http://webkit.opendarwin.org/">WebKit</a> CVS version show
the same behavior:</p>

<ul>
<li>test 1 doesn't work (blank canvas)</li>
<li>test 2 works (canvas filled black)</li>
<li>test 3 works (canvas filled black)</li>
</ul>

<p>Just to be sure I checked with a recent <a href="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla1.8/">Firefox 1.5 beta candidate</a>, and all three test cases worked fine (canvas filled black).</p>

<p>Please test this in your version of Safari and <a href="/contact/">let me know</a> how it went. If this is indeed a bug in Safari, we should file this as a bug with Apple.</p>

<h4>styles.css</h4>
<pre>
/*
    empty file
*/
</pre>

<h4>test1.html</h4>
<pre>
&lt;html&gt;
&lt;head&gt;
    &lt;link rel="stylesheet" href="styles.css" type="text/css"&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;canvas id="mycanvas" width="400" height="200"&gt;&lt;/canvas&gt;
&lt;script type="application/x-javascript"&gt;
var canvas = document.getElementById("mycanvas");
var ctx = canvas.getContext("2d"); 
ctx.fillRect(0, 0, canvas.width, canvas.height);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>

<h4>test2.html</h4>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;canvas id="mycanvas" width="400" height="200"&gt;&lt;/canvas&gt;
&lt;script type="application/x-javascript"&gt;
var canvas = document.getElementById("mycanvas");
var ctx = canvas.getContext("2d"); 
ctx.fillRect(0, 0, canvas.width, canvas.height);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>

<h4>test3.html</h4>
<pre>
&lt;html&gt;
&lt;head&gt;
    &lt;link rel="stylesheet" href="styles.css" type="text/css"&gt;
&lt;script type="application/x-javascript"&gt;
function draw(){
    var canvas = document.getElementById("mycanvas");
    var ctx = canvas.getContext("2d"); 
    ctx.fillRect(0, 0, canvas.width, canvas.height);
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="draw()"&gt;
&lt;canvas id="mycanvas" width="400" height="200"&gt;&lt;/canvas&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>]]></description>
      <dc:creator>Martin Dittus</dc:creator>
      <category>osx</category>
      <category>software</category>
      <category>stuff</category>
      
      <guid isPermaLink="true">http://dekstop.de/weblog/2005/09/safari_canvas_bug/</guid>
      <pubDate>Wed, 07 Sep 2005 22:17:43 GMT</pubDate>
    </item>
  </channel>
</rss>

