diff options
Diffstat (limited to 'files/fr/mozilla/add-ons/webextensions/api/tabs/duplicate/index.md')
-rw-r--r-- | files/fr/mozilla/add-ons/webextensions/api/tabs/duplicate/index.md | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/files/fr/mozilla/add-ons/webextensions/api/tabs/duplicate/index.md b/files/fr/mozilla/add-ons/webextensions/api/tabs/duplicate/index.md new file mode 100644 index 0000000000..177cec75a3 --- /dev/null +++ b/files/fr/mozilla/add-ons/webextensions/api/tabs/duplicate/index.md @@ -0,0 +1,120 @@ +--- +title: tabs.duplicate() +slug: Mozilla/Add-ons/WebExtensions/API/tabs/duplicate +translation_of: Mozilla/Add-ons/WebExtensions/API/tabs/duplicate +browser-compat: webextensions.api.tabs.duplicate +--- +<div>{{AddonSidebar()}}</div> + +<p>Duplique un onglet dont l'identifiant est donné.</p> + +<p>Il s'agit d'une fonction asynchrone qui renvoie une <a href="/fr/docs/Web/JavaScript/Reference/Global_Objects/Promise">promesse (<code>Promise</code>)</a>.</p> + +<h2 id="syntax">Syntaxe</h2> + +<pre class="brush:js"> +let duplicating = browser.tabs.duplicate( + tabId, // entier + duplicateProperties // objet optionnel +); +</pre> + +<h3 id="parameters">Paramètres</h3> + +<dl> + <dt><code>tabId</code></dt> + <dd><code>integer</code>. L'identifiant de l'onglet à dupliquer.</dd> + <dt><code>duplicateProperties</code> Optionnel</dt> + <dd><p><code>object</code>. Un objet décrivant la façon dont l'onglet est dupliqué. Il contient les propriétés suivantes :</p> + <dl> + <dt><code><var>index</var></code> Optionnel</dt> + <dd><code>integer</code>. La position du nouvel onglet dans la fenêtre. La valeur est restreinte à l'intervalle entre zéro et le nombre d'onglets dans la fenêtre.</dd> + <dt><code><var>active</var></code> Optionnel</dt> + <dd> + <p><code>boolean</code>. Si l'onglet devient l'onglet actif dans la fenêtre. Cela ne change pas l'état du focus pour la fenêtre. <code>true</code> par défaut.</p> + </dd> + </dl> + </dd> +</dl> + +<h3 id="return_value">Valeur de retour</h3> + +<p>Une <a href="/fr/docs/Web/JavaScript/Reference/Global_Objects/Promise">promesse (<code>Promise</code>)</a> dont la valeur de résolution sera un objet <a href="/fr/docs/Mozilla/Add-ons/WebExtensions/API/tabs/Tab"><code>tabs.Tab</code></a> contenant des détails sur l'onglet dupliqué. L'objet <code>Tab</code> contiendra les propriétés <code>url</code>, <code>title</code> et <code>favIconUrl</code> uniquement si l'extension dispose de la <a href="/fr/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions"> permission <code>"tabs"</code></a> ou lorsque <a href="/fr/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions">l'hôte correspond à un hôte ciblé dans les permissions</a>. Si une erreur se produit, la promesse sera rejetée avec un message d'erreur.</p> + +<div class="note"> +<p><strong>Note :</strong> À partir de Firefox 68, la promesse renvoyée par <code>browser.tabs.duplicate()</code> se résout dès que l'onglet a été dupliqué. Auparavant, la promesse n'était résolue qu'une fois l'onglet entièrement chargé.</p> +</div> + +<h2 id="Exemples">Exemples</h2> + +<p>Duplique le premier onglet, puis affiche l'identifiant de l'onglet nouvellement créé :</p> + +<pre class="brush: js"> +function onDuplicated(tabInfo) { + console.log(tabInfo.id); +} + +function onError(error) { + console.error(error); +} + +// Duplique le premier onglet du tableau +function duplicateFirstTab(tabs) { + console.log(tabs); + if (tabs.length > 0) { + let duplicating = browser.tabs.duplicate(tabs[0].id); + duplicating.then(onDuplicated, onError); + } +} + +// On récupère tous les onglets ouverts +let querying = browser.tabs.query({}); +querying.then(duplicateFirstTab, onError);</pre> + +<h3 id="example_extensions">Exemple d'extensions</h3> + +<ul> + <li><a href="https://github.com/mdn/webextensions-examples/tree/master/tabs-tabs-tabs">tabs-tabs-tabs</a></li> +</ul> + +<h2 id="browser_compatibility">Compatibilité des navigateurs</h2> + +<p>{{Compat}}</p> + +<div class="note"><p><strong>Note :</strong></p> + +<p>Cette API est basée sur l'API Chromium <a href="https://developer.chrome.com/extensions/tabs#method-executeScript"><code>chrome.tabs</code></a>. Cette documentation est dérivée de <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/tabs.json"><code>tabs.json</code></a> dans le code de Chromium code.</p> + +<p>Les données de compatibilité relatives à Microsoft Edge sont fournies par Microsoft Corporation et incluses ici sous la licence Creative Commons Attribution 3.0 pour les États-Unis.</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> |