aboutsummaryrefslogtreecommitdiff
path: root/files/ru/mozilla/add-ons/webextensions/api/tabs/index.html
blob: 32f8abbc44b7966b67d96789621d83591f7fa840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: tabs
slug: Mozilla/Add-ons/WebExtensions/API/tabs
tags:
  - API
  - Add-ons
  - Extensions
  - Interface
  - NeedsTranslation
  - Non-standard
  - Reference
  - TopicStub
  - WebExtensions
  - tabs
translation_of: Mozilla/Add-ons/WebExtensions/API/tabs
---
<div>{{AddonSidebar}}</div>

<p>Interact with the browser's tab system. You can use this API to get a list of opened tabs and to create, modify, and rearrange tabs in the browser.</p>

<p>You can use most of this API without any special permission. However, to access <code>Tab.url</code>, <code>Tab.title</code>, and <code>Tab.faviconUrl</code>, you need to have the "tabs" <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">permission</a>. In Firefox this also means you need "tabs" to {{WebExtAPIRef("tabs.query", "query")}} by URL.</p>

<h2 id="Types">Types</h2>

<dl>
 <dt>{{WebExtAPIRef("tabs.MutedInfoReason")}}</dt>
 <dd>An event that caused a muted state change.</dd>
 <dt>{{WebExtAPIRef("tabs.MutedInfo")}}</dt>
 <dd>Tab muted state and the reason for the last state change.</dd>
 <dt>{{WebExtAPIRef("tabs.Tab")}}</dt>
 <dd>Contains various properties of a single tab.</dd>
 <dt>{{WebExtAPIRef("tabs.ZoomSettingsMode")}}</dt>
 <dd>Defines how zoom changes are handled, i.e. which entity is responsible for the actual scaling of the page; defaults to <code>automatic</code>.</dd>
 <dt>{{WebExtAPIRef("tabs.ZoomSettingsScope")}}</dt>
 <dd>Defines whether zoom changes will persist for the page's origin, or only take effect in this tab; defaults to <code>per-origin</code> when in <code>automatic</code> mode, and <code>per-tab</code> otherwise.</dd>
 <dt>{{WebExtAPIRef("tabs.ZoomSettings")}}</dt>
 <dd>Defines how zoom changes in a tab are handled and at what scope.</dd>
 <dt>{{WebExtAPIRef("tabs.TabStatus")}}</dt>
 <dd>Whether the tabs have completed loading.</dd>
 <dt>{{WebExtAPIRef("tabs.WindowType")}}</dt>
 <dd>The type of window.</dd>
</dl>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{WebExtAPIRef("tabs.TAB_ID_NONE")}}</dt>
 <dd>An ID which represents the absence of a browser tab.</dd>
</dl>

<h2 id="Functions">Functions</h2>

<dl>
 <dt>{{WebExtAPIRef("tabs.get()")}}</dt>
 <dd>Retrieves details about the specified tab.</dd>
 <dt>{{WebExtAPIRef("tabs.getCurrent()")}}</dt>
 <dd>Gets the tab that this script call is being made from. May be undefined if called from a non-tab context (for example: a background page or popup view).</dd>
 <dt>{{WebExtAPIRef("tabs.connect()")}}</dt>
 <dd>Connects to the content script(s) in the specified tab. The {{WebExtAPIRef('runtime.onConnect')}} event is fired in each content script running in the specified tab for the current extension. For more details, see <a href="/en-US/Add-ons/WebExtensions/Content_scripts">content script messaging</a>.</dd>
 <dt>{{WebExtAPIRef("tabs.sendRequest()")}}</dt>
 <dd>Sends a single request to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The {{WebExtAPIRef('extension.onRequest')}} event is fired in each content script running in the specified tab for the current extension.</dd>
 <dt>{{WebExtAPIRef("tabs.sendMessage()")}}</dt>
 <dd>Sends a single message to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The {{WebExtAPIRef('runtime.onMessage')}} event is fired in each content script running in the specified tab for the current extension.</dd>
 <dt>{{WebExtAPIRef("tabs.getSelected()")}}</dt>
 <dd>Gets the tab that is selected in the specified window.</dd>
 <dt>{{WebExtAPIRef("tabs.getAllInWindow()")}}</dt>
 <dd>Gets details about all tabs in the specified window.</dd>
 <dt>{{WebExtAPIRef("tabs.create()")}}</dt>
 <dd>Creates a new tab.</dd>
 <dt>{{WebExtAPIRef("tabs.duplicate()")}}</dt>
 <dd>Duplicates a tab.</dd>
 <dt>{{WebExtAPIRef("tabs.query()")}}</dt>
 <dd>Gets all tabs that have the specified properties, or all tabs if no properties are specified.</dd>
 <dt>{{WebExtAPIRef("tabs.highlight()")}}</dt>
 <dd>Highlights the given tabs.</dd>
 <dt>{{WebExtAPIRef("tabs.update()")}}</dt>
 <dd>Modifies the properties of a tab. Properties that are not specified in <var>updateProperties</var> are not modified.</dd>
 <dt>{{WebExtAPIRef("tabs.move()")}}</dt>
 <dd>Moves one or more tabs to a new position within its window, or to a new window. Note that tabs can only be moved to and from normal (<code>window.type === "normal"</code>) windows.</dd>
 <dt>{{WebExtAPIRef("tabs.reload()")}}</dt>
 <dd>Reload a tab.</dd>
 <dt>{{WebExtAPIRef("tabs.remove()")}}</dt>
 <dd>Closes one or more tabs.</dd>
 <dt>{{WebExtAPIRef("tabs.detectLanguage()")}}</dt>
 <dd>Detects the primary language of the content in a tab.</dd>
 <dt>{{WebExtAPIRef("tabs.captureVisibleTab()")}}</dt>
 <dd>Captures the visible area of the currently active tab in the specified window. You must have <code>&lt;all_urls&gt;</code> permission to use this method.</dd>
 <dt>{{WebExtAPIRef("tabs.executeScript()")}}</dt>
 <dd>Injects JavaScript code into a page. For details, see the programmatic injection section of the <a href="/en-US/Add-ons/WebExtensions/Content_scripts">content scripts</a> doc.</dd>
 <dt>{{WebExtAPIRef("tabs.insertCSS()")}}</dt>
 <dd>Injects CSS into a page. For details, see the programmatic injection section of the <a href="/en-US/Add-ons/WebExtensions/Content_scripts">content scripts</a> doc.</dd>
 <dt>{{WebExtAPIRef("tabs.setZoom()")}}</dt>
 <dd>Zooms a specified tab.</dd>
 <dt>{{WebExtAPIRef("tabs.getZoom()")}}</dt>
 <dd>Gets the current zoom factor of a specified tab.</dd>
 <dt>{{WebExtAPIRef("tabs.setZoomSettings()")}}</dt>
 <dd>Sets the zoom settings for a specified tab, which define how zoom changes are handled. These settings are reset to defaults upon navigating the tab.</dd>
 <dt>{{WebExtAPIRef("tabs.getZoomSettings()")}}</dt>
 <dd>Gets the current zoom settings of a specified tab.</dd>
</dl>

<h2 id="Events">Events</h2>

<dl>
 <dt>{{WebExtAPIRef("tabs.onCreated")}}</dt>
 <dd>Fired when a tab is created. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set.</dd>
 <dt>{{WebExtAPIRef("tabs.onUpdated")}}</dt>
 <dd>Fired when a tab is updated.</dd>
 <dt>{{WebExtAPIRef("tabs.onMoved")}}</dt>
 <dd>Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved. Move events are not fired for the other tabs that must move in response. This event is not fired when a tab is moved between windows. For that, see {{WebExtAPIRef('tabs.onDetached')}}.</dd>
 <dt>{{WebExtAPIRef("tabs.onSelectionChanged")}}</dt>
 <dd>Fires when the selected tab in a window changes.</dd>
 <dt>{{WebExtAPIRef("tabs.onActiveChanged")}}</dt>
 <dd>Fires when the selected tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to {{WebExtAPIRef('tabs.onUpdated')}} events to be notified when a URL is set.</dd>
 <dt>{{WebExtAPIRef("tabs.onActivated")}}</dt>
 <dd>Fires when the active tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set.</dd>
 <dt>{{WebExtAPIRef("tabs.onHighlightChanged")}}</dt>
 <dd>Fired when the highlighted or selected tabs in a window changes.</dd>
 <dt>{{WebExtAPIRef("tabs.onHighlighted")}}</dt>
 <dd>Fired when the highlighted or selected tabs in a window changes.</dd>
 <dt>{{WebExtAPIRef("tabs.onDetached")}}</dt>
 <dd>Fired when a tab is detached from a window, for example because it is being moved between windows.</dd>
 <dt>{{WebExtAPIRef("tabs.onAttached")}}</dt>
 <dd>Fired when a tab is attached to a window, for example because it was moved between windows.</dd>
 <dt>{{WebExtAPIRef("tabs.onRemoved")}}</dt>
 <dd>Fired when a tab is closed.</dd>
 <dt>{{WebExtAPIRef("tabs.onReplaced")}}</dt>
 <dd>Fired when a tab is replaced with another tab due to prerendering or instant.</dd>
 <dt>{{WebExtAPIRef("tabs.onZoomChange")}}</dt>
 <dd>Fired when a tab is zoomed.</dd>
</dl>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat}}</p>

<div class="hidden note">
<p>The "Chrome incompatibilities" section is included from <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities"> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities</a> using the <a href="/en-US/docs/Template:WebExtChromeCompat">WebExtChromeCompat</a> macro.</p>

<p>If you need to update this content, edit <a href="https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities">https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities</a>, then shift-refresh this page to see your changes.</p>
</div>

<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/tabs"><code>chrome.tabs</code></a> API. This documentation is derived from <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/tabs.json"><code>tabs.json</code></a> in the Chromium code.</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>