0

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>(...)
2
  • You could try search on Google: "firefox extension github" since Github is full of open source, you might find something useful Commented Oct 14, 2014 at 13:28
  • I tried that : I cannot find anything specific on github/MDN . Furthermore a large part on MDN seems outdated. Commented Oct 14, 2014 at 13:43

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

not tested yet, but can use the Mozilla API (like TCPScoket ) without asking for the user's permission ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.