Reputation: 35226
I created a library in a firefox extension :
./components/main.js
./skin/icon.png
./install.rdf
./chrome.manifest
my main.js would use define a class calling a mozilla TCPScoket ( https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket)
function MYLib() {}
MYLib.prototype.doWork = function(arg1,arg2) { /* do something with TCPScoket */}
How should I use my library on the client side in the HTML ?
I'm looking for something like (?):
<html><head><script>
var mylib = MozillaApiThing.createNewInstance("chrome://myextension/", "MYLib");
....
</script>(...)
Upvotes: 0
Views: 129
Reputation: 7721
chrome
or resource
(not in restartless) URLs are available as direct URLs (ie you can enter them into address-bar and they show up). Therefore you can use it as a simple script src
<script src="chrome://myextension/components/jsfile.js"></script>
Alternatively, you can read the JS file (ie with XMLHttpRequest or FileUtils.jsm or osfile.jsm) and then insert the content into the page with createElement('script')
, textContent
and appendChild()
Alternatively, you can try The message manager
Note: Inserted local script into the page will have the content page scope (no access to browser scope API)
Upvotes: 1