# github-url-detection

> Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.

Latest version **11.2.4** (published 2026-08-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install github-url-detection
pnpm add github-url-detection
yarn add github-url-detection
bun add github-url-detection
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 11.2.4 |
| Published | 2026-08-02 |
| First published | 2020-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.18 |
| Dependencies | 1 |
| Unpacked size | 75.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 136 |
| Author | Federico Brigante |
| Maintainers | fregante, refined-github |
| Keywords | github, page, routes, detect, test, extension |

## Links

- npm: https://www.npmjs.com/package/github-url-detection
- Repository: https://github.com/refined-github/github-url-detection
- Homepage: https://github.com/refined-github/github-url-detection#readme
- Issues: https://github.com/refined-github/github-url-detection/issues
- Funding: https://github.com/sponsors/fregante
- npm.io page: https://npm.io/package/github-url-detection

## Dependencies (1)

- [github-reserved-names](https://npm.io/package/github-reserved-names.md) ^2.1.3

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 11.2.4 (latest) — 2026-08-02
- 7.0.1-0 (next) — 2023-02-09
- 11.2.3 — 2026-07-12
- 11.2.2 — 2026-07-11
- 11.2.1 — 2026-04-15
- 11.2.0 — 2026-04-05
- 11.1.3 — 2026-03-02
- 11.1.2 — 2026-02-03
- 11.1.1 — 2026-02-01
- 11.1.0 — 2026-01-24
- 11.0.1 — 2026-01-21
- 11.0.0 — 2026-01-14
- 10.2.3 — 2026-01-09
- 10.2.2 — 2025-12-16
- 10.2.1 — 2025-06-18
- … 85 more at https://npm.io/package/github-url-detection/versions

## README

# <img width="438" align="right" src="https://user-images.githubusercontent.com/1402241/81425503-01b4d800-9158-11ea-9406-484a1ff37968.png"> github-url-detection

> Which GitHub page are you on? Is it an issue? Is it a list? Perfect for your WebExtension or userscript.

Battle-tested in [Refined GitHub](https://github.com/sindresorhus/refined-github) extension.

- Try the live [demo](https://refined-github.github.io/github-url-detection/)
- See the code and expected URLs for [every detection](https://github.com/refined-github/github-url-detection/blob/main/index.ts)

## Install

```sh
npm install github-url-detection
```

```js
// This package is pure ESM
import * as pageDetect from 'github-url-detection';
```

## Usage

```js
const href = 'https://github.com/refined-github/github-url-detection/issues/1';
if (pageDetect.isIssue(new URL(href))) { // Pass the URL as an `URL` object
	alert('The passed URL is of an issue!')
}

if (pageDetect.isRepo()) { // Uses `window.location.href` by default
	alert('You’re looking at a repo!')
}

if (pageDetect.isIssueOrPRList()) {
	alert('You’re looking at a issues and PRs list!')
}
```

## API

Most detections are URL-based while others need access to the current `document`. You can determine which ones are URL-based by looking at their signature: URL-based functions have a `url` parameter.

### URL-based detections

By default, URL-based detections use the `location` global if you don't pass a `url` argument.

```js
if (pageDetect.isIssueOrPRList()) {
	alert('You’re looking at a issues or PRs list!')
}
```

```js
if (pageDetect.isIssueOrPRList(new URL('https://github.com/refined-github/github-url-detection/pulls'))) {
	alert('You’re looking at a issues or PRs list!')
}
```

Notice that the `url` parameter is not a plain string but it has to be a proper `URL` or `location` object.

### Document-based detections

By default, `document`-based detections use the `document` global, which means they can only be used if you have the whole page, you can't just test any random URL string.

```js
if (pageDetect.isOrganizationProfile()) {
	alert('You’re on an organization profile, like https://github.com/babel')
}
```

### Async detections with `waitFor`

The `waitFor` helper function allows you to wait for a detection to become true by repeatedly checking it on each animation frame. This is useful for DOM-based detections that need to wait for elements to appear before the document is fully loaded.

```js
import {utils, isOrganizationProfile} from 'github-url-detection';

async function init() {
	// Wait for the detection to return true or for the document to be complete
	if (!await utils.waitFor(isOrganizationProfile)) {
		return; // Not an organization profile
	}

	// The page is now confirmed to be an organization profile
	console.log('On organization profile!');
}
```

The `waitFor` function:
- Repeatedly calls the detection function on each animation frame
- Stops when the detection returns `true` or when `document.readyState` is `'complete'`
- Returns the final result of the detection
- Works with any detection function that returns a boolean

## Related

- [github-reserved-names](https://github.com/Mottie/github-reserved-names) - Get a list, or check if a user or organization name is reserved by GitHub.
- [shorten-repo-url](https://github.com/fregante/shorten-repo-url) - Shorten GitHub links like GitHub shortens Issues and Commit links.

## License

MIT © [Federico Brigante](https://fregante.com)

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