Recherche dans l'historique du navigateur les objets history.HistoryItem
correspondant aux critères donnés.
C'est une fonction asynchrone qui renvoie une Promise
.
Syntaxe
var searching = browser.history.search( query // object )
Paramètres
query
- Un objet qui indique ce qu'il faut rechercher dans l'historique du navigateur. Cet objet a les champs suivants :
-
text
string
. Rechercher des éléments d'historique par URL et titre. La chaîne est divisée en termes de recherche distincts aux limites de l'espace. Chaque terme de recherche est insensible à la casse par rapport à l'URL et au titre de l'élément d'historique. L'élément d'historique sera renvoyé si tous les termes de recherche correspondent.- Par exemple, considérez cet article :
- URL:
"http://example.org"
Title:"Example Domain"
-
"http" -> matches "domain" -> matches "MAIN ample" -> matches "main tt" -> matches "main https" -> does not match
- Spécifiez une chaîne vide (
""
) pour récupérer tous les objetshistory.HistoryItem
qui répondent à tous les autres critères. startTime
Facultatifnumber
oustring
ouobject
. Une valeur indiquant une date et une heure. Cela peut être représenté par : un objetDate
, une chaîne de date ISO 8601, ou le nombre de millisecondes depuis l'époque. Si elle est fournie, cette option exclut les résultats dontlastVisitTime
est antérieure à cette heure. Si elle est omise, la recherche est limitée aux dernières 24 heures.endTime
Facultatifnumber
oustring
ouobject
. Une valeur indiquant une date et une heure. Cela peut être représenté par : un objetDate
, une chaîne de date ISO 8601, ou le nombre de millisecondes depuis l'époque. Si elle est fournie, cette option exclut les résultats dontlastVisitTime
est postérieur à cette fois. Si elle est omise, toutes les entrées sont prises en compte à partir de l'heure de début.maxResults
Facultatifnumber
. Le nombre maximum de résultats à récupérer. La valeur par défaut est 100, avec une valeur minimale de 1. La fonction renvoie une erreur si vous lui transmettez une valeurmaxResults
inférieure à 1.
Valeur retournée
Une Promise
sera remplie avec un tableau d'objets de type history.HistoryItem
, chacun décrivant un seul élément d'historique correspondant. Les articles sont triés dans l'ordre chronologique inverse.
Exemples
Consigne l'URL et la dernière heure de visite pour tous les éléments d'historique visités au cours des dernières 24 heures :
function onGot(historyItems) { for (item of historyItems) { console.log(item.url); console.log(new Date(item.lastVisitTime)); } } var searching = browser.history.search({text: ""}); searching.then(onGot);
Logs the URL and last visit time for all history items ever visited:
function onGot(historyItems) { for (item of historyItems) { console.log(item.url); console.log(new Date(item.lastVisitTime)); } } var searching = browser.history.search({ text: "", startTime: 0 }); searching.then(onGot);
Consigne l'URL et la dernière visite de la dernière visite sur une page contenant la chaîne "mozilla" :
function onGot(historyItems) { for (item of historyItems) { console.log(item.url); console.log(new Date(item.lastVisitTime)); } } var searching = browser.history.search({ text: "mozilla", startTime: 0, maxResults: 1 }); searching.then(onGot);
Example extensions
Compatibilité du navigateur
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Ordinateur | Mobile | ||||
---|---|---|---|---|---|
search | Chrome Support complet Oui | Edge Aucun support Non | Firefox Support complet 49 | Opera Support complet Oui | Firefox Android Aucun support Non |
Légende
- Support complet
- Support complet
- Aucun support
- Aucun support
Cette API est basée sur l'API Chromium chrome.history
. Cette documentation est dérivée de history.json
dans le code de Chromium.
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.
// 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.