Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a browser plugin?

I'm curious as to the procedure for writing browser plugins for browsers like Chrome, Safari, and Opera. I'm thinking specifically of Windows here and would prefer working with C++.

Are there any tools or tutorials that detail the process?

Note: I am not referring to extensions or 'addons'. I'm referring to a plugin similar to how Flash and Adobe Reader have plugins to handle specific content-types.

like image 424
Nathan Osman Avatar asked Apr 15 '10 21:04

Nathan Osman


People also ask

How do I make a browser plug in?

Open your chrome browser and go to URL chrome://extensions turn on your Developer mode Enable. After click the button Load Unpacked and load the extension Source Code. Turn Developer Mode On and Load Extension Source Code. After you can see our Extension will load and shows in to the Browser Toolbar Menu.

How do I create a Chrome plugin?

Go to chrome://extensions in your Google Chrome browser. Check the Developer mode checkbox in the top right-hand corner. Click “Load Unpacked” to see a file-selection dialog. Select your extension directory.

How are browser extensions made?

Extensions are made of different, but cohesive, components. Components can include background scripts, content scripts, an options page, UI elements and various logic files. Extension components are created with web development technologies: HTML, CSS, and JavaScript.


2 Answers

As others point out, plugins for those browser are written using the NPAPI.

Note: Both Firefox and Chrome will default most plugins to click-to-play soon, with Chrome planning to phase out NPAPI entirely. NPAPI for new projects is discouraged at this point.

Resources for getting started with NPAPI:

  • MDC plugin section
  • three part NPAPI tutorial
  • memory management in NPAPI
  • npsimple - the "Hello World" of NPAPI plugins
  • npapi-sdk - the source for the canonical NPAPI headers
  • Mozillas test plugin - good for looking up specific NPAPI use cases

The NPAPI itself is however relatively low-level, but there are tools and frameworks that can help you with it:

  • FireBreath - cross-browser, cross-platform frame-work for plugins
  • Nixysa - generate glue-code for NPAPI plugins
  • JUCE - application framework also providing support for plugins
  • QtBrowserPlugin - Qt based browser plugin framework
like image 113
Georg Fritzsche Avatar answered Sep 30 '22 19:09

Georg Fritzsche


I investigated some frameworks listed by Georg, here is what I get:

  1. FireBreath. I think it is almost the best one available. You can create a cross platform browser plugin with FireBreath in a few days. I did find some cons: It does not support utf-8 characters on Windows. For example: if there are Chinese characters in a file name, you cannot read the content of that file. I believe that boost/locale can resolve this issue. But FireBreath does not contain boost/locale. Yes you can use external boost, but I spent several days configuring and tweaking and still cannot get it compiling on Windows. The author uses cmake to orgnize code and sub-projects. And he created a lot of bat or shell scripts and cmake macros, it is very hard to understand and configure. In short, if you want something that FireBreath currently does not provide, you will have a bad luck, it is very hard to add new features.

  2. Nixysa. I don't think that it is being actively developed. Documentation is poor. And from the comments of the wiki page: https://code.google.com/p/nixysa/wiki/HelloWorldWalkThru We can know that users could not get help at all and were having trouble get it running on Windows

  3. JUCE. It is not specially for creating browser plugins. It does NOT support Linux. The author thinks that NPAPI is going to die so he has no plan to support Linux or add new features.

  4. QtBrowserPlugin. You can not find it in documentation later than QT 4.5. In another word, it is not maintained(and removed from Qt 5.0)

I will update this answer once I find more.

Update: Chrome dropped NPAPI support. I think in the future it becomes harder and harder to write plugins in C++ because lacks of support from browsers.

like image 43
Tyler Liu Avatar answered Sep 30 '22 18:09

Tyler Liu