Controlling a Firefox Extension via Javascript

Asked
Active3 hr before
Viewed126 times

4 Answers

controllingfirefoxextension
90%

Thanks for contributing an answer to Stack Overflow!, Stack Overflow Public questions & answers , GitLab launches Collective on Stack Overflow ,Stack Overflow en español

In my chrome js:

var myExtension = {
   myListener: function(evt) {
      IprPreferences.setFreshIpStatus(true); // replace with whatever you want to 'fire' in the extension
   }
}

document.addEventListener("MyExtensionEvent", function(e) {
   myExtension.myListener(e);
}, false, true);
// The last value is a Mozilla-specific value to indicate untrusted content is allowed to trigger the event.

In the web content:

var element = document.createElement("MyExtensionDataElement");
element.setAttribute("attribute1", "foobar");
element.setAttribute("attribute2", "hello world");
document.documentElement.appendChild(element);

var evt = document.createEvent("Events");
evt.initEvent("MyExtensionEvent", true, false);
element.dispatchEvent(evt);
load more v
88%

These are good to enable extension errors in the Firefox Error Console (Tools > Error Console), disable XUL caching and such.,The three types of extension preferences are string, integer and boolean, and the six methods to work with them are:,The profile directory is where you will find all the settings for your Firefox profiles, including extension information.,What is needed to have a good base for your extension development, is to create the structure of the extension code. Start by creating this hierarchy:

We begin with the intimidating code of install.rdf. This is where you will have all the meta information about your extension, which versions of Firefox it supports and other assorted information. Our install.rdf will look like this:

<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-RDF-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">

	<Description about="urn:mozilla:install-manifest">
		<em:id>linktargetfinder@robertnyman.com</em:id>

		<em:name>Link Target Finder</em:name>
		<em:version>1.0</em:version>
		<em:type>2</em:type>
		<em:creator>Robert Nyman</em:creator>

		<em:description>Finds links that have a target attribute</em:description>
		<em:homepageURL>http://www.robertnyman.com/</em:homepageURL>
		<em:optionsURL>chrome://linktargetfinder/content/options.xul</em:optionsURL>

		<em:targetApplication>

			<Description>
				<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
				<em:minVersion>2.0</em:minVersion>
				<em:maxVersion>3.1b2</em:maxVersion>

			</Description>
		</em:targetApplication>
	</Description>
</RDF>
load more v
72%

They communicate with the rest of the extension using a messaging API.,The content_scripts key also has a "css" property that you can use to inject CSS stylesheets.,content_scripts manifest key,page-to-extension-messaging

{

   "manifest_version": 2,
   "name": "modify-page",
   "version": "1.0",

   "content_scripts": [{
      "matches": ["https://developer.mozilla.org/*"],
      "js": ["page-eater.js"]
   }]

}
load more v
65%

Is it possible, using javascript, to control an overlay firefox extension? I've extracted the contents of the extension and have identified what functions/methods I need to run, but they are not accessible within the scope of the console. ,Yes it possible to interact with other add-ons, given the right circumstances.,Bootstrapped/SDK add-ons: you can load XPIProvider.jsm (which changed location recently) and get to the bootstrapped scope (run environment of bootstrap.js) via XPIProvider.bootstrapScopes[addonID], and take it from there (use whatever is in the bootstrap scope, e.g. the SDK loader).,Unlike the other extension types webextensions are restrictive, they do not provide access to the low-level APIs that you can find all over the wiki.

In my chrome js:

var myExtension = {
   myListener: function(evt) {
      IprPreferences.setFreshIpStatus(true); // replace with whatever you want to 'fire' in the extension
   }
}

document.addEventListener("MyExtensionEvent", function(e) {
   myExtension.myListener(e);
}, false, true);
// The last value is a Mozilla-specific value to indicate untrusted content is allowed to trigger the event.

In the web content:

var element = document.createElement("MyExtensionDataElement");
element.setAttribute("attribute1", "foobar");
element.setAttribute("attribute2", "hello world");
document.documentElement.appendChild(element);

var evt = document.createEvent("Events");
evt.initEvent("MyExtensionEvent", true, false);
element.dispatchEvent(evt);
load more v

Other "controlling-firefox" queries related to "Controlling a Firefox Extension via Javascript"