title: How do I use the canvas drawWindow function in an addon created using the addon sdk?
body: <p>I've create a Firefox addon using the <a href="https://addons.mozilla.org/en-US/developers/docs/sdk/latest/" rel="nofollow noreferrer">addon sdk</a>. I'm trying to use the <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/Graphics/Drawing_graphics_with_canvas#Rendering_Web_Content_Into_A_Canvas" rel="nofollow noreferrer">canvas drawWindow</a> function.</p>
  
  <p>I've got the following code to use the function, where ctx refers to a canvas context, that I got with <code>canvas.getContext("2d")</code>.</p>
  
  <pre><code>ctx.drawWindow(window, 0, 0, 100, 200, "rgb(255,255,255)");
  </code></pre>
  
  <p>When I run this code, within a script that is attached using</p>
  
  <pre><code>tabs.activeTab.attach({
      contentScriptFile: data.url("app.js") // app.js contains the above line of code
  });
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>TypeError: ctx.drawWindow is not a function
  </code></pre>
  
  <p>This error does not occur when I call functions like strokeRect and fillRect on the same ctx object.</p>
  
  <p>The docs on <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/Graphics/Drawing_graphics_with_canvas#Rendering_Web_Content_Into_A_Canvas" rel="nofollow noreferrer">this page</a> says you need chrome privileges to use the code, so that may be issue. I would expect a different error, based on the <a href="https://mxr.mozilla.org/mozilla/source/content/canvas/src/nsCanvasRenderingContext2D.cpp#2352" rel="nofollow noreferrer">code</a> for the function.</p>
  
  <p>I found out that I can chrome privileges in my addon using <a href="https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/chrome.html" rel="nofollow noreferrer">this</a>, but what would I do next to use ctx.drawWindow?</p>
  
  <p>Also, when I ran the code in <a href="https://stackoverflow.com/questions/15961636/override-firefox-insecure-warnings-with-aboutconfig">this question</a>, from a scratchpad on a page, rather than from an addon,  rather than a "Error: The operation is insecure", I get the same "Exception: ctx.drawWindow is not a function".</p>
  
  <p>So, basically what I'm asking is, how would I go about use canvas drawWindow in addon created using the addon sdk?</p>
  
  <p><strong>Edit:</strong> I'm trying to do this because I need a method to access individual pixels of the rendered page. I'm hoping to draw the page to canvas, then access the pixel using <a href="https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D#getImageData%28%29" rel="nofollow noreferrer">getImageData</a>. If there are other methods of doing accessing individual pixels (in an Firefox addon), that would be helpful too.</p>