⬆️ ⬇️

Writing a simple web browser plugin using FireBreath

As already mentioned earlier on Habré, FireBreath is a framework for developing cross-platform plug-ins using NPAPI [1] technologies and ActiveX Control hosts, which will allow using the plug-in in the following browsers: Gecko / Firefox, Google Chrome, Apple Safari, Opera, Microsoft Internet Explorer 6, 7, and 8.



I found this framework useful for the following: in the project (web application) a Java applet was used to print Pdf files directly to the printer, but due to various problems with Java Policy and rights, the applet + various small bugs could not be stable somehow capture the applet focus after loading or hang browser during printing. Perhaps just the hands are crooked. In general, printing worked, then not, and this did not suit anyone.



As an option, it was decided to try to write a plugin that will get rid of the applet and print files quickly and securely. Actually, printing now performs the same Java code, rewritten as a jar file. However, the layer that interacts between Java and client code is the browser plugin.

')

Now we will write a simple “count, do nothing” plugin that will write data to a file in the local file system.



Install Firebreath





alex@alex-laptop:~$ git clone git://github.com/firebreath/FireBreath.git -b firebreath-1.5 firebreath-1.5

Initialized empty Git repository in /home/alex/firebreath-1.5/.git/

remote: Counting objects: 16089, done.

remote: Compressing objects: 100% (4841/4841), done.

remote: Total 16089 (delta 12322), reused 14495 (delta 11066)

Receiving objects: 100% (16089/16089), 11.28 MiB | 535 KiB/s, done.

Resolving deltas: 100% (12322/12322), done.

alex@alex-laptop:~$ cd firebreath-1.5/

alex@alex-laptop:~/firebreath-1.5$ python fbgen.py

Plugin Name []: readFile

Plugin Identifier [readFile]:

Plugin Prefix [RFI]:

Plugin MIME type [application/x-readfile]:

Plugin Description []:

Invalid syntax: Description must be one or more characters long!

Plugin Description []: Read test.txt from ~ folder

Plugin has no UI [false]:

Company Name []:

Invalid syntax: Name must be at least one character, and may not contain carriage returns.

Company Name []: Takeforce

Company Identifier [Takeforce]:

Company Domain [takeforce.com]:

Done. Files placed in /home/alex/firebreath-1.5/projects/readFile




Plugin build



We will need the following packages to work:

  1. CMake version 2.8
  2. libgtk2.0-dev
  3. Git
In Ubuntu / Debian, you can install using the command:

apt-get install cmake libgtk2.0-dev git





Implementation



As a result, we will have in the build / bin / readFile folder a file, npreadFile.so, which needs to be copied ~ / .mozilla / plugins, where chrome and firefox can find it. After that, you can start the browser and open the file build / projects / readFile / gen / FBControl.htm

The page will say that the plugin has successfully loaded and now you can try it in the console - we write:

plugin().write('Hello');

And look at our file /home/alex/log.txt, in which “Hello” appeared.



findings



If you need to perform something on the client with browser rights that could not be done in other ways, or perform some heavy operations, and at the same time, you are satisfied that you need to install software on the client computer, it makes sense to look towards FireBreath.



I checked that the plugin created in FireBreath works in Google Chome, Mozilla Firefox and IE8 version. It is also stated that it works in Opera, Safari and IE6-7, but I did not check it.



References:



1) en.wikipedia.org/wiki/NPAPI

2) www.firebreath.org

Source: https://habr.com/ru/post/118897/



All Articles