Skip to main content

Overview

The glide.tabs API provides methods for querying, managing, and controlling browser tabs. This includes getting the active tab, finding tabs by properties, and unloading tabs to reduce memory usage.

Methods

active()

Returns the active tab for the currently focused window.
glide.tabs.active(): Promise<glide.TabWithID>
return
Promise<glide.TabWithID>
A promise that resolves to the active tab object with a guaranteed id property.
Note: This is equivalent to:
const tab = await browser.tabs.query({ active: true, currentWindow: true })[0];
But with additional error handling for invalid states.

get_first()

Find the first tab matching the given query filter.
glide.tabs.get_first(
  query: Browser.Tabs.QueryQueryInfoType
): Promise<Browser.Tabs.Tab | undefined>
query
Browser.Tabs.QueryQueryInfoType
required
Query object to filter tabs. Supports properties like:
  • title: Match tab title
  • url: Match tab URL (supports wildcards)
  • active: Whether the tab is active
  • currentWindow: Whether the tab is in the current window
  • And other standard WebExtension tab query properties
return
Promise<Browser.Tabs.Tab | undefined>
A promise that resolves to the first matching tab, or undefined if no tabs match.

query()

Gets all tabs that have the specified properties, or all tabs if no properties are specified.
glide.tabs.query(
  query: Browser.Tabs.QueryQueryInfoType
): Promise<Browser.Tabs.Tab[]>
query
Browser.Tabs.QueryQueryInfoType
required
Query object to filter tabs. Same properties as get_first().
return
Promise<Browser.Tabs.Tab[]>
A promise that resolves to an array of all matching tabs. Returns an empty array if no tabs match.

unload()

Unload the given tabs to reduce memory usage.
glide.tabs.unload(
  ...tabs: Array<number | Browser.Tabs.Tab>
): Promise<void>
tabs
Array<number | Browser.Tabs.Tab>
required
Variable number of tabs to unload. Can be tab IDs (numbers) or tab objects.
return
Promise<void>
A promise that resolves when all tabs have been unloaded.
You cannot unload the currently active tab. If you attempt to do so, an error will be thrown:
Error: active tabs cannot be unloaded
Unloading tabs is similar to Firefox’s “Unload Tab” feature. The tab remains visible in the tab bar but its content is freed from memory. When you click on an unloaded tab, it automatically reloads.Learn more about unloading tabs

Complete Example

glide.ts
// Create a keymap to manage memory by unloading old tabs
glide.keymaps.set('normal', '<leader>tu', async () => {
  const allTabs = await glide.tabs.query({});
  const activeTab = await glide.tabs.active();
  
  // Unload all tabs except the active one
  const tabsToUnload = allTabs.filter(tab => 
    tab.id !== activeTab.id && !tab.pinned
  );
  
  if (tabsToUnload.length > 0) {
    await glide.tabs.unload(...tabsToUnload);
    console.log(`Unloaded ${tabsToUnload.length} tabs`);
  }
});

// Find and switch to a specific tab
glide.keymaps.set('normal', '<leader>fg', async () => {
  const githubTab = await glide.tabs.get_first({ 
    url: "*://github.com/*" 
  });
  
  if (githubTab?.id) {
    await browser.tabs.update(githubTab.id, { active: true });
  }
});

Type Reference

glide.TabWithID

A tab object that is guaranteed to have an id property:
type TabWithID = Omit<Browser.Tabs.Tab, "id"> & { id: number };
This extends the standard Browser.Tabs.Tab but ensures the id is always present (not undefined).