A Tale Of Two Bugs

Noticed two weird quirks yesterday, one in Chrome and one in Safari on iOS.

Reset Canvas on Chrome

Usually to reset the content of the canvas tag one writes:

canvas.width = canvas width;

But that doesn’t really work in Chrome: the canvas stays the same and is not cleared.

It sort of works, though, in that afterwards, if one tries to paint something on the same canvas, the new information “clears” a zone around itself.

This reminded me of the strange Chrome behavior where if you have many tabs opened, and leave them opened for a long time, when you activate them again they “repaint” the page on the screen, quite slowly (AFAIK, no other tabbed browser does this).

I suspect that Chrome has a universal “lazy” approach (in the noble sense of the term found in “lazy evaluation”): don’t do anything until you absolutely have to. There is no point in maintaining the appearance of an invisible tab in memory (of a tab that hasn’t been visible for a while); there is no point in repainting a canvas until it’s used, esp. when set to new dimensions that are the same as the old ones.

Except, there is, since resetting canvas width is the accepted method of clearing it.

The workaround:

canvas.width = canvas.width + 1;

Then Chrome feels compelled to actually repaint the canvas.

Of course if you do this often, you’ll end up needlessly enlarging the canvas; what you want to do is storing the original size and playing with it: +1 or -1 every other time.

Console in Safari

Having the console on in Safari on iOS breaks the offline capability of the app. But not always! and that’s what’s really weird: only apps launched from an icon in the dock, not apps launched from within Safari.

Here’s how to reproduce the problem:

  1. Have / make an offline app with a manifest file
  2. Verify that it works offline by launching it and reloading it from within Safari when the device is offline
  3. Add the app to the homepage
  4. Launch the app from the icon on the homepage: it works fine
  5. Set the console on from the Safari options (last line)
  6. Reload the app when offline from Safari: it works (if it worked in step 2)
  7. Launch the app from the icon on the homepage: it doesn’t work! (“Invalid argument”)
  8. Disable console and reload the app from the icon on the homepage (while still offline): it works

The workaround: I don’t know of any; just make sure the console is disabled when trying to launch an app from an icon while offline.

Thu, 15 Jul 2010 • permalink