41
edits
(Fixed typo in the "Milestone 3: Improvements" section) |
(Updates and cleanup of the "APIs provided in the extension pages" section based on last brainstorming with Shane) |
||
| Line 82: | Line 82: | ||
'''Status''': not implemented yet (TODO: link to bugzilla issue)) | '''Status''': not implemented yet (TODO: link to bugzilla issue)) | ||
browser.userScripts. | browser.userScripts.setAPIScript({url: 'apiContentScript.js'}); | ||
browser.userScripts.register(userScriptOptions); | browser.userScripts.register(userScriptOptions); | ||
These APIs are accessible only in the extension pages (any extension page besides the content script and the content script iframes): | These APIs are accessible only in the extension pages (any extension page besides the content script and the content script iframes): | ||
- '''browser.userScripts. | - '''browser.userScripts.setAPIScript''': used to specify an extension Content Script which will be executed (in the content process as a regular content script) to provide the custom APIs to inject into the registered userScripts sandboxes (if executed multiple times, it will replace the API script executed on the next page loads). | ||
- '''browser.userScripts.register''': used to register a userScript, | - '''browser.userScripts.register''': used to register a userScript and its options (the ones shared with contentScripts.register plus some additional one specific to the userScripts, e.g. scriptMetadata is an opaque object for the WebExtensions API which may contains any metadata that the extension wants to associate to the userScript, as an example Greasemonkey may want to have the userScript name and the array of the granted APIs) | ||
==== example background.js ==== | ==== example background.js ==== | ||
// | // browser.userScripts.setAPIScript: specify an extension content script to execute automatically | ||
// when one or more userScripts matches a webpage, see the next section for more details about | |||
// | // how this content script can define which APIs should be available to the userScripts. | ||
browser.userScripts.setAPIScript({url: "apiContentScript.js"}); | |||
// browser.userScripts.register: register a userScript (and its options). | |||
let userScript = await browser.userScripts.register({ | |||
source, // [string] Used by the API to know which source to execute in the userScript sandbox | |||
// userScripts specific options. | |||
scriptMetadata, // [object] A serializable object for use by the extension, opaque to Firefox. | |||
sandboxOptions // [object] additional sandbox options we specifically choose to expose, in followups (needs research/sec-reviews/etc) | |||
// Options shared with contentScripts.register. | |||
matches: [...], | |||
excludeMatches: [...], | |||
includeGlobs: [...], | |||
excludeGlobs: [...], | |||
runAt: "...", | |||
matchAboutBlank: true/false | |||
allFrames: true/false, | |||
}); | |||
=== APIs provided in the regular content scripts === | === APIs provided in the regular content scripts === | ||
edits