diff options
Diffstat (limited to 'files/fr/mozilla/add-ons/webextensions/api/runtime/lasterror/index.html')
-rw-r--r-- | files/fr/mozilla/add-ons/webextensions/api/runtime/lasterror/index.html | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/files/fr/mozilla/add-ons/webextensions/api/runtime/lasterror/index.html b/files/fr/mozilla/add-ons/webextensions/api/runtime/lasterror/index.html index 743fdd2851..0384ff364d 100644 --- a/files/fr/mozilla/add-ons/webextensions/api/runtime/lasterror/index.html +++ b/files/fr/mozilla/add-ons/webextensions/api/runtime/lasterror/index.html @@ -34,7 +34,7 @@ gettingCookies.then(onGot, onError);</pre> <h2 id="Syntaxe">Syntaxe</h2> -<pre class="syntaxbox brush:js">var myError = browser.runtime.lastError; // null or Error object</pre> +<pre class="brush: js">var myError = browser.runtime.lastError; // null or Error object</pre> <h3 id="Valeur">Valeur</h3> @@ -44,37 +44,37 @@ gettingCookies.then(onGot, onError);</pre> <p>Définir un cookie, utiliser pour enregistrer le nouveau cookie ou signaler une erreur :</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> - <span class="keyword token">if</span> <span class="punctuation token">(</span>browser<span class="punctuation token">.runtime.</span>lastError<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>browser<span class="punctuation token">.runtime.</span>lastError<span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> <span class="keyword token">else</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="punctuation token">}</span> +<pre class="brush: js">function logCookie(c) { + if (browser.runtime.lastError) { + console.error(browser.runtime.lastError); + } else { + console.log(c); + } +} -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> +browser.cookies.set( + {url: "https://developer.mozilla.org/"}, logCookie -<span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre> +);</pre> <p>La même chose, mais en utilisant une promesse de gérer le résultat de <code>setCookie()</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> +<pre class="brush: js">function logCookie(c) { + console.log(c); +} -<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> +function logError(e) { + console.error(e); +} -<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> +var setCookie = browser.cookies.set( + {url: "https://developer.mozilla.org/"} +); + +setCookie.then(logCookie, logError);</pre> <div class="note"> -<p>Note: <code>runtime.lastError</code> est un alias pour {{WebExtAPIRef("extension.lastError")}}: Ils sont ensemble, et la vérification de l'un fonctionnera.</p> +<p><strong>Note :</strong> <code>runtime.lastError</code> est un alias pour {{WebExtAPIRef("extension.lastError")}}: Ils sont ensemble, et la vérification de l'un fonctionnera.</p> </div> <h2 id="Compatibilité_du_navigateur">Compatibilité du navigateur</h2> @@ -83,7 +83,7 @@ setCookie<span class="punctuation token">.</span><span class="function token">th <p>{{WebExtExamples}}</p> -<div class="note"><strong>Remerciements :</strong> +<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/runtime#event-onConnect"><code>chrome.runtime</code></a>. Cette documentation est dérivée de <a href="https://chromium.googlesource.com/chromium/src/+/master/extensions/common/api/runtime.json"><code>runtime.json</code></a> dans le code de Chromium code.</p> |