history Permission — Chrome Extension Reference

5 min read

history Permission — Chrome Extension Reference

Overview

manifest.json Setup

{
  "permissions": ["history"]
}

Key APIs

chrome.history.search(query)

chrome.history.search({
  text: "github",           // Search query (empty string = all)
  startTime: Date.now() - 86400000,  // Last 24 hours
  maxResults: 100
}, (results) => {
  results.forEach(item => {
    console.log(item.title, item.url, item.visitCount, item.lastVisitTime);
  });
});

chrome.history.getVisits(details)

chrome.history.getVisits({ url: "https://github.com" }, (visits) => {
  visits.forEach(v => {
    console.log(v.visitTime, v.transition); // "typed", "link", "auto_bookmark", etc.
  });
});

chrome.history.addUrl(details)

chrome.history.addUrl({ url: "https://example.com" });

chrome.history.deleteUrl(details)

chrome.history.deleteUrl({ url: "https://example.com" });

chrome.history.deleteRange(range)

chrome.history.deleteRange({
  startTime: Date.now() - 3600000,  // Last hour
  endTime: Date.now()
}, () => console.log("Deleted last hour of history"));

chrome.history.deleteAll()

Events

chrome.history.onVisited

chrome.history.onVisited.addListener((historyItem) => {
  console.log("Visited:", historyItem.url, historyItem.title);
});

chrome.history.onVisitRemoved

HistoryItem Structure

interface HistoryItem {
  id: string;
  url?: string;
  title?: string;
  lastVisitTime?: number;
  visitCount?: number;
  typedCount?: number;    // Times user typed URL directly
}

Common Patterns

Browsing Analytics Dashboard

History Search Extension

Privacy Tool

Recently Visited Quick Access

Runtime Permission Check

import { checkPermission, requestPermission } from '@theluckystrike/webext-permissions';
const result = await checkPermission('history');
if (!result.granted) {
  const req = await requestPermission('history');
  if (!req.granted) {
    showMessage("History access needed for this feature");
    return;
  }
}
// Safe to use chrome.history

Security & Privacy Considerations

Gotchas

Common Errors

API Reference

Frequently Asked Questions

How do I search browser history in an extension?

Use chrome.history.search() to query the user’s browsing history. You can search by text, URL, and time range.

Can extensions delete history entries?

Yes, with the history permission, you can use chrome.history.deleteUrl() to remove specific URLs from history. —

Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.

No previous article
No next article