Closed Bug 810633 Opened 12 years ago Closed 12 years ago

Allow Dynamic contentScriptOptions

Categories

(Add-on SDK Graveyard :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: matrix.org, Unassigned)

Details

An example of a PageMod.

require("page-mod").PageMod({
	include: "*",
	contentScriptFile: data.url("script.js"),

	contentScriptOptions: {
		showOptions: true,
		mypref: prefs.get("mypref"),
	},
});

Because this object is evaluated at setup `mypref` doesn't get changed when the preference changes.

If it allowed an object or a function the function can be evaluated at "mod time" so this happen, such as prefs updating or having a variable you can change in between calls.

require("page-mod").PageMod({
	include: "*",
	contentScriptFile: data.url("script.js"),

	contentScriptOptions: function(){return{
		showOptions: true,
		mypref: prefs.get("mypref"),
	}},
});

This is nice because a lot of PageMod's don't stick around, they make their change and disappear, setting up a way for workers to send preferences is a pain when you only need each pref once.  This way you get things like preferences, counters ... always up to date with minimal effort.
The updates would be async at best, so depending on the use case it may be best to message pass the information.
This seems a bit too flaky for our purposes.

We have a planned change that should make this easier in a better method: https://github.com/mozilla/addon-sdk/wiki/JEP-Content-scripts
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.