-
-
Notifications
You must be signed in to change notification settings - Fork 467
fix(types): Add type safety to browser.runtime.executeScript files option
#2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1fd9fd8
d827f7a
c2ba008
e204bce
b301497
e2293ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| * @module wxt/browser | ||
| */ | ||
| import { browser as _browser, type Browser } from '@wxt-dev/browser'; | ||
| import type { ScriptPublicPath } from './utils/inject-script'; | ||
|
|
||
| /** | ||
| * This interface is empty because it is generated per-project when running `wxt prepare`. See: | ||
|
|
@@ -23,9 +24,39 @@ export interface WxtRuntime {} | |
| */ | ||
| export interface WxtI18n {} | ||
|
|
||
| export type WxtBrowser = Omit<typeof _browser, 'runtime' | 'i18n'> & { | ||
| type ScriptInjection<Args extends any[], Result> = | ||
| Browser.scripting.ScriptInjection<Args, Result> extends infer T | ||
| ? T extends { files: string[] } | ||
| ? Omit<T, 'files'> & { files: ScriptPublicPath[] } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API docs say that file injections can be either CSS or JS, which does not align with my understanding of
If this is the case, we'd need to add more union to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it should be fine for now. MDN doesn't include CSS files in their docs: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript I'd say it's fine for now, if someone opens an issue we'll know what needs added. |
||
| : T | ||
| : never; | ||
| type InjectionResult<Result> = Array< | ||
| Browser.scripting.InjectionResult<Awaited<Result>> | ||
| >; | ||
|
|
||
| export interface WxtScripting { | ||
| executeScript: { | ||
| /** | ||
| * @see {@link Browser.scripting.executeScript} | ||
| */ | ||
| <Args extends any[], Result>( | ||
| injection: ScriptInjection<Args, Result>, | ||
| ): Promise<InjectionResult<Result>>; | ||
| <Args extends any[], Result>( | ||
| injection: ScriptInjection<Args, Result>, | ||
| callback: (results: InjectionResult<Result>) => void, | ||
| ): void; | ||
| }; | ||
| } | ||
|
|
||
| export type WxtBrowser = Omit< | ||
| typeof _browser, | ||
| 'runtime' | 'i18n' | 'scripting' | ||
| > & { | ||
| runtime: WxtRuntime & Omit<(typeof _browser)['runtime'], 'getURL'>; | ||
| i18n: WxtI18n & Omit<(typeof _browser)['i18n'], 'getMessage'>; | ||
| scripting: WxtScripting & | ||
| Omit<(typeof _browser)['scripting'], 'executeScript'>; | ||
| }; | ||
|
|
||
| export const browser: WxtBrowser = _browser; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.