Skip to content

Commit 58c738b

Browse files
🤖 Merge PR DefinitelyTyped#71864 [Chrome] Add addHostAccessRequest and removeHostAccessRequest for permissions since Chrome 133 by @erwanjugand
Co-authored-by: fregante <[email protected]>
1 parent 1865b19 commit 58c738b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

‎types/chrome/index.d.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6826,6 +6826,22 @@ declare namespace chrome {
68266826
permissions?: chrome.runtime.ManifestPermissions[];
68276827
}
68286828

6829+
export interface AddHostAccessRequest {
6830+
/** The id of a document where host access requests can be shown. Must be the top-level document within a tab. If provided, the request is shown on the tab of the specified document and is removed when the document navigates to a new origin. Adding a new request will override any existent request for `tabId`. This or `tabId` must be specified. */
6831+
documentId?: string;
6832+
/** The URL pattern where host access requests can be shown. If provided, host access requests will only be shown on URLs that match this pattern. */
6833+
pattern?: string;
6834+
/** The id of the tab where host access requests can be shown. If provided, the request is shown on the specified tab and is removed when the tab navigates to a new origin. Adding a new request will override an existent request for `documentId`. This or `documentId` must be specified. */
6835+
tabId?: number;
6836+
}
6837+
6838+
/**
6839+
* Adds a host access request. Request will only be signaled to the user if extension can be granted access to the host in the request. Request will be reset on cross-origin navigation. When accepted, grants persistent access to the site’s top origin
6840+
* @since Chrome 133
6841+
*/
6842+
export function addHostAccessRequest(request: AddHostAccessRequest): Promise<void>;
6843+
export function addHostAccessRequest(request: AddHostAccessRequest, callback: () => void): void;
6844+
68296845
/**
68306846
* Checks if the extension has the specified permissions.
68316847
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
@@ -6858,6 +6874,22 @@ declare namespace chrome {
68586874
export function remove(permissions: Permissions): Promise<boolean>;
68596875
export function remove(permissions: Permissions, callback: (removed: boolean) => void): void;
68606876

6877+
export interface RemoveHostAccessRequest {
6878+
/** The id of a document where host access request will be removed. Must be the top-level document within a tab. This or `tabId` must be specified. */
6879+
documentId?: string;
6880+
/** The URL pattern where host access request will be removed. If provided, this must exactly match the pattern of an existing host access request. */
6881+
pattern?: string;
6882+
/** The id of the tab where host access request will be removed. This or `documentId` must be specified. */
6883+
tabId?: number;
6884+
}
6885+
6886+
/**
6887+
* Removes a host access request, if existent.
6888+
* @since Chrome 133
6889+
*/
6890+
export function removeHostAccessRequest(request: RemoveHostAccessRequest): Promise<void>;
6891+
export function removeHostAccessRequest(request: RemoveHostAccessRequest, callback: () => void): void;
6892+
68616893
/** Fired when access to permissions has been removed from the extension. */
68626894
export const onRemoved: chrome.events.Event<(permissions: Permissions) => void>;
68636895

@@ -8629,7 +8661,7 @@ declare namespace chrome {
86298661
export function connectNative(application: string): Port;
86308662
/**
86318663
* Retrieves the JavaScript 'window' object for the background page running inside the current extension/app. If the background page is an event page, the system will ensure it is loaded before calling the callback. If there is no background page, an error is set.
8632-
* @deprecated Background pages do not exist in MV3 extensions.
8664+
* @deprecated Removed since Chrome 133. Background pages do not exist in MV3 extensions.
86338665
*/
86348666
export function getBackgroundPage(): Promise<Window>;
86358667
/** Retrieves the JavaScript 'window' object for the background page running inside the current extension/app. If the background page is an event page, the system will ensure it is loaded before calling the callback. If there is no background page, an error is set. */

‎types/chrome/test/index.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,17 @@ function testPermissions() {
26932693
origins: ["https://example.com/*"],
26942694
};
26952695

2696+
const request: chrome.permissions.AddHostAccessRequest | chrome.permissions.RemoveHostAccessRequest = {
2697+
documentId: "1",
2698+
pattern: "",
2699+
tabId: 1,
2700+
};
2701+
2702+
chrome.permissions.addHostAccessRequest(request); // $ExpectType Promise<void>
2703+
chrome.permissions.addHostAccessRequest(request, () => {}); // $ExpectType void
2704+
// @ts-expect-error
2705+
chrome.permissions.addHostAccessRequest(request, () => {}).then(() => {});
2706+
26962707
chrome.permissions.contains(permissions); // $ExpectType Promise<boolean>
26972708
chrome.permissions.contains(permissions, (result: boolean) => {}); // $ExpectType void
26982709
// @ts-expect-error
@@ -2719,6 +2730,11 @@ function testPermissions() {
27192730
// @ts-expect-error : 'test' is not a recognized permission.
27202731
chrome.permissions.remove({ permissions: ["test"] });
27212732

2733+
chrome.permissions.removeHostAccessRequest(request); // $ExpectType Promise<void>
2734+
chrome.permissions.removeHostAccessRequest(request, () => {}); // $ExpectType void
2735+
// @ts-expect-error
2736+
chrome.permissions.removeHostAccessRequest(request, () => {}).then(() => {});
2737+
27222738
chrome.permissions.onAdded.addListener((permissions) => {
27232739
permissions; // $ExpectType Permissions
27242740
});

0 commit comments

Comments
 (0)