docs.rodeo

MDN Web Docs mirror

history.search()

{{AddonSidebar}} 

Searches the browser’s history for {{WebExtAPIRef("history.HistoryItem")}}  objects matching the given criteria.

This is an asynchronous function that returns a Promise.

Syntax

let searching = browser.history.search(
  query                  // object
)

Parameters

Return value

A Promise will be fulfilled with an array of objects of type {{WebExtAPIRef("history.HistoryItem")}} , each describing a single matching history item. Items are sorted in reverse chronological order.

Examples

Logs the URL and last visit time for all history items visited in the last 24 hours:

function onGot(historyItems) {
  for (const item of historyItems) {
    console.log(item.url);
    console.log(new Date(item.lastVisitTime));
  }
}

browser.history.search({ text: "" }).then(onGot);

Logs the URL and last visit time for all history items ever visited:

function onGot(historyItems) {
  for (const item of historyItems) {
    console.log(item.url);
    console.log(new Date(item.lastVisitTime));
  }
}

browser.history
  .search({
    text: "",
    startTime: 0,
  })
  .then(onGot);

Logs the URL and last visit time of the most recent visit to a page that contain the string “mozilla”:

function onGot(historyItems) {
  for (const item of historyItems) {
    console.log(item.url);
    console.log(new Date(item.lastVisitTime));
  }
}

browser.history
  .search({
    text: "mozilla",
    startTime: 0,
    maxResults: 1,
  })
  .then(onGot);

{{WebExtExamples}} 

Browser compatibility

{{Compat}} 

[!NOTE] This API is based on Chromium’s chrome.history API. This documentation is derived from history.json in the Chromium code.

In this article

View on MDN