roachfiend.com

  • firefox extensions
  • tutorials
  • faq
  • December 27, 2009

    How to write Google Chrome extensions

    Filed under: tutorials — Eric @ 4:37 pm

    Google Chrome is the latest browser to let users add, edit and contribute their own coding efforts. Extensions or plugins are what makes web browsers so handy and extendable. Firefox users have long known this– Google Chrome’s extension capabilities are so far not as well known, but hopefully will soon have a synergistic effect on both applications. More publicity for competing products ensures a wide array of choices.

    Google has their own “Getting Started” tutorial which is extremely helpful. You can get your feet wet here:

    http://code.google.com/chrome/extensions/getstarted.html

    Note that at this point, you will need the Developer version of Chrome. You can grab it here:

    http://www.chromium.org/getting-involved/dev-channel

    Structure

    The Chrome extension’s backbone is the manifest file. Specifically, manifest.js. It describes what will be packaged in the extension and describes the name, a brief description, whatever explicit permissions you grant it, and other details. The fields in full are described here:

    http://code.google.com/chrome/extensions/manifest.html

    The most basic Chrome extension only requires a manifest.js file and another javascript file. For this tutorial, we will use a pre-existing Firefox extension, which is a very basic one- Allow Right Click. This is simply a file that prevents attempts to inhibit the context menu from activating. This is seen on some web sites as a protection scheme of sorts, to try and prevent a user from saving an image or viewing the source. You can get around either of those by simply viewing the cache, but it does come in handy sometimes.

    You can test out the effectiveness of the scripts here:

    http://www.dynamicdrive.com/dynamicindex9/noright.htm
    http://www.dynamicdrive.com/dynamicindex9/noright2.htm
    http://www.dynamicdrive.com/dynamicindex9/noright3.htm

    Function

    Here is the bypass script in its entirety:

    void(document.ondragstart=null);
    void(document.oncontextmenu=null);
    void(document.onselectstart=null);
    void(document.onclick=null);
    void(document.onmousedown=null);
    void(document.onmouseup=null);
    void(document.onbeforecopy=null);
    void(document.onbeforecut=null);
    void(document.oncopy=null)

    Save this in a file by itself as rightclick.js.
    This issues a series of null statements that will “void out” attempts to manipulate your context menu. The manifest file for this particular extension is below, which you can save as manifest.js, editing it as desired:


    {
    "authors": [ {
    "email": "ehamiter@gmail.com",
    "name": "Eric Hamiter"
    } ],
    "content_scripts": [ {
    "js": [ "rightclick.js" ],
    "matches": [ "http://*/*" ]
    } ],
    "description": "Bypass right-click prohibited pages.",
    "homepage": "http://erichamiter.com",
    "update_url": "http://erichamiter.com/chrome/updates.xml",
    "name": "Allow Right Click",
    "version": "1.0"
    }

    The first part is self-evident. The matches section will match any web page- in this case that is precisely what we want. In some cases, though, if you only want it to activate on certain pages, you can limit it here.

    As of now, you cannot use a wildcard domain for the matches section- say, images.google.*. This would be very handy instead of matching images.google.com, images.google.co.uk, et cetera. You can get around this limitation by using a javascript trick in your script:


    if (location.hostname.indexOf("images.google.") == 0) {

    script here

    }

    You’ll also notice an update section. This works the same as a Firefox extension- it checks an xml file on your server to see if there is a newer version. The updates.xml relevant section on my server is below:


    <gupdate protocol="2.0">
    <app appid="fhbfcblhfgbemciedggloeeekecmlhcf">
    <updatecheck codebase="http://erichamiter.com/chrome/allowrightclick.crx" version="1.0"/>
    </app>
    </gupdate>

    The app appid is generated by Chrome after you package the extension, which I will describe in a bit.

    So, we have rightclick.js and manifest.js. Put both of these files in a single folder, named appropriately- “allowrightclick” or something similar. Simple is the best option.

    In your Chrome browser, type in this address:

    chrome://extensions/

    Or alternatively, click on the wrench icon and select Extensions. You should see a screen similar to this one:

    Extension screen

    Toggle the developer mode selection, and you should see these choices: Load unpacked extension, Pack extension, Update extensions now.

    Extension screen choices

    For now, we want the first option: Load unpacked extension. Select it and it will prompt you for the location of your files. Select your folder and hit ok. I wound up with this (your ID will be random and unique, just like you):

    Allow Right Click unpacked

    Now try out the previous test sites and see if it’s working:

    http://www.dynamicdrive.com/dynamicindex9/noright.htm
    http://www.dynamicdrive.com/dynamicindex9/noright2.htm
    http://www.dynamicdrive.com/dynamicindex9/noright3.htm

    If you can successfully right-click and get a menu, it’s working! So, to pack up the extension as a bona-fide Chrome extension, you just visit your extension page again, and select “Pack extension.” Select the previous folder, and it will prompt you for the extension root and directory and an optional private key:

    Allow Right Click packed

    Select your directory again, and you do not need the private key file. If you edit or update the extension, then you can add the private key file which will generate in a moment, and then future updates will retain the same ID.

    Chrome will pop up an alert box reminding you that you should keep your key safe:

    Extension safety

    It saves the two files (extension.crx and extension.pem) in the parent folder of your working extension directory. The .crx file is your new Chrome extension, ready to distribute and to be added to any Beta or Developer version of Chrome. The .pem file is your personal key file and you should keep it safe somewhere. This will be needed to update the file to maintain the same ID.

    To test out the new file, uninstall your unpacked extension, and open your .crx file with Chrome. Control-O will open a file; navigate to your .crx file; hit continue, then install. You should get a notice that it has installed successfully.

    There are a few different places for trying out new extensions:

    https://chrome.google.com/extensions
    http://www.chromeextensions.org/
    http://www.chromeplugins.org

    There are a small but steadily growing number of cool Chrome extensions out there. Create one today and let the world know about it.


    August 20, 2006

    Hack the crap out of Firefox for some useful error pages

    Filed under: tutorials — Eric @ 12:38 am

    I tried to get this to work in an extension, but it ain’t happening.

    Update! It is now a working extension, mostly thanks to Nick, developer of InfoLister, and master of jedi XUL tricks. I’ll leave the original article as below for informational purposes.

    [...Would you like to know more?]


    January 2, 2006

    If you happen to have a Linksys WRT54G wireless router…

    Filed under: tutorials — Eric @ 1:43 pm

    …and you use an alternative firmware, say, DD-WRT, and you tend to have to reset your modem and router a lot, then I have a possible fix for you. If you don’t know what the hell it is I’m talking about, then let me explain.

    If you have the router in question:


    …and the version number of it is 1-4, then you can upgrade the firmware in it to a 3rd-party one, which will allow you to configure a bunch of things that you were previously not able to. This is a cool thing, because you can fine-tune your setup, and add in other features like static DHCP leases. That means, for example, that you can always assign the same IP address to one of your laptops so you can keep your port forwarding options on it the same, but if you take your laptop down the road to Joe’s Wi_Fi spot, it will automatically grab it without you having to re-configure anything. It’s handy.

    So, once you do it, because of the new options and wonderful toys, your once-stable connection might be dropping in and out a bit more than you would like. Some of the default settings on DD-WRT were not getting along with my modem at all. So much, in fact, that it made me question the modem’s general health, so I replaced it with a newer one. Same problems! So after scouring the internet for other people suffering from my connection’s problems, here’s a cluster of things I changed which resulted in a very solid configuration, and I have had zero dropped connections since, where they used to be one per every few hours.

    µTorrent has a tip to help:

    Special note for users with Linksys WRT54G/GL/GS routers, there are severe problems with them when running any P2P app (read for fix)


    The default firmware for Linksys (and all replacement firmwares except for one) have a severe problem where they track old connections for FIVE days, which causes the router to hang when using P2P apps, or any software that generates a lot of connections. DHT only aggravates the situation because of the number of connections it generates.


    Linksys has yet to address this issue, but there is a fix. If you use alternative firmware, you can put in a start-up script to fix this problem. DD-WRT and HyperWRT support custom start-up scripts. I am not responsible if you screw up your router, so you do this at your own risk. This page has instructions on recovering a bricked router.

    I’ll walk you through how to do it with DD-WRT- the page has instructions for both DD-WRT and HyperWRT if you run that one instead. Note that these are my settings and are working great for me, which means that it probably will be for you too, but I can’t guarantee it. I advise you to do some more research about doing this if I’ve said at least one thing that you’re not toally sure about.


    Go to Admin > Services and choose to enable SSHD. Save settings.
    Download putty.exe if you don’t have it, and run it.

    For host name, put in your router’s IP address. The default is 192.168.1.1. Leave the port at 22, and make sure the protocol is SSH. Hit open.
    Login as root.
    root@192.168.x.x’s password is your router’s password. If you’ve never changed it from the default setting, it’s admin.

    At the ~ # prompt, enter the following (copy and paste one line at a time by copying a line below, then pasting it into putty by right clicking on putty’s screen, and hitting enter after each line):

    nvram set rc_startup="
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
    echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
    echo '600 1800 120 60 120 120 10 60 30 120' > /proc/sys/net/ipv4/ip_conntrack_tcp_timeouts
    "
    

    Then you’ll be back to the ~ # prompt. Type in

    nvram commit
    reboot
    

    Then the system will tell you The system is going down NOW !! Sending SIGTERM to all processes.That’s fine. Once it reboots, you can close putty and go to your web management console.

    Go to your Management tab, and scroll down to IP Filter Settings. Change the Maximum Ports value to 4096 and the TCP and UDP to 300 each. Save settings.
    Go to the Setup tab, and under Basic Setup, note the STP setting. If you have Comcast cable, disable this.
    Under optional settings, the MTU size is set to auto. Change it to manual and enter 1392.
    Go to the Wireless tab, and then select the subheader Adavnced Settings. Change the Xmit Power to 200 80.

    Again, these are my settings and they work well for me. I will not take responsibility if you accidentally destroy your router trying to update it. Those that feel comfortable doing some thing like this, I urge you to try it out, it’s a noticeable increase in performance.


    December 2, 2005

    Update your extensions’ maxVersion with perl

    Filed under: tutorials — Eric @ 7:48 pm

    Whenever a new version of Firefox comes out, there are invariably a few extensions that won’t work with it. Not because the extension’s functionality is no longer suited, but because of a value that is set too low- the maxVersion. That tells Firefox that the extension is only compatible with a certain version of Firefox. You can update the extension by opening it up, and changing the maxVersion to the current Firefox version, or even higher. The easiest way to do this is to use a perl script to do it for you.

    If you don’t have perl installed on your Windows machine, it’s a free download here: ActivePerl

    It’s an easy setup, just click a few buttons, then you’re done. Then copy and paste the following into a new file and call it maxversion-updater.pl or anything, really, as long as you have the `pl` extension.

    The easiest way to find where your profile folder is this:

    Start > Run > %appdata%\Mozilla\Firefox\Profiles

    Copy the 8 digits before the `.folder` and paste them in the script below.

    - – -

    #!/usr/bin/perl

    use File::Find;
    use strict;

    # Firefox extension update script, written by Eric Hamiter
    #
    # This script will attempt to update extensions used on
    # earlier builds of Firefox by changing the maxVersion fields.
    # It will probably work, but might accidentally set
    # your house on fire. I don’t accept responsibility for what
    # might happen, so use at your own risk.
    #
    # Modify the following lines to point the variable to your
    # Firefox profile directory and specify the new Firefox version.

    my $default_folder=”xxxxxxxx.default”;
    my $new_version=”1.5″;

    # The rest of the script requires no modification.

    my $max=”em:maxVersion”;
    my $def=”$ENV{‘APPDATA’}\\Mozilla\\Firefox\\Profiles\\$default_folder”;
    my $directory=”$def\\extensions”;

    find (\&change, $directory);

    sub change
    {
    my @newMax;
    my $oldMax;

    if ( $File::Find::name =~ /\.rdf$/ ) {

    open (FILE, $File::Find::name ) or
    die “Cannot open file: $!”;

    print “\n” . $File::Find::name . “\n”;
    while ( $oldMax = ) {
    $oldMax =~ s/<$max>.*$new_version $oldMax =~ s/$max=".*"/$max="$new_version"/i;
    push(@newMax, $oldMax);
    }
    close FILE;

    open ( OUTFILE, ">$File::Find::name” ) or
    die “Cannot open file: $!”;

    print ( OUTFILE @newMax );
    close ( OUTFILE );

    undef( @newMax );
    }
    }

    - – -


    Next Page »