TypeScript Definitions for Chrome Extensions

0.1.425 · active · verified Sun Apr 19

The `chrome-types` package provides official TypeScript declaration files for Chrome Extensions, automatically generated from the Chromium source code. This ensures the definitions are highly accurate and consistently up-to-date with the latest Chrome API changes. Published daily via GitHub Actions, the package reflects Chrome's HEAD revision, making it the most current source for Chrome extension types. It is currently at version 0.1.425. The default `index.d.ts` file includes only Manifest V3 (MV3) and newer types, while a separate `_all.d.ts` file is available for projects requiring definitions for deprecated Platform Apps APIs. This package is crucial for developers building Chrome extensions with TypeScript, providing robust type safety and autocompletion for the global `chrome` object and its various namespaces, distinguishing itself from community-maintained alternatives like `@types/chrome` by its direct origin from the Chromium project itself.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `tsconfig.json` to enable `chrome-types` and shows a basic Chrome extension background script utilizing `chrome.runtime`, `chrome.storage`, `chrome.action`, and `chrome.scripting` APIs with full TypeScript support.

{
  "compilerOptions": {
    "target": "es2020",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "types": ["chrome-types"], // Explicitly include chrome-types
    "moduleResolution": "node"
  },
  "include": ["src/**/*.ts", "manifest.json"],
  "exclude": ["node_modules"]
}

// src/background.ts
chrome.runtime.onInstalled.addListener(() => {
  console.log('Chrome extension installed.');
  chrome.storage.local.set({ greeting: 'Hello, Chrome Extensions!' }, () => {
    console.log('Initial greeting saved.');
  });
});

chrome.action.onClicked.addListener(async (tab) => {
  console.log(`Action clicked on tab: ${tab?.id}`);
  const data = await chrome.storage.local.get('greeting');
  console.log('Retrieved greeting:', data.greeting);
  
  if (tab?.id) {
    // Example: Injecting a content script programmatically
    chrome.scripting.executeScript({
      target: { tabId: tab.id },
      function: () => {
        alert('Hello from your Chrome extension!');
      },
    });
  }
});

view raw JSON →