Building a firefox plugin – part four
The traffic going to my “Building a firefox plugin” series over the last year or two has been incredible. Granted, I knew that the other documenation was poor, but in recent times I have encountered links to my previous posts in all sorts of strange places — even in the comments in a project I ended up reviewing for an employer where the original author had not previously met me. I never inteded those to be the end of the series, but it has been quite some time since I last posted an update. The main reason for this is that for all but a few uses — android in particular — I no longer recommend anyone write a NPAPI plugin from scratch. The reason for this is that the popular FireBreath framework makes all of this so easy and fixes so many edge cases in different browser versions that it isn’t worth doing it by hand anymore.
Yes, I wrote FireBreath. A lot of others have contributed.
A different approach to learning NPAPI
Now that I have a good example already up and running, it seems pointless to keep trying to describe things with words and code snippets when I can simply walk you through what I have done — what is in use and works well. To that end, and in hopes that it will foster more capable NPAPI developers to help with FireBreath development (we still don’t support printing, for example), I have created a series of 5 minute screencasts providing a brief overview of FireBreath’s NPAPI framework.
I don’t expect that this is as comprehensive as it should be; I’m hoping that comments will help me see what future segments I should create. I have posted these screencasts on youtube and will link to them from here. You can also find a more complete series that includes this one on the FireBreath website.
24 Comments
4 Trackbacks
-
[…] Building a firefox plugin – part four […]
-
[…] Building a firefox plugin – part four […]
-
[…] Building a firefox plugin – part four […]
Guest
10 years ago
hey,
what plugins do you have in VIM? looks almost like a real IDE :P
taxilian
10 years ago
Most people don’t know how much vim can actually do; the main plugin you’re seeing there is NERDTree Explorer. The core of my vim plugins can be found at https://github.com/spf13/spf13-vim, which is maintained by a good friend of mine. It’s also cool to realize that everything you see here could have been done in a console session — even over ssh — as easily as it was in a gui session, though mouse support is a bit better in the gui.
Argh
10 years ago
nice.. I always wanted to master this vim thing.. but argh it’s pain… thanks :)
Dan
10 years ago
Colonel you should be promoted to General by all means.
Thank you.
taxilian
10 years ago
Thanks, but I’m not sure General Panic would sound quite the same… ;-)
Anonymous
10 years ago
I am writing a TextExtractor plug-in for Firefox and for that I need to traverse the DOM tree.
When I try to do something like this.
elementPtr child_node ;
elementPtr body = m_host->getDOMDocument()->getBody();
int node_count = body->getChildNodeCount() ;
int node_offset ;
for( node_offset =0 ; node_offset getChildNode( node_offset ) ;
int width = child_node->getWidth() ;
}
When I debug this code I get some unusual things.
1. node_count comes totally different than the number of child-nodes actually present in the body.
2. During the call to getWidth() , it throws exception.
Please help me, where am I doing wrong.
taxilian
10 years ago
A much better place for this question would be forums.firebreath.org, stackoverflow.com, or the google groups list. (see http://firebreath.org for details). You could also drop into the IRC room at http://npapi.com/chat
Offhand, I don’t know why that wouldn’t be working; it could be that it’s returning text nodes as well as other nodes, which could cause the issue you’re seeing. All it’s doing is calling javascript, so play with it in javascript first, then move the js code to firebreath.
Anonymous
10 years ago
Actually I have already created an HTMLTextExtractor for Internet Explorer and there, I used classes like
IHTMLDocument2 ,
IHTMLDOMNode,
IHTMLElement etc. and
QueryInterface for conversion between them.
In mozilla there exists some very identical classes like
nsIDOMHTMLDocument ,
nsIDOMNode ,
nsIDOMElement
It will be very easy for me to do the tree traversing using these things. Is it possible to make use of them and how ?
taxilian
10 years ago
that is the XPCOM interface; it only works on mozilla, and I have no idea whether or not you can still use it with an NPAPI plugin or if you can only use it with an extension. I don’t deal with extensions or XPCOM, so I can’t help you there. Those are not related to NPAPI at all.
Kamath Ganga
10 years ago
HI.
I have created a a basic NPAPI plugin for MAC. It was a 32 bit plugin and used to work fine in safari 5.0.5 in 32 bit mode. But after installing safari 5.1 in 32 bit its not working . And i recompiled by plugin in 64 bit but still its not working. Can you please give me some pointers to solve this issue
taxilian
10 years ago
Based on the information you have given me, I couldn’t even begin to speculate. In addition, this is not a good place to ask that question; I recommend posting a *lot* more details and trying on stackoverflow.com or forums.firebreath.org. Among other things, you may want to elaborate on the statement “its not working”, since that could mean anything from “it’s as if I didn’t have it installed” to “it caused my computer to explode and it destroyed my house along with it”. Not very specific at all, really.
Also, it probably doesn’t need to be said, but you’d be well served using FireBreath instead of trying to do it by hand, since there are a lot of weird edge cases that FireBreath already includes workarounds for.
vsoma
10 years ago
I have created my ‘TextExtractor’ dll. I am able to invoke it’s methods from chrome and opera extensions using code something like this
window.document.body.innerHTML += “” ; window.document.getElementById(“TextExtractor”).GetText() ;
i.e. by embeding the object tag programatically and then calling the object method.
In case of firefox however this code is not working
content.document.body.innerHTML += “” ; var plugin = content.document.getElementById(“TextExtractor”); plugin.GetText();
But if I manually insert the object tag and the javascript code I am able to call the GetText method.
Plese help ?
taxilian
10 years ago
use a setTimeout to wait for about 200 milliseconds before trying to access the plugin. It’s not available immediately.
vsoma
10 years ago
I tried setTimeout() and even that is not working. What is more ! firefox 3.* are able to invoke plugin method if object tag is manually inserted in the file. But for firefox 6 and firefox 8 even
doing that causes a crash saying the “plugin ‘TextExtractor’ crashed”. And as I told you earlier
chrome and opera work even with programtic inject of the object. Non of the firefox version works there.
taxilian
10 years ago
I’d have to see your javascript code. I suspect you’re doign the setTimeout wrong. However, this is not the place to discuss problems like this; I recommend stackoverflow.com
vsoma
10 years ago
Sorry to bother you here. I tried stackoverflow.com but the need for tags and all makes asking questions a big deal there.
My javascript code looks like this.
function PluginGetText(){ var plugin = content.document.getElementById(“TextExtractor”) ; plugin.GetText() ;}var HelloWorld = { onMenuItemCommand: function() { content.document.body.innerHTML += “” ; window.setTimeout(“PluginGetText()” , 1000) ; }};
Navaid
10 years ago
Don’t know if its the right place to ask this question, but here it goes. Does Firefox or any other browser load plug-ins on the Print Preview page. If not, is it do-able? If yes, in my case it doesn’t appear to work, what could the problem possibly be?
Hung Uong Dong
10 years ago
I want to open a app (exe) on window that from all browsers, I research NPAPI, so I have never seen a example that easy to make that I want, Oh, WOW, HOW???… Please help me now!, share your idea, share your knowledge! thanks for your suggestions (I’m a C# programming, happy coding with c++…)
taxilian
10 years ago
You have to implement NPP_Print to make that work.
taxilian
10 years ago
Use FireBreath (http://firebreath.org)
Reji
10 years ago
Hello..
I created a NP plugin project with the help of FireBreath. It provides me the basic foundation for the plugin development. But I have not digged much into the auto generated files by the FireBreath.
I just wanted to know, if I can go ahead and develop a NPAPI plugin that will create a worker thread within the plugin’s context. I want to have multi threading capability within the plugin. I also want to know, if its safe to have multi threading within plugin context while communicating with browser.
Ben
10 years ago
A better place for this question would stackoverflow.com, the Google Groups list (http://groups.google.com/group/firebreath-dev), or the IRC room at http://npapi.com/chat.
nikhilrkn
10 years ago
Hey Thank you so much for the detailed write up on NPAPI development. Can I develop the same using C functions? Is the firebreath compulsory? Can you PLEASE suggest me a link which has the documentation for developing things in “C” and without the use of firebreath?
taxilian
10 years ago
NPAPI itself is a C api. we adapt it to C++ for convenience. Certainly you could do it without firebreath if you wanted to go to the work.