I want to develop a simple Chrome extension in C++, using NPAPI, which does the job of dumping the HTML content of the current page onto a file. I don't have much expertise in developing plugins/extensions. How do I get started on this?
2 Answers
1 - Create a Extension... http://code.google.com/chrome/extensions/getstarted.html
2 - Create a NPAPI plugin... http://colonelpanic.net/2009/03/building-a-firefox-plugin-part-one/
3 - On the manifest of your extension add the plugin...
"plugins": [
{ "path": "your_npapi_plugin.dll" }
],
4 - On your extension background page create the plugin
<script>
var plugin = document.getElementById("MyNPAPIPluginId");
...
</script>
5 - Create a javascript that you will use as a content script injected on every page. On that script communicate with your npapi scriptable object and do the work you want to do.
How do I get the value of MyNPAPIPluginId? All I have is the name of the DLL?
On your background page when you add the tag of your plugin, you place the id
<embed type="application/my-plugin-mimetype" id="MyNPAPIPluginId">
On Windows you add the MIMEType on the resource file of the DLL, add a entry with:
VALUE "MIMEType", "application/my-plugin-mimetype"
-
How do I get the value of MyNPAPIPluginId? All I have is the name of the DLL. Feb 24, 2012 at 2:49
-
On your background page when you add the tag of your plugin, you place the id <embed type="application/my-plugin-mimetype" id="MyNPAPIPluginId"> Feb 24, 2012 at 9:38
-
On Windows you add the MIMEType on the resource file of the DLL, add a entry with: VALUE "MIMEType", "application/my-plugin-mimetype" Feb 24, 2012 at 10:03
There's a plugin here that will help you....
http://code.google.com/p/npapi-file-io/
...source is there aswell. This plugin will allow you to write a string (your html) to a file plus a few other nice things. Windows and Linux only unfortunately.
Then all you need to do is write a script to dump what you want.
As smorgan points out in the comments these sort of plugins have the potential to be rather dangerous.
So make sure when you add the plugin to your manifest that you set the public property to false...
http://code.google.com/chrome/extensions/npapi.html
"plugins": [
{ "path": "plugin.dll", "public": false }
]
And in the future (Chrome 18) you should use manifest version 2...
http://code.google.com/chrome/extensions/trunk/manifestVersion.html
Also, I take it that you want to save the file without any user input. If that isnt true and having a dialog to select where to save the file every time is acceptable then this can be done without using a plugin.
-
Keep in mind that if you are not very, very careful with how you package and use this plugin, you give every web page in the world read/write access to every file on the computer of every user who installs your extension. An NPAPI plugin that allows arbitrary I/O is extremely dangerous, and needs to be handled accordingly.– smorganFeb 22, 2012 at 16:00
-
-
It shall not make use of any I/O. I'm actually creating the web-capture plugin for Google Chrome, similar to the Adobe web-capture plugin for IE. The plugin should work on Windows and Mac and I'll be adding a DLL later. Is there anything I should take care of from the beginning? Feb 23, 2012 at 7:49
-
Well I dont know jack really when it comes to making a plugin (its all a little beyond me), but one thing you might like to look at is FireBreath.... code.google.com/p/firebreath– PAEzFeb 23, 2012 at 8:08
-
You are going to make an extension that writes a page to a file but doesn't do any file I/O? How does that work?– smorganFeb 23, 2012 at 9:28