Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Screenshot Plugin [closed]

Does anyone have a good tutorial on creating a simple screen capture plugin for Firefox and/or Chrome?

like image 562
Andres Avatar asked Jun 05 '11 16:06

Andres


2 Answers

Here's a snippet for Firefox. In your overlay XUL add:

    <html:canvas id="my-canvas" style="display: none;" />

Then in your overlay javascript, listen for new document loads and this snippet will save the screenshot to a file:

    var canvas = document.getElementById('my-canvas');
    var context = canvas.getContext('2d');

    //Find the window dimensions
    canvas.height = doc.defaultView.innerHeight; //doc is the content document that you listened for
    canvas.width = doc.defaultView.innerWidth;

    context.drawWindow(doc.defaultView, 0, 0, canvas.width, canvas.height, "rgba(0,0,0,0)");

    //Create a data url from the canvas
    var dataUrl = canvas.toDataURL("image/png");

Read about nsiIOService and nsiWebBrowserPersist to create an nsiURI from data url and then persist it locally.

like image 93
Amir Nathoo Avatar answered Sep 30 '22 12:09

Amir Nathoo


There's a sample extension on how to do this with Chrome http://code.google.com/chrome/extensions/dev/samples.html#e1697cacebad05218798bf3e8a0f724517f0e8c3

like image 29
MrD Avatar answered Sep 30 '22 12:09

MrD