# are-they-here

> Browser tab tracker

Latest version **0.1.0** (published 2017-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install are-they-here
pnpm add are-they-here
yarn add are-they-here
bun add are-they-here
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-05-17 |
| First published | 2017-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alexander Komarov |
| Maintainers | akxcv |
| Keywords | tab, tracker, active, focus, browser |

## Links

- npm: https://www.npmjs.com/package/are-they-here
- Repository: https://github.com/akxcv/are-they-here
- Homepage: https://github.com/akxcv/are-they-here#readme
- Issues: https://github.com/akxcv/are-they-here/issues
- npm.io page: https://npm.io/package/are-they-here

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-05-17

## README

# are-they-here

**are-they-here** is a simple package that determines the *last active tab of the domain*.
Because `localStorage` is persisted across all tabs of a single domain, this kind of tracking
is possible.

## How it works

1. All tabs receive a random ID.
2. When any activity\* happens in a tab, it's marked as *active*.
3. There can only be *one* active tab for a domain in a given time.

That is, if there's only one tab of `example.com` is open, it's always considered active.
When two or more tabs of `example.com` are open and user switches between them, active tab changes.

\* - "any activity" means:

- window received focus;
- mouse movement detected;
- document has been scrolled;
- key press detected.

## Installation

Install with [yarn](https://github.com/yarnpkg/yarn):
```sh
$ yarn add are-they-here
```

## Usage

**are they here** provides four functions:

- `areTheyHere()` - true if current tab is active, false otherwise;
- `ifTheyAreHere(cb)` - perform callback (`cb`) if current tab is active;
- `unlessTheyAreHere(cb)` - perform callback (`cb`) if current tab is NOT active;
- `whenTheyCome(cb)` - perform callback (`cb`) every time current tab *becomes* active.

### Example

```js
import { unlessTheyAreHere, whenTheyCome } from 'are-they-here'

document.addEventListener('DOMContentLoaded', () => {
  unlessTheyAreHere(() => console.log('You just missed DOMContentLoaded! :/'))
})

whenTheyCome(() => console.log('Greetings to this tab!'))
```

---
_Source: https://npm.io/package/are-they-here · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
