To interact with the user's browser history, use the history API.
To use the history API, declare the "history"
permission in the extension manifest. For example:
{"name":"My extension",..."permissions":["history"],...}
The history API uses transition types to describe how the browser navigated to a particular URL on a particular visit. For example, if a user visits a page by clicking a link on another page, the transition type is "link". See the reference content for a list of transition types.
To try this API, install the history API example from the chrome-extension-samples repository.
An object encapsulating one result of a history query.
string
The unique identifier for the item.
number optional
When this page was last loaded, represented in milliseconds since the epoch.
string optional
The title of the page when it was last loaded.
number optional
The number of times the user has navigated to this page by typing in the address.
string optional
The URL navigated to by a user.
number optional
The number of times the user has navigated to this page.
"link" "typed" "auto_bookmark" "auto_subframe" "manual_subframe" "generated" "auto_toplevel" "form_submit" "reload" "keyword" "keyword_generated"
The user arrived at this page by clicking a link on another page.
The user arrived at this page by typing the URL in the address bar. This is also used for other explicit navigation actions.
The user arrived at this page through a suggestion in the UI, for example, through a menu item.
The user arrived at this page through subframe navigation that they didn't request, such as through an ad loading in a frame on the previous page. These don't always generate new navigation entries in the back and forward menus.
The user arrived at this page by selecting something in a subframe.
The user arrived at this page by typing in the address bar and selecting an entry that didn't look like a URL, such as a Google Search suggestion. For example, a match might have the URL of a Google Search result page, but it might appear to the user as "Search Google for ...". These are different from typed navigations because the user didn't type or see the destination URL. They're also related to keyword navigations.
The page was specified in the command line or is the start page.
The user arrived at this page by filling out values in a form and submitting the form. Not all form submissions use this transition type.
The user reloaded the page, either by clicking the reload button or by pressing Enter in the address bar. Session restore and Reopen closed tab also use this transition type.
The URL for this page was generated from a replaceable keyword other than the default search provider.
Corresponds to a visit generated for a keyword.
string
The URL for the operation. It must be in the format as returned from a call to history.search()
.
An object encapsulating one visit to a URL.
string
The unique identifier for the corresponding history.HistoryItem
.
boolean
True if the visit originated on this device. False if it was synced from a different device.
string
The visit ID of the referrer.
The transition type for this visit from its referrer.
string
The unique identifier for this visit.
number optional
When this visit occurred, represented in milliseconds since the epoch.
chrome.history.addUrl(
details: UrlDetails,
callback?: function,
)
Adds a URL to the history at the current time with a transition type of "link".
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.history.deleteAll(
callback?: function,
)
Deletes all items from the history.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.history.deleteRange(
range: object,
callback?: function,
)
Removes all items within the specified date range from the history. Pages will not be removed from the history unless all visits fall within the range.
object
number
Items added to history before this date, represented in milliseconds since the epoch.
number
Items added to history after this date, represented in milliseconds since the epoch.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.history.deleteUrl(
details: UrlDetails,
callback?: function,
)
Removes all occurrences of the given URL from the history.
function optional
The callback
parameter looks like: () => void
Promise<void>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.history.getVisits(
details: UrlDetails,
callback?: function,
)
Retrieves information about visits to a URL.
function optional
The callback
parameter looks like: (results: VisitItem[]) => void
Promise<VisitItem[]>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.history.search(
query: object,
callback?: function,
)
Searches the history for the last visit time of each page matching the query.
object
number optional
Limit results to those visited before this date, represented in milliseconds since the epoch.
number optional
The maximum number of results to retrieve. Defaults to 100.
number optional
Limit results to those visited after this date, represented in milliseconds since the epoch. If property is not specified, it will default to 24 hours.
string
A free-text query to the history service. Leave this empty to retrieve all pages.
function optional
The callback
parameter looks like: (results: HistoryItem[]) => void
Promise<HistoryItem[]>
Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.
chrome.history.onVisited.addListener(
callback: function,
)
Fired when a URL is visited, providing the HistoryItem
data for that URL. This event fires before the page has loaded.
function
The callback
parameter looks like: (result: HistoryItem) => void
chrome.history.onVisitRemoved.addListener(
callback: function,
)
Fired when one or more URLs are removed from history. When all visits have been removed the URL is purged from history.
function
The callback
parameter looks like: (removed: object) => void
object
boolean
True if all history was removed. If true, then urls will be empty.
string[] optional
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-05-24 UTC.