3

I'm trying to use drawImage on Canvas Context in injected content script from my Chrome Extension.

  testCanvas = document.createElement('canvas');
  testContext = testCanvas.getContext('2d');
  var image = new Image();
  testContext.drawImage(image, 0, 0);

In Chrome 26 it works ok, but in dev channel (Chrome 28) this seams broken as I got this message:

Uncaught TypeError: Type error

When I move same script directly into background page, it works without any problem.

I think this can be related to some security related change but I failed to find any relevant information.

Kepi
  • 332
  • 3
  • 10

1 Answers1

7

This is a bug, you should report it. Some more testing reveals that in Chrome 28.0.1498.0, the Image constructor does not create a valid HTMLImageElement instance (as seen in the screenshot below).
This code is run in the context of a Content script. The same code works fine on regular pages and in the extension's process (background page).

To work around the problem, use document.createElement('img') instead of new Image().

.appendChild(new Image()) Error: NotFoundError: DOM Exception 8

And don't forget to report the bug at https://code.google.com/p/chromium/issues/list.

Rob W
  • 341,306
  • 83
  • 791
  • 678
  • 1
    Thanks! Bug reported at https://code.google.com/p/chromium/issues/detail?id=238071 – Kepi May 04 '13 at 20:49
  • @Kepi I've reported a new bug at https://code.google.com/p/chromium/issues/detail?id=245296. It turns out that the bug is not specific to `new Image()`, but also `Audio` and `Option`. – Rob W May 30 '13 at 15:31