Skip to content

Commit 7a23f66

Browse files
authored
🤖 Merge PR DefinitelyTyped#74789 [chrome] several fixes by @erwanjugand
1 parent 14d43b1 commit 7a23f66

2 files changed

Lines changed: 56 additions & 19 deletions

File tree

types/chrome/index.d.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,10 @@ declare namespace chrome {
346346
export function setIcon(details: TabIconDetails, callback: () => void): void;
347347

348348
/**
349-
* Sets the html document to be opened as a popup when the user clicks on the action's icon.
349+
* Sets the HTML document to be opened as a popup when the user clicks on the action's icon.
350350
*
351351
* Can return its result via Promise.
352+
* @since Chrome 96
352353
*/
353354
export function setPopup(details: PopupDetails): Promise<void>;
354355
export function setPopup(details: PopupDetails, callback: () => void): void;
@@ -1165,6 +1166,7 @@ declare namespace chrome {
11651166
* Clears websites' cache storage data.
11661167
*
11671168
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
1169+
* @since Chrome 72
11681170
*/
11691171
export function removeCacheStorage(options: RemovalOptions): Promise<void>;
11701172
export function removeCacheStorage(options: RemovalOptions, callback: () => void): void;
@@ -2433,7 +2435,17 @@ declare namespace chrome {
24332435
* Exactly one of `imageData` or `path` must be specified. Both are dictionaries mapping a number of pixels to an image representation. The image representation in `imageData` is an `ImageData` object; for example, from a `canvas` element, while the image representation in `path` is the path to an image file relative to the extension's manifest. If `scale` screen pixels fit into a device-independent pixel, the `scale * n` icon is used. If that scale is missing, another image is resized to the required size.
24342436
*/
24352437
export class SetIcon {
2436-
constructor(options?: { imageData?: ImageData | { [size: string]: ImageData } | undefined });
2438+
constructor(
2439+
options:
2440+
| {
2441+
imageData: ImageData | { [index: number]: ImageData };
2442+
path?: string | { [index: number]: string } | undefined;
2443+
}
2444+
| {
2445+
imageData?: ImageData | { [index: number]: ImageData } | undefined;
2446+
path: string | { [index: number]: string };
2447+
},
2448+
);
24372449
}
24382450

24392451
/** Provides the Declarative Event API consisting of {@link events.Event.addRules addRules}, {@link events.Event.removeRules removeRules}, and {@link events.Event.getRules getRules}. */
@@ -3330,7 +3342,7 @@ declare namespace chrome {
33303342
/** Indicates the data type of the option. The requested data type must match the real data type of the underlying option. */
33313343
type: `${OptionType}`;
33323344
/** Indicates the value to set. Leave unset to request automatic setting for options that have `autoSettable` enabled. The data type supplied for `value` must match `type`. */
3333-
value?: string | number | boolean | number;
3345+
value?: string | number | boolean | number[];
33343346
}
33353347

33363348
/**
@@ -3560,6 +3572,8 @@ declare namespace chrome {
35603572
/**
35613573
* Performs a document scan and returns a Promise that resolves with a {@link ScanResults} object. If a callback is passed to this function, the returned data is passed to it instead.
35623574
* @param options An object containing scan parameters.
3575+
*
3576+
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
35633577
*/
35643578
export function scan(options: ScanOptions): Promise<ScanResults>;
35653579
export function scan(options: ScanOptions, callback: (result: ScanResults) => void): void;
@@ -4364,9 +4378,12 @@ declare namespace chrome {
43644378
}
43654379

43664380
/**
4367-
* Retrieves the network details of the device's default network. If the user is not affiliated or the device is not connected to a network, runtime.lastError will be set with a failure reason.
4381+
* Retrieves the network details of the device's default network. If the user is not affiliated or the device is not connected to a network, {@link runtime.lastError} will be set with a failure reason.
43684382
* @param callback Called with the device's default network's NetworkDetails.
4383+
*
4384+
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
43694385
*/
4386+
export function getNetworkDetails(): Promise<NetworkDetails>;
43704387
export function getNetworkDetails(callback: (networkDetails: NetworkDetails) => void): void;
43714388
}
43724389

@@ -6308,7 +6325,7 @@ declare namespace chrome {
63086325
* This API is different from identity.getAccounts in two ways. The information returned is available offline, and it only applies to the primary account for the profile.
63096326
* @param details Profile options.
63106327
*
6311-
* Can return its result via Promise since Chrome 105.
6328+
* Can return its result via Promise since Chrome 106.
63126329
*/
63136330
export function getProfileUserInfo(details?: ProfileDetails): Promise<ProfileUserInfo>;
63146331
export function getProfileUserInfo(
@@ -6323,7 +6340,7 @@ declare namespace chrome {
63236340
* If an access token is discovered to be invalid, it should be passed to removeCachedAuthToken to remove it from the cache. The app may then retrieve a fresh token with `getAuthToken`.
63246341
* @param details Token information.
63256342
*
6326-
* Can return its result via Promise since Chrome 105.
6343+
* Can return its result via Promise since Chrome 106.
63276344
*/
63286345
export function removeCachedAuthToken(details: InvalidTokenDetails): Promise<void>;
63296346
export function removeCachedAuthToken(details: InvalidTokenDetails, callback: () => void): void;
@@ -7911,7 +7928,7 @@ declare namespace chrome {
79117928

79127929
export enum ClientCertificateType {
79137930
ECDSA_SIGN = "ecdsaSign",
7914-
RAS_SIGN = "rasSign",
7931+
RSA_SIGN = "rsaSign",
79157932
}
79167933

79177934
export interface SelectDetails {
@@ -8806,7 +8823,7 @@ declare namespace chrome {
88068823
export type QueryInfo =
88078824
& {
88088825
/** String to query with the default search provider. */
8809-
text?: string | undefined;
8826+
text: string;
88108827
}
88118828
& (
88128829
| {
@@ -12142,7 +12159,7 @@ declare namespace chrome {
1214212159
* Called when the list of {@link TtsVoice} that would be returned by getVoices has changed.
1214312160
* @since Chrome 124
1214412161
*/
12145-
const onVoicesChanged: chrome.events.Event<() => void>;
12162+
export const onVoicesChanged: chrome.events.Event<() => void>;
1214612163
}
1214712164

1214812165
////////////////////
@@ -13094,7 +13111,7 @@ declare namespace chrome {
1309413111
EXTRA_HEADERS = "extraHeaders",
1309513112
}
1309613113

13097-
/** @since Chrome 44 */
13114+
/** @since Chrome 79 */
1309813115
export enum OnErrorOccurredOptions {
1309913116
/** Specifies that headers can violate Cross-Origin Resource Sharing (CORS). */
1310013117
EXTRA_HEADERS = "extraHeaders",
@@ -13286,14 +13303,14 @@ declare namespace chrome {
1328613303
extends SetPartial<WebRequestDetails, "documentId" | "documentLifecycle" | "frameType">
1328713304
{
1328813305
/** Contains the HTTP request body data. Only provided if extraInfoSpec contains 'requestBody'. */
13289-
requestBody: {
13306+
requestBody?: {
1329013307
/** Errors when obtaining request body data. */
1329113308
error?: string;
1329213309
/** If the request method is POST and the body is a sequence of key-value pairs encoded in UTF8, encoded as either multipart/form-data, or application/x-www-form-urlencoded, this dictionary is present and for each key contains the list of all values for that key. If the data is of another media type, or if it is malformed, the dictionary is not present. An example value of this dictionary is {'key': \['value1', 'value2'\]}. */
1329313310
formData?: { [key: string]: FormDataItem[] };
1329413311
/** If the request method is PUT or POST, and the body is not already parsed in formData, then the unparsed request body elements are contained in this array. */
1329513312
raw?: UploadData[];
13296-
} | undefined;
13313+
};
1329713314
}
1329813315

1329913316
export interface OnBeforeSendHeadersDetails extends WebRequestDetails {
@@ -14345,7 +14362,7 @@ declare namespace chrome {
1434514362
* The headers provided by a hypothetical response if the request does not get blocked or redirected before it is sent. Represented as an object which maps a header name to a list of string values. If not specified, the hypothetical response would return empty response headers, which can match rules which match on the non-existence of headers. E.g. `{"content-type": ["text/html; charset=utf-8", "multipart/form-data"]}`
1434614363
* @since Chrome 129
1434714364
*/
14348-
responseHeaders?: { [name: string]: unknown };
14365+
responseHeaders?: { [name: string]: string[] };
1434914366
/** The ID of the tab in which the hypothetical request takes place. Does not need to correspond to a real tab ID. Default is -1, meaning that the request isn't related to a tab. */
1435014367
tabId?: number;
1435114368
/**
@@ -14683,13 +14700,13 @@ declare namespace chrome {
1468314700
* Fired when the extension's side panel is closed.
1468414701
* @since Chrome 142
1468514702
*/
14686-
const onClosed: events.Event<(info: PanelClosedInfo) => void>;
14703+
export const onClosed: events.Event<(info: PanelClosedInfo) => void>;
1468714704

1468814705
/**
1468914706
* Fired when the extension's side panel is opened.
1469014707
* @since Chrome 141
1469114708
*/
14692-
const onOpened: events.Event<(info: PanelOpenedInfo) => void>;
14709+
export const onOpened: events.Event<(info: PanelOpenedInfo) => void>;
1469314710
}
1469414711

1469514712
////////////////////
@@ -14795,7 +14812,7 @@ declare namespace chrome {
1479514812
/** Specifies wildcard patterns for pages this user script will be injected into. */
1479614813
includeGlobs?: string[] | undefined;
1479714814
/** The list of ScriptSource objects defining sources of scripts to be injected into matching pages. This property must be specified for {@link register}, and when specified it must be a non-empty array.*/
14798-
js: ScriptSource[];
14815+
js?: ScriptSource[] | undefined;
1479914816
/** Specifies which pages this user script will be injected into. See Match Patterns for more details on the syntax of these strings. This property must be specified for {@link register}. */
1480014817
matches?: string[] | undefined;
1480114818
/** Specifies when JavaScript files are injected into the web page. The preferred and default value is `document_idle` */

types/chrome/test/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,14 @@ function testDeclarativeContent() {
13161316
const imageData = new ImageData(32, 32);
13171317

13181318
new chrome.declarativeContent.SetIcon({ imageData }); // $ExpectType SetIcon
1319+
new chrome.declarativeContent.SetIcon({ imageData: { 32: imageData } }); // $ExpectType SetIcon
1320+
new chrome.declarativeContent.SetIcon({ path: "image.jpg" }); // $ExpectType SetIcon
1321+
new chrome.declarativeContent.SetIcon({ imageData, path: "image.jpg" }); // $ExpectType SetIcon
1322+
new chrome.declarativeContent.SetIcon({ imageData, path: { "32": "image.jpg" } }); // $ExpectType SetIcon
1323+
// @ts-expect-error Cannot use 'in' operator to search for 'iconIndex' in undefined
1324+
new chrome.declarativeContent.SetIcon();
1325+
// @ts-expect-error Uncaught Error: Either the path or imageData property must be specified
1326+
new chrome.declarativeContent.SetIcon({});
13191327

13201328
const action = new chrome.declarativeContent.ShowAction(); // $ExpectType ShowAction
13211329

@@ -4528,7 +4536,7 @@ function testDocumentScan() {
45284536
const optionSettings: chrome.documentScan.OptionSetting[] = [{
45294537
name: "name",
45304538
type: "GROUP",
4531-
value: "value",
4539+
value: [10],
45324540
}];
45334541
chrome.documentScan.setOptions(scannerHandle, optionSettings); // $ExpectType Promise<SetOptionsResponse<"handle">>
45344542
chrome.documentScan.setOptions(scannerHandle, optionSettings, response => { // $ExpectType void
@@ -4597,6 +4605,18 @@ function testEnterpriseHardwarePlatform() {
45974605
chrome.enterprise.hardwarePlatform.getHardwarePlatformInfo((info) => {}).then((info) => {});
45984606
}
45994607

4608+
// https://developer.chrome.com/docs/extensions/reference/api/enterprise/networkingAttributes
4609+
function testEntrepriseNetworkingAttributes() {
4610+
chrome.enterprise.networkingAttributes.getNetworkDetails(); // $ExpectType Promise<NetworkDetails>
4611+
chrome.enterprise.networkingAttributes.getNetworkDetails((networkAddresses) => { // $ExpectType void
4612+
networkAddresses.ipv4; // $ExpectType string | undefined
4613+
networkAddresses.ipv6; // $ExpectType string | undefined
4614+
networkAddresses.macAddress; // $ExpectType string
4615+
});
4616+
// @ts-expect-error
4617+
chrome.enterprise.networkingAttributes.getNetworkDetails((networkAddresses) => {}).then((networkAddresses) => {});
4618+
}
4619+
46004620
// https://developer.chrome.com/docs/extensions/reference/api/enterprise/login
46014621
function testEnterpriseLogin() {
46024622
chrome.enterprise.login.exitCurrentManagedGuestSession(); // $ExpectType Promise<void>
@@ -6626,7 +6646,7 @@ function testPrinterProvider() {
66266646
// https://developer.chrome.com/docs/extensions/reference/api/platformKeys
66276647
function testPlatformKeys() {
66286648
chrome.platformKeys.ClientCertificateType.ECDSA_SIGN === "ecdsaSign";
6629-
chrome.platformKeys.ClientCertificateType.RAS_SIGN === "rasSign";
6649+
chrome.platformKeys.ClientCertificateType.RSA_SIGN === "rsaSign";
66306650

66316651
const arrayBuffer = new ArrayBuffer(0);
66326652

@@ -6645,7 +6665,7 @@ function testPlatformKeys() {
66456665
interactive: true,
66466666
request: {
66476667
certificateAuthorities: [],
6648-
certificateTypes: ["ecdsaSign", chrome.platformKeys.ClientCertificateType.RAS_SIGN],
6668+
certificateTypes: ["ecdsaSign", chrome.platformKeys.ClientCertificateType.RSA_SIGN],
66496669
},
66506670
};
66516671

0 commit comments

Comments
 (0)