Skip to content

API for other addons

Lionel Wong edited this page Jun 8, 2023 · 7 revisions

This document assumes familiarity with web extension development.

Request information about windows from Winger

Winger manages and stores certain data associated with windows; this data can be accessed by other extensions via this API. Let's look at some examples first, then an explanation in detail on how to use the API.

Examples

Get names of all open windows:

const windowInfos = await browser.runtime.sendMessage('winman@lionelw', { 
  type: 'info', 
  properties: ['givenName'],
});
// [
//   { id: 3, givenName: 'Big Project' },
//   { id: 5, givenName: 'Socials' },
//   { id: 7, givenName: 'toread' },
//   { id: 9, givenName: '🚗 June roadtrip' },
// ]

Get a window's name and last-focused time:

const windowInfos = await browser.runtime.sendMessage('winman@lionelw', { 
  type: 'info', 
  properties: ['givenName', 'lastFocused'],
  windowIds: [3],
});
// [ { id: 3, givenName: 'Big Project', lastFocused: 1686186776834 } ]

Syntax

We use runtime.sendMessage to send a request to Winger, whose extension ID is 'winman@lionelw'.

The request object should contain a type: 'info' property, and at least one of the following properties:

  • properties

    An array of window properties to request. The following are available:

    • 'givenName' – Name of a window, assigned by the user via Winger
    • 'lastFocused' – The last epoch time a window received focus, as recorded by Winger
    • 'firstSeen' – The epoch time a window was created while Winger was active, or otherwise, the first time a window was encountered by Winger
  • windowIds (optional)

    An array of window IDs. If absent, requests data for all windows.

Return value

A Promise that fulfills with an array of window objects, each containing a window ID and requested properties.