Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#71963 updated types for webextension-polyf…
Browse files Browse the repository at this point in the history
…ill by @Lusito
  • Loading branch information
Lusito authored Feb 22, 2025
1 parent 6ca7ec0 commit 162fd26
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 81 deletions.
16 changes: 14 additions & 2 deletions types/webextension-polyfill/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { TabGroups as ImportedTabGroups } from "./namespaces/tabGroups";
import { Tabs as ImportedTabs } from "./namespaces/tabs";
import { Theme as ImportedTheme } from "./namespaces/theme";
import { TopSites as ImportedTopSites } from "./namespaces/topSites";
import { Trial as ImportedTrial } from "./namespaces/trial";
import { Types as ImportedTypes } from "./namespaces/types";
import { UserScripts as ImportedUserScripts } from "./namespaces/userScripts";
import { WebNavigation as ImportedWebNavigation } from "./namespaces/webNavigation";
Expand Down Expand Up @@ -389,13 +390,18 @@ declare namespace Browser {
*/
const topSites: TopSites.Static;

/**
* Permissions: "trialML"
*/
const trial: Trial.Static;

/**
* Contains types used by other schemas.
*/
const types: Types.Static;

/**
* Permissions: "manifest:user_scripts"
* Permissions: "manifest:user_scripts", "userScripts"
*/
const userScripts: UserScripts.Static;

Expand Down Expand Up @@ -751,13 +757,18 @@ declare namespace Browser {
*/
topSites: TopSites.Static;

/**
* Permissions: "trialML"
*/
trial: Trial.Static;

/**
* Contains types used by other schemas.
*/
types: Types.Static;

/**
* Permissions: "manifest:user_scripts"
* Permissions: "manifest:user_scripts", "userScripts"
*/
userScripts: UserScripts.Static;

Expand Down Expand Up @@ -835,6 +846,7 @@ declare namespace Browser {
export import Tabs = ImportedTabs;
export import Theme = ImportedTheme;
export import TopSites = ImportedTopSites;
export import Trial = ImportedTrial;
export import Types = ImportedTypes;
export import UserScripts = ImportedUserScripts;
export import WebNavigation = ImportedWebNavigation;
Expand Down
4 changes: 2 additions & 2 deletions types/webextension-polyfill/namespaces/action.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ export namespace Action {
/**
* Sets the text color for the badge.
*/
setBadgeTextColor(details: SetBadgeTextColorDetailsType): void;
setBadgeTextColor(details: SetBadgeTextColorDetailsType): Promise<void>;

/**
* Gets the text color of the browser action badge.
*/
getBadgeTextColor(details: Details): void;
getBadgeTextColor(details: Details): Promise<ColorArray>;

/**
* Enables the browser action for a tab. By default, browser actions are enabled.
Expand Down
4 changes: 2 additions & 2 deletions types/webextension-polyfill/namespaces/captivePortal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export namespace CaptivePortal {
/**
* Returns the current portal state, one of `unknown`, `not_captive`, `unlocked_portal`, `locked_portal`.
*/
getState(): void;
getState(): Promise<"unknown" | "not_captive" | "unlocked_portal" | "locked_portal">;

/**
* Returns the time difference between NOW and the last time a request was completed in milliseconds.
*/
getLastChecked(): void;
getLastChecked(): Promise<number>;

/**
* Fired when the captive portal state changes.
Expand Down
5 changes: 5 additions & 0 deletions types/webextension-polyfill/namespaces/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export namespace Commands {
*/
getAll(): Promise<Command[]>;

/**
* Open extension shortcuts configuration page.
*/
openShortcutSettings(): void;

/**
* Fired when a registered command is activated using a keyboard shortcut.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export namespace ContextualIdentities {
* @param cookieStoreIds The ID or list of IDs of the contextual identity cookie stores.
* @param position The position the contextual identity should move to.
*/
move(cookieStoreIds: string | string[], position: number): void;
move(cookieStoreIds: string | string[], position: number): Promise<void>;

/**
* Deletes a contextual identity by its cookie Store ID.
Expand Down
6 changes: 6 additions & 0 deletions types/webextension-polyfill/namespaces/cookies.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export namespace Cookies {
* Optional.
*/
topLevelSite?: string;

/**
* Whether or not the cookie is in a third-party context, respecting ancestor chains.
* Optional.
*/
hasCrossSiteAncestor?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export namespace DeclarativeNetRequest {
| "imageset"
| "web_manifest"
| "speculative"
| "json"
| "other";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export namespace DevtoolsPanels {
*
* @param path Relative path of an extension page to display within the sidebar.
*/
setPage(path: Manifest.ExtensionURL): void;
setPage(path: Manifest.ExtensionURL): Promise<void>;

/**
* Fired when the sidebar pane becomes visible as a result of user switching to the panel that hosts it.
Expand Down
5 changes: 4 additions & 1 deletion types/webextension-polyfill/namespaces/geckoProfiler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export namespace GeckoProfiler {
| "responsiveness"
| "cpufreq"
| "bandwidth"
| "memory";
| "memory"
| "tracing"
| "sandbox"
| "flows";

type supports = "windowLength";

Expand Down
84 changes: 26 additions & 58 deletions types/webextension-polyfill/namespaces/manifest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export namespace Manifest {
*/
browser_specific_settings?: BrowserSpecificSettings;

/**
* Name must be at least 2, at should be at most 75 characters
*/
name: string;

/**
Expand Down Expand Up @@ -97,10 +100,7 @@ export namespace Manifest {
/**
* Optional.
*/
background?:
| WebExtensionManifestBackgroundC1Type
| WebExtensionManifestBackgroundC2Type
| WebExtensionManifestBackgroundC3Type;
background?: WebExtensionManifestBackgroundType;

/**
* Alias property for options_ui.page, ignored when options_ui.page is set. When using this property the options page is
Expand Down Expand Up @@ -279,6 +279,8 @@ export namespace Manifest {
size: number;
}

type OptionalOnlyPermission = "trialML" | "userScripts";

type OptionalPermissionNoPrompt =
| "idle"
| "cookies"
Expand Down Expand Up @@ -320,7 +322,7 @@ export namespace Manifest {
| "webNavigation"
| "identity.email";

type OptionalPermissionOrOrigin = OptionalPermission | MatchPattern;
type OptionalPermissionOrOrigin = OptionalPermission | OptionalOnlyPermission | MatchPattern;

type PermissionPrivileged = "mozillaAddons" | "activityLog" | "networkStatus" | "normandyAddonStudy";

Expand Down Expand Up @@ -673,40 +675,44 @@ export namespace Manifest {
*/
type WebExtensionManifestIncognitoEnum = "not_allowed" | "spanning" | "split";

interface WebExtensionManifestBackgroundC1Type {
page: ExtensionURL;
/**
* Only supported for page/scripts; not for service_worker yet, see bug 1775574
*/
type WebExtensionManifestBackgroundTypeEnum = "module" | "classic";

type WebExtensionManifestBackgroundPreferredEnvironmentItemEnum = "service_worker" | "document";

interface WebExtensionManifestBackgroundType {
/**
* Optional.
*/
persistent?: boolean;
}
service_worker?: ExtensionURL;

type WebExtensionManifestBackgroundC2TypeEnum = "module" | "classic";
/**
* Optional.
*/
page?: ExtensionURL;

interface WebExtensionManifestBackgroundC2Type {
scripts: ExtensionURL[];
/**
* Optional.
*/
scripts?: ExtensionURL[];

/**
* Only supported for page/scripts; not for service_worker yet, see bug 1775574
* Optional.
*/
type?: WebExtensionManifestBackgroundC2TypeEnum;
type?: WebExtensionManifestBackgroundTypeEnum;

/**
* Optional.
*/
persistent?: boolean;
}

interface WebExtensionManifestBackgroundC3Type {
service_worker: ExtensionURL;

/**
* Even though Manifest V3, does not support multiple background scripts, you can optionally declare the service worker as
* an ES Module by specifying "type": "module", which allows you to import further code.
* Optional.
*/
type?: "module";
preferred_environment?: WebExtensionManifestBackgroundPreferredEnvironmentItemEnum[];
}

interface WebExtensionManifestOptionsUiType {
Expand Down Expand Up @@ -761,37 +767,6 @@ export namespace Manifest {
extension_ids?: Array<ExtensionID | "*">;
}

interface WebExtensionManifestChromeSettingsOverridesSearchProviderParamsItemType {
/**
* A url parameter name
*/
name: string;

/**
* The type of param can be either "purpose" or "pref".
* Optional.
*/
condition?: "purpose" | "pref";

/**
* The preference to retrieve the value from.
* Optional.
*/
pref?: string;

/**
* The context that initiates a search, required if condition is "purpose".
* Optional.
*/
purpose?: "contextmenu" | "searchbar" | "homepage" | "keyword" | "newtab";

/**
* A url parameter value.
* Optional.
*/
value?: string;
}

interface WebExtensionManifestChromeSettingsOverridesSearchProviderType {
name: string;

Expand Down Expand Up @@ -847,13 +822,6 @@ export namespace Manifest {
* Optional.
*/
is_default?: boolean;

/**
* A list of optional search url parameters. This allows the additon of search url parameters based on how the search is
* performed in Firefox.
* Optional.
*/
params?: WebExtensionManifestChromeSettingsOverridesSearchProviderParamsItemType[];
}

interface WebExtensionManifestChromeSettingsOverridesType {
Expand Down
2 changes: 1 addition & 1 deletion types/webextension-polyfill/namespaces/networkStatus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export namespace NetworkStatus {

interface Static {
/**
* Returns the $(ref:NetworkLinkInfo} of the current network connection.
* Returns the $(ref:NetworkLinkInfo) of the current network connection.
*/
getLinkInfo(): void;

Expand Down
4 changes: 2 additions & 2 deletions types/webextension-polyfill/namespaces/permissions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export namespace Permissions {
/**
* Optional.
*/
permissions?: Manifest.OptionalPermission[];
permissions?: Array<Manifest.OptionalPermission | Manifest.OptionalOnlyPermission>;

/**
* Optional.
Expand All @@ -25,7 +25,7 @@ export namespace Permissions {
/**
* Optional.
*/
permissions?: Manifest.Permission[];
permissions?: Array<Manifest.Permission | Manifest.OptionalOnlyPermission>;

/**
* Optional.
Expand Down
26 changes: 26 additions & 0 deletions types/webextension-polyfill/namespaces/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ export namespace Runtime {
* Optional.
*/
url?: string;

/**
* The worldId of the USER_SCRIPT world that sent the message. Only present on onUserScriptMessage and onUserScriptConnect
* (in port.sender) events.
* Optional.
*/
userScriptWorldId?: string;
}

/**
Expand Down Expand Up @@ -560,6 +567,11 @@ export namespace Runtime {
*/
onConnect: Events.Event<(port: Port) => void>;

/**
* Fired when a connection is made from a USER_SCRIPT world registered through the userScripts API.
*/
onUserScriptConnect: Events.Event<(port: Port) => void>;

/**
* Fired when a connection is made from another extension.
*/
Expand Down Expand Up @@ -601,6 +613,20 @@ export namespace Runtime {
) => Promise<unknown> | true | undefined
>;

/**
* Fired when a message is sent from a USER_SCRIPT world registered through the userScripts API.
*
* @param message Optional. The message sent by the calling script.
* @param sendResponse Function to call (at most once) when you have a response. The argument should be any JSON-ifiable
* object. If you have more than one <code>onMessage</code> listener in the same document,
* then only one may send a response. This function becomes invalid when the event listener returns,
* unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep
* the message channel open to the other end until <code>sendResponse</code> is called).
*/
onUserScriptMessage: Events.Event<
(message: unknown, sender: MessageSender, sendResponse: () => void) => boolean | undefined
>;

/**
* Fired when a runtime performance issue is detected with the extension. Observe this event to be proactively notified of
* runtime performance problems with the extension.
Expand Down
2 changes: 1 addition & 1 deletion types/webextension-polyfill/namespaces/search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export namespace Search {
/**
* Perform a search.
*/
search(searchProperties: SearchSearchPropertiesType): void;
search(searchProperties: SearchSearchPropertiesType): Promise<void>;

/**
* Use the chrome.search API to search via the default provider.
Expand Down
2 changes: 1 addition & 1 deletion types/webextension-polyfill/namespaces/sidebarAction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export namespace SidebarAction {
/**
* Toggles the extension sidebar in the active window.
*/
toggle(): void;
toggle(): Promise<void>;

/**
* Checks whether the sidebar action is open.
Expand Down
Loading

0 comments on commit 162fd26

Please sign in to comment.