202
edits
(→Types of Overrides: Add TODO to remove window.eval and provide an exportFunction example) |
(Update technical details (get rid of window.eval and fix location for content script registration)) |
||
Line 90: | Line 90: | ||
As with user agent overrides, JS injections should be designed to use as little code as possible. Due to the nature of these overrides, it is hard to provide exact guidelines. | As with user agent overrides, JS injections should be designed to use as little code as possible. Due to the nature of these overrides, it is hard to provide exact guidelines. | ||
The injected JS will be executed in its own context per default, check [https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#Content_script_environment the MDN web docs] for details. If it is required to run JS in the websites context, | The injected JS will be executed in its own context per default, check [https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#Content_script_environment the MDN web docs] for details. If it is required to run JS in the websites context, functions can be exported via [https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction exportFunction]: | ||
<syntaxhighlight lang="js"> | <syntaxhighlight lang="js"> | ||
window. | Object.defineProperty(window.wrappedJSObject, "isTestFeatureSupported", { | ||
get: exportFunction(function() { | |||
return true; | |||
}, window), | |||
set: exportFunction(function() {}, window) | |||
}); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==== Technical details ==== | ==== Technical details ==== | ||
Line 104: | Line 106: | ||
JS injections are defined within individual files within the [https://github.com/mozilla/webcompat-addon/blob/master/src/webextension/injections/js/ src/webextension/injections/js/] directory of the addon sources. In this folder, you will find a collection of files, one file per override or injection. For easier cross-reference, please stick to the ''bugNNNNN-short-description.js'' file name schema. | JS injections are defined within individual files within the [https://github.com/mozilla/webcompat-addon/blob/master/src/webextension/injections/js/ src/webextension/injections/js/] directory of the addon sources. In this folder, you will find a collection of files, one file per override or injection. For easier cross-reference, please stick to the ''bugNNNNN-short-description.js'' file name schema. | ||
In addition, the injection file has to be registered in the | In addition, the injection file has to be registered in the constant array located at the top of [https://github.com/mozilla/webcompat-addon/blob/master/src/webextension/background.js#L7 src/webextension/background.js]. Details on available parameters can be found [https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/content_scripts in the MDN web docs]. | ||
== Open points for further discussion == | == Open points for further discussion == |
edits