aboutsummaryrefslogtreecommitdiff
path: root/files/uk/mozilla/add-ons/webextensions/api
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/uk/mozilla/add-ons/webextensions/api
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/uk/mozilla/add-ons/webextensions/api')
-rw-r--r--files/uk/mozilla/add-ons/webextensions/api/index.html57
-rw-r--r--files/uk/mozilla/add-ons/webextensions/api/sessions/index.html136
-rw-r--r--files/uk/mozilla/add-ons/webextensions/api/sessions/restore/index.html108
3 files changed, 301 insertions, 0 deletions
diff --git a/files/uk/mozilla/add-ons/webextensions/api/index.html b/files/uk/mozilla/add-ons/webextensions/api/index.html
new file mode 100644
index 0000000000..0bbd6f9878
--- /dev/null
+++ b/files/uk/mozilla/add-ons/webextensions/api/index.html
@@ -0,0 +1,57 @@
+---
+title: JavaScript APIs
+slug: Mozilla/Add-ons/WebExtensions/API
+tags:
+ - NeedsTranslation
+ - TopicStub
+ - WebExtensions
+translation_of: Mozilla/Add-ons/WebExtensions/API
+---
+<div>{{AddonSidebar}}</div>
+
+<div>
+<p>JavaScript APIs for WebExtensions can be used inside the extension's <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Anatomy_of_a_WebExtension#Background_scripts">background scripts</a> and in any other documents bundled with the extension, including <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Browser_action">browser action</a> or <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Page_actions">page action</a> popups, <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Sidebars">sidebars</a>, <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Options_pages">options pages</a>, or <a href="/en-US/Add-ons/WebExtensions/manifest.json/chrome_url_overrides">new tab pages</a>. A few of these APIs can also be accessed by an extension's <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Anatomy_of_a_WebExtension#Content_scripts">content scripts</a> (see the <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#WebExtension_APIs">list in the content script guide</a>).</p>
+
+<p>To use the more powerful APIs you need to <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/permissions">request permission</a> in your extension's manifest.json.</p>
+
+<p>You can access the APIs using the <code>browser</code> namespace:</p>
+
+<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">logTabs</span><span class="punctuation token">(</span>tabs<span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>tabs<span class="punctuation token">)</span><span class="punctuation token">;</span>
+<span class="punctuation token">}</span>
+
+browser<span class="punctuation token">.</span>tabs<span class="punctuation token">.</span><span class="function token">query</span><span class="punctuation token">(</span><span class="punctuation token">{</span>currentWindow<span class="punctuation token">:</span> <span class="keyword token">true</span><span class="punctuation token">}</span><span class="punctuation token">,</span> logTabs<span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
+</div>
+
+<div>
+<p>Many of the APIs are asynchronous, returning a <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>:</p>
+
+<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">logCookie</span><span class="punctuation token">(</span>c<span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>c<span class="punctuation token">)</span><span class="punctuation token">;</span>
+<span class="punctuation token">}</span>
+
+<span class="keyword token">function</span> <span class="function token">logError</span><span class="punctuation token">(</span>e<span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ console<span class="punctuation token">.</span><span class="function token">error</span><span class="punctuation token">(</span>e<span class="punctuation token">)</span><span class="punctuation token">;</span>
+<span class="punctuation token">}</span>
+
+<span class="keyword token">var</span> setCookie <span class="operator token">=</span> browser<span class="punctuation token">.</span>cookies<span class="punctuation token">.</span><span class="keyword token">set</span><span class="punctuation token">(</span>
+ <span class="punctuation token">{</span>url<span class="punctuation token">:</span> <span class="string token">"https://developer.mozilla.org/"</span><span class="punctuation token">}</span>
+<span class="punctuation token">)</span><span class="punctuation token">;</span>
+setCookie<span class="punctuation token">.</span><span class="function token">then</span><span class="punctuation token">(</span>logCookie<span class="punctuation token">,</span> logError<span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>
+</div>
+
+<div>
+<p>Note that this is different from Google Chrome's extension system, which uses the <code>chrome</code> namespace instead of <code>browser</code>, and which uses callbacks instead of promises for asynchronous functions. As a porting aid, the Firefox implementation of WebExtensions APIs supports <code>chrome</code> and callbacks as well as <code>browser</code> and promises. Mozilla has also written a polyfill which enables code that uses <code>browser</code> and promises to work unchanged in Chrome: <a class="external external-icon" href="https://github.com/mozilla/webextension-polyfill">https://github.com/mozilla/webextension-polyfill</a>.</p>
+
+<p>Firefox also implements these APIs under the <code>chrome</code> namespace using callbacks. This allows code written for Chrome to run largely unchanged in Firefox for the APIs documented here.</p>
+
+<p>Microsoft Edge uses the <code>browser</code> namespace, but doesn't yet support promise-based asynchronous APIs. In Edge, for the time being, asynchronous APIs must use callbacks.</p>
+
+<p>Not all browsers support all the APIs: for the details, see <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Browser_support_for_JavaScript_APIs">Browser support for JavaScript APIs</a>.</p>
+
+<h2 id="JavaScript_API_listing">JavaScript API listing</h2>
+
+<p>See below for a complete list of JavaScript APIs:</p>
+</div>
+
+<div>{{SubpagesWithSummaries}}</div>
diff --git a/files/uk/mozilla/add-ons/webextensions/api/sessions/index.html b/files/uk/mozilla/add-ons/webextensions/api/sessions/index.html
new file mode 100644
index 0000000000..1a1c8fcf2c
--- /dev/null
+++ b/files/uk/mozilla/add-ons/webextensions/api/sessions/index.html
@@ -0,0 +1,136 @@
+---
+title: sessions
+slug: Mozilla/Add-ons/WebExtensions/API/sessions
+tags:
+ - API
+ - Add-ons
+ - Extensions
+ - NeedsTranslation
+ - Non-standard
+ - Reference
+ - TopicStub
+ - WebExtensions
+ - sessions
+translation_of: Mozilla/Add-ons/WebExtensions/API/sessions
+---
+<div>{{AddonSidebar}}</div>
+
+<p>Use the sessions API to list, and restore, tabs and windows that have been closed while the browser has been running.</p>
+
+<p>The {{WebExtAPIRef("sessions.getRecentlyClosed()")}} function returns an array of {{WebExtAPIRef("tabs.Tab")}} and {{WebExtAPIRef("windows.Window")}} objects, representing tabs and windows that have been closed since the browser was running, up to the maximum defined in {{WebExtAPIRef("sessions.MAX_SESSION_RESULTS")}}.</p>
+
+<p>You can then restore a window or tab using the {{WebExtAPIRef("sessions.restore()")}} function. Restoring doesn't just reopen the tab: it also restores the tab's navigation history so the back/forward buttons will work.</p>
+
+<p>This API also provides a group of functions that enable an extension to store additional state associated with a tab or a window. Then, if the tab or window is closed and subsequently restored, the extension can retrieve the state. For example, a tab grouping extension might use this to remember which group a tab is in, so as to restore it into the right group if the user restores the tab.</p>
+
+<p>To use the sessions API you must have the "sessions" <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/permissions#API_permissions">API permission</a>.</p>
+
+<h2 id="Types">Types</h2>
+
+<dl>
+ <dt>{{WebExtAPIRef("sessions.Filter")}}</dt>
+ <dd>Enables you to restrict the number of {{WebExtAPIRef("sessions.Session", "Session")}} objects returned by a call to {{WebExtAPIRef("sessions.getRecentlyClosed()")}}.</dd>
+ <dt>{{WebExtAPIRef("sessions.Session")}}</dt>
+ <dd>
+ <p>Represents a tab or window that the user has closed in the current browsing session.</p>
+ </dd>
+</dl>
+
+<h2 id="Properties">Properties</h2>
+
+<dl>
+ <dt>{{WebExtAPIRef("sessions.MAX_SESSION_RESULTS")}}</dt>
+ <dd>The maximum number of sessions that will be returned by a call to <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sessions/getRecentlyClosed" title="Returns an array Session objects, representing windows and tabs that were closed in the current browsing session (that is: the time since the browser was started)."><code>sessions.getRecentlyClosed()</code></a>.</dd>
+</dl>
+
+<h2 id="Functions">Functions</h2>
+
+<dl>
+ <dt>{{WebExtAPIRef("sessions.forgetClosedTab()")}}</dt>
+ <dd>Removes a closed tab from the browser's list of recently closed tabs.</dd>
+ <dt>{{WebExtAPIRef("sessions.forgetClosedWindow()")}}</dt>
+ <dd>Removes a closed window from the browser's list of recently closed windows.</dd>
+ <dt>{{WebExtAPIRef("sessions.getRecentlyClosed()")}}</dt>
+ <dd>Returns an array of {{WebExtAPIRef("sessions.Session", "Session")}} objects, representing windows and tabs that were closed in the current browsing session (that is: the time since the browser was started).</dd>
+ <dt>{{WebExtAPIRef("sessions.restore()")}}</dt>
+ <dd>
+ <p>Restores a closed tab or window.</p>
+ </dd>
+ <dt>{{WebExtAPIRef("sessions.setTabValue()")}}</dt>
+ <dd>
+ <p>Store a key/value pair associated with a given tab.</p>
+ </dd>
+ <dt>{{WebExtAPIRef("sessions.getTabValue()")}}</dt>
+ <dd>
+ <p>Retrieve a previously stored value for a given tab, given its key.</p>
+ </dd>
+ <dt>{{WebExtAPIRef("sessions.removeTabValue()")}}</dt>
+ <dd>
+ <p>Remove a key/value pair from a given tab.</p>
+ </dd>
+ <dt>{{WebExtAPIRef("sessions.setWindowValue()")}}</dt>
+ <dd>
+ <p>Store a key/value pair associated with a given window.</p>
+ </dd>
+ <dt>{{WebExtAPIRef("sessions.getWindowValue()")}}</dt>
+ <dd>
+ <p>Retrieve a previously stored value for a given window, given its key.</p>
+ </dd>
+ <dt>{{WebExtAPIRef("sessions.removeWindowValue()")}}</dt>
+ <dd>
+ <p>Remove a key/value pair from a given window.</p>
+ </dd>
+</dl>
+
+<h2 id="Events">Events</h2>
+
+<dl>
+ <dt>{{WebExtAPIRef("sessions.onChanged")}}</dt>
+ <dd>
+ <p>Fired when a tab or window is closed.</p>
+ </dd>
+</dl>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p>{{Compat("webextensions.api.sessions")}}</p>
+
+<p>{{WebExtExamples("h2")}}</p>
+
+<div class="note"><strong>Acknowledgements</strong>
+
+<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/sessions"><code>chrome.sessions</code></a> API.</p>
+
+<p>Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.</p>
+</div>
+
+<div class="hidden">
+<pre>// Copyright 2015 The Chromium Authors. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+</pre>
+</div>
diff --git a/files/uk/mozilla/add-ons/webextensions/api/sessions/restore/index.html b/files/uk/mozilla/add-ons/webextensions/api/sessions/restore/index.html
new file mode 100644
index 0000000000..f557ad46f1
--- /dev/null
+++ b/files/uk/mozilla/add-ons/webextensions/api/sessions/restore/index.html
@@ -0,0 +1,108 @@
+---
+title: sessions.restore()
+slug: Mozilla/Add-ons/WebExtensions/API/sessions/restore
+tags:
+ - API
+ - WebExtensions
+ - Додатки
+ - Розширення
+translation_of: Mozilla/Add-ons/WebExtensions/API/sessions/restore
+---
+<div>{{AddonSidebar()}}</div>
+
+<p>Відновлює закрите вікно або вкладку. Відновлення є не просто перевідкриттям: воно також повертає історію переходів, тож кнопки вперед/назад також працюватимуть. Відновлення вікна відновить всі вкладки, які вікно мало перед закриттям.</p>
+
+<p>Це асинхронна функція, що повертає <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>.</p>
+
+<h2 id="Синтаксис">Синтаксис</h2>
+
+<pre class="syntaxbox brush:js">var restoringSession = browser.sessions.restore(
+ sessionId // рядок
+)
+</pre>
+
+<h3 id="Параметри">Параметри</h3>
+
+<dl>
+ <dt><code>sessionId</code></dt>
+ <dd>Рядок, що містить ідентифікатор сесії для відновлення вікна чи вкладки. Його можна дістати із властивості <code>sessionId</code> об'єкта {{WebExtAPIRef("tabs.Tab", "Tab")}} чи {{WebExtAPIRef("windows.Window", "Window")}}, взятого з котрогось із об'єктів {{WebExtAPIRef("sessions.Session", "Session")}}, що їх масив вертає {{WebExtAPIRef("sessions.getRecentlyClosed()")}}.</dd>
+</dl>
+
+<h3 id="Вертає">Вертає</h3>
+
+<p>Об'єкт <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>. Через нього буде передано об'єкт {{WebExtAPIRef("sessions.Session", "Session")}}, що відповідатиме відновленій сесії.</p>
+
+<h2 id="Підтримка_веб-переглядачами">Підтримка веб-переглядачами</h2>
+
+<div class="hidden">Таблиця сумісності на цій сторінці створена зі структурованих даних. Якщо ви хочете долучитися до розробки цих даних, пропонуйте нам свої pull request до репозиторію <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a>.</div>
+
+<p>{{Compat("webextensions.api.sessions.restore")}}</p>
+
+<h2 id="Приклади">Приклади</h2>
+
+<p>Цей код відновлює останню завершену сессію (вікно або вкладку):</p>
+
+<pre class="brush: js">function restoreMostRecent(sessionInfos) {
+ if (!sessionInfos.length) {
+ console.log("No sessions found")
+ return;
+ }
+ let sessionInfo = sessionInfos[0];
+ if (sessionInfo.tab) {
+ browser.sessions.restore(sessionInfo.tab.sessionId);
+ } else {
+ browser.sessions.restore(sessionInfo.window.sessionId);
+ }
+}
+
+function onError(error) {
+ console.log(error);
+}
+
+browser.browserAction.onClicked.addListener(function() {
+ var gettingSessions = browser.sessions.getRecentlyClosed({
+ maxResults: 1
+ });
+ gettingSessions.then(restoreMostRecent, onError);
+});
+</pre>
+
+<p>{{WebExtExamples}}</p>
+
+<div class="note"><strong>Подяки</strong>
+
+<p>Цей API ґрунтується на <a href="https://developer.chrome.com/extensions/sessions"><code>chrome.sessions</code></a> API з Chromium.</p>
+
+<p>Дані про сумісність з Microsoft Edge надано корпорацією Microsoft і подано тут під ліцензією Creative Commons Attribution 3.0 United States License.</p>
+</div>
+
+<div class="hidden">
+<pre>// Copyright 2015 The Chromium Authors. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+</pre>
+</div>