From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../mozilla/add-ons/webextensions/api/index.html | 61 ++++++++++++++++++ .../add-ons/webextensions/api/privacy/index.html | 72 ++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 files/pl/mozilla/add-ons/webextensions/api/index.html create mode 100644 files/pl/mozilla/add-ons/webextensions/api/privacy/index.html (limited to 'files/pl/mozilla/add-ons/webextensions/api') diff --git a/files/pl/mozilla/add-ons/webextensions/api/index.html b/files/pl/mozilla/add-ons/webextensions/api/index.html new file mode 100644 index 0000000000..724bf34516 --- /dev/null +++ b/files/pl/mozilla/add-ons/webextensions/api/index.html @@ -0,0 +1,61 @@ +--- +title: JavaScript APIs +slug: Mozilla/Add-ons/WebExtensions/API +tags: + - NeedsTranslation + - TopicStub + - WebExtensions +translation_of: Mozilla/Add-ons/WebExtensions/API +--- +
{{AddonSidebar}}
+ +
+

JavaScript APIs for WebExtensions can be used inside the extension's background scripts and in any other documents bundled with the extension, including browser action or page action popups, sidebars, options pages, or new tab pages. A few of these APIs can also be accessed by an extension's content scripts (see the list in the content script guide).

+ +

To use the more powerful APIs you need to request permission in your extension's manifest.json.

+ +

You can access the APIs using the browser namespace:

+ +
function logTabs(tabs) {
+  console.log(tabs)
+}
+
+browser.tabs.query({currentWindow: true}, logTabs)
+
+ +
+

Many of the APIs are asynchronous, returning a {{JSxRef("Promise")}}:

+ +
function logCookie(c) {
+  console.log(c)
+}
+
+function logError(e) {
+  console.error(e)
+}
+
+let setCookie = browser.cookies.set(
+  {url: "https://developer.mozilla.org/"}
+);
+setCookie.then(logCookie, logError)
+
+ +
+

Note that this is different from Google Chrome's extension system, which uses the chrome namespace instead of browser, and which uses callbacks instead of promises for asynchronous functions. As a porting aid, the Firefox implementation of WebExtensions APIs supports chrome and callbacks as well as browser and promises. Mozilla has also written a polyfill which enables code that uses browser and promises to work unchanged in Chrome: https://github.com/mozilla/webextension-polyfill.

+ +

Firefox also implements these APIs under the chrome namespace using callbacks. This allows code written for Chrome to run largely unchanged in Firefox for the APIs documented here.

+ +

Microsoft Edge uses the browser namespace, but doesn't yet support promise-based asynchronous APIs. In Edge, for the time being, asynchronous APIs must use callbacks.

+ +

Not all browsers support all the APIs: for the details, see Browser support for JavaScript APIs.

+ +

Tip: Throughout the JavaScript API listings you will find short code examples that illustrate how the API is used. You can exercise these examples, without needing to create a web extension, using the console in the Toolbox. For example, here is the first code example on this page running in the Toolbox console in Firefox Developer Edition:

+ +

Illustration of a snippet of web extension code run from the console in the Toolbox

+ +

JavaScript API listing

+ +

See below for a complete list of JavaScript APIs:

+
+ +
{{LandingPageListSubpages}}
diff --git a/files/pl/mozilla/add-ons/webextensions/api/privacy/index.html b/files/pl/mozilla/add-ons/webextensions/api/privacy/index.html new file mode 100644 index 0000000000..321f0f8834 --- /dev/null +++ b/files/pl/mozilla/add-ons/webextensions/api/privacy/index.html @@ -0,0 +1,72 @@ +--- +title: privacy +slug: Mozilla/Add-ons/WebExtensions/API/privacy +tags: + - API + - Add-ons + - Extensions + - NeedsTranslation + - Privacy + - Reference + - TopicStub + - WebExtensions +translation_of: Mozilla/Add-ons/WebExtensions/API/privacy +--- +
{{AddonSidebar}}
+ +

Access and modify various privacy-related browser settings.

+ +

To use the privacy API, you must have the "privacy" API permission.

+ +

Properties

+ +
+
{{WebExtAPIRef("privacy.network")}}
+
Access and modify privacy settings relating to the network.
+
{{WebExtAPIRef("privacy.services")}}
+
Access and modify privacy settings relating to the services provided by the browser or third parties.
+
{{WebExtAPIRef("privacy.websites")}}
+
Access and modify privacy settings relating to the behavior of websites.
+
+ +

Browser compatibility

+ +

{{Compat("webextensions.api.privacy", 10, 1)}}

+ +

{{WebExtExamples("h2")}}

+ +
Acknowledgements + +

This API is based on Chromium's chrome.privacy API.

+
+ + -- cgit v1.2.3-54-g00ecf