Installation
MV2 MV3 Chrome Firefox Safari
Overview
@webext-core/match-patterns
provides utilities for working with match patterns.
Installation
NPM
pnpm i @webext-core/match-patterns
import { MatchPattern } from '@webext-core/match-patterns';
CDN
curl -o match-patterns.js https://cdn.jsdelivr.net/npm/@webext-core/match-patterns/lib/index.global.js
<script src="/match-patterns.js"></script>
<script>
const { MatchPattern } = webExtCoreMatchPatterns;
</script>
Usage
MatchPattern
includes one function: includes
. It can be used to check if a URL is included (or matches) the match pattern.
import { MatchPattern } from '@webext-core/match-patterns';
const google = new MatchPattern('*://*.google.com');
google.includes('https://acounts.google.com'); // true
google.includes('https://google.com/search?q=test'); // true
const youtube = new MatchPattern('*://youtube.com/watch');
youtube.includes('https://youtube.com/watch'); // true
youtube.includes('https://youtube.com/mrbeast'); // false
youtube.includes('https://acounts.google.com'); // false
includes
also accepts URLs and window.location
google.includes(new URL('https://google.com'));
google.includes(window.location);
Table of Contents