webext-content-scripts
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -26,5 +26,5 @@ import type { ExtensionTypes } from 'webextension-polyfill'; | ||
export declare function executeScript({ tabId, frameId, files, allFrames, matchAboutBlank, runAt, }: InjectionDetails, { ignoreTargetErrors }?: InjectionOptions): Promise<void>; | ||
export declare function getTabsByUrl(patterns: string[]): Promise<number[]>; | ||
export declare function getTabsByUrl(matches: string[], excludeMatches?: string[]): Promise<number[]>; | ||
export declare function injectContentScript(where: MaybeArray<number | Target>, scripts: MaybeArray<ContentScript>, options?: InjectionOptions): Promise<void>; | ||
export declare function isScriptableUrl(url: string): boolean; | ||
export {}; |
12
index.js
import chromeP from 'webext-polyfill-kinda'; | ||
import { patternToRegex } from 'webext-patterns'; | ||
const gotScripting = typeof chrome === 'object' && 'scripting' in chrome; | ||
@@ -117,8 +118,11 @@ function castTarget(target) { | ||
} | ||
export async function getTabsByUrl(patterns) { | ||
if (patterns.length === 0) { | ||
export async function getTabsByUrl(matches, excludeMatches) { | ||
if (matches.length === 0) { | ||
return []; | ||
} | ||
const tabs = await chromeP.tabs.query({ url: patterns }); | ||
return tabs.map(tab => tab.id).filter((id) => typeof id === 'number'); | ||
const exclude = excludeMatches ? patternToRegex(...excludeMatches) : undefined; | ||
const tabs = await chromeP.tabs.query({ url: matches }); | ||
return tabs | ||
.filter(tab => tab.id && tab.url && (exclude ? !exclude.test(tab.url) : true)) | ||
.map(tab => tab.id); | ||
} | ||
@@ -125,0 +129,0 @@ export async function injectContentScript(where, scripts, options = {}) { |
{ | ||
"name": "webext-content-scripts", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Utility functions to inject content scripts in WebExtensions, for Manifest v2 and v3", | ||
@@ -40,2 +40,3 @@ "keywords": [ | ||
"unicorn/prefer-ternary": "off", | ||
"n/file-extension-in-import": "off", | ||
"@typescript-eslint/no-implicit-any-catch": "off", | ||
@@ -46,2 +47,3 @@ "@typescript-eslint/consistent-type-definitions": "off" | ||
"dependencies": { | ||
"webext-patterns": "^1.2.0", | ||
"webext-polyfill-kinda": "^0.10.0" | ||
@@ -52,6 +54,9 @@ }, | ||
"@types/chrome": "^0.0.206", | ||
"@types/jest": "^29.2.5", | ||
"@types/webextension-polyfill": "^0.9.2", | ||
"jest-chrome": "^0.8.0", | ||
"typescript": "^4.9.4", | ||
"vitest": "^0.27.1", | ||
"xo": "^0.53.1" | ||
} | ||
} |
17403
262
2
8
+ Addedwebext-patterns@^1.2.0
+ Addedescape-string-regexp@5.0.0(transitive)
+ Addedwebext-patterns@1.5.0(transitive)