Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 38 additions & 75 deletions types/chrome/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14103,27 +14103,26 @@ declare namespace chrome {
* If specified, the side panel options for the given tab will be returned.
* Otherwise, returns the default side panel options (used for any tab that doesn't have specific settings).
*/
tabId?: number;
tabId?: number | undefined;
}

/**
* @since Chrome 116
*/
/** @since Chrome 116 */
export type OpenOptions =
& {
/** The tab in which to open the side panel.
/**
* The tab in which to open the side panel.
* If the corresponding tab has a tab-specific side panel, the panel will only be open for that tab.
* If there is not a tab-specific panel, the global panel will be open in the specified tab and any other tabs without a currently-open tab- specific panel.
* This will override any currently-active side panel (global or tab-specific) in the corresponding tab.
* At least one of this and windowId must be provided. */
tabId?: number;
* At least one of this and `windowId` must be provided. */
tabId?: number | undefined;
/**
* The window in which to open the side panel.
* This is only applicable if the extension has a global (non-tab-specific) side panel or tabId is also specified.
* This is only applicable if the extension has a global (non-tab-specific) side panel or `tabId` is also specified.
* This will override any currently-active global side panel the user has open in the given window.
* At least one of this and tabId must be provided.
* At least one of this and `tabId` must be provided.
*/
windowId?: number;
windowId?: number | undefined;
}
& ({
tabId: number;
Expand All @@ -14133,7 +14132,7 @@ declare namespace chrome {

export interface PanelBehavior {
/** Whether clicking the extension's icon will toggle showing the extension's entry in the side panel. Defaults to false. */
openPanelOnActionClick?: boolean;
openPanelOnActionClick?: boolean | undefined;
}

/** @since Chrome 140 */
Expand All @@ -14143,15 +14142,15 @@ declare namespace chrome {

export interface PanelOptions {
/** Whether the side panel should be enabled. This is optional. The default value is true. */
enabled?: boolean;
enabled?: boolean | undefined;
/** The path to the side panel HTML file to use. This must be a local resource within the extension package. */
path?: string;
path?: string | undefined;
/**
* If specified, the side panel options will only apply to the tab with this id.
* If omitted, these options set the default behavior (used for any tab that doesn't have specific settings).
* Note: if the same path is set for this tabId and the default tabId, then the panel for this tabId will be a different instance than the panel for the default tabId.
*/
tabId?: number;
tabId?: number | undefined;
}

/**
Expand All @@ -14177,84 +14176,48 @@ declare namespace chrome {

/**
* Returns the active panel configuration.
* Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility.
* You cannot use both on the same function call.
* The promise resolves with the same type that is passed to the callback.
*/
export function getOptions(
/** Specifies the context to return the configuration for. */
options: GetPanelOptions,
callback: (options: PanelOptions) => void,
): void;

export function getOptions(
/** Specifies the context to return the configuration for. */
options: GetPanelOptions,
): Promise<PanelOptions>;
*
* Can return its result via Promise.
* @param options Specifies the context to return the configuration for.
*/
export function getOptions(options: GetPanelOptions): Promise<PanelOptions>;
export function getOptions(options: GetPanelOptions, callback: (options: PanelOptions) => void): void;

/**
* Returns the extension's current side panel behavior.
* Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility.
* You cannot use both on the same function call.
* The promise resolves with the same type that is passed to the callback.
*
* Can return its result via Promise.
*/
export function getPanelBehavior(
callback: (behavior: PanelBehavior) => void,
): void;

export function getPanelBehavior(): Promise<PanelBehavior>;
export function getPanelBehavior(callback: (behavior: PanelBehavior) => void): void;

/**
* @since Chrome 116
* Opens the side panel for the extension. This may only be called in response to a user action.
* Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility.
* You cannot use both on the same function call.
* The promise resolves with the same type that is passed to the callback.
*
* Can return its result via Promise.
* @param options Specifies the context in which to open the side panel.
* @since Chrome 116
*/
export function open(
/** Specifies the context in which to open the side panel. */
options: OpenOptions,
callback: () => void,
): void;

export function open(
/** Specifies the context in which to open the side panel. */
options: OpenOptions,
): Promise<void>;
export function open(options: OpenOptions): Promise<void>;
export function open(options: OpenOptions, callback: () => void): void;

/**
* Configures the side panel.
* Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility.
* You cannot use both on the same function call.
* The promise resolves with the same type that is passed to the callback.
*
* Can return its result via Promise.
* @param options The configuration options to apply to the panel.
*/
export function setOptions(
/** The configuration options to apply to the panel. */
options: PanelOptions,
callback: () => void,
): void;

export function setOptions(
/** The configuration options to apply to the panel. */
options: PanelOptions,
): Promise<void>;
export function setOptions(options: PanelOptions): Promise<void>;
export function setOptions(options: PanelOptions, callback: () => void): void;

/**
* Configures the extension's side panel behavior. This is an upsert operation.
* Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility.
* You cannot use both on the same function call.
* The promise resolves with the same type that is passed to the callback.
*
* Can return its result via Promise.
* @param behavior The new behavior to be set.
*/
export function setPanelBehavior(
/** The new behavior to be set. */
behavior: PanelBehavior,
callback: () => void,
): void;

export function setPanelBehavior(
/** The new behavior to be set. */
behavior: PanelBehavior,
): Promise<void>;
export function setPanelBehavior(behavior: PanelBehavior): Promise<void>;
export function setPanelBehavior(behavior: PanelBehavior, callback: () => void): void;
}

////////////////////
Expand Down
96 changes: 35 additions & 61 deletions types/chrome/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5600,101 +5600,75 @@ function testSessions() {

// https://developer.chrome.com/docs/extensions/reference/api/sidePanel
function testSidePanel() {
chrome.sidePanel.Side.LEFT === "left";
chrome.sidePanel.Side.RIGHT === "right";

chrome.sidePanel.getLayout(); // $ExpectType Promise<PanelLayout>
chrome.sidePanel.getLayout((layout) => { // $ExpectType void
layout.side; // $ExpectType "left" | "right"
});
// @ts-expect-error
chrome.sidePanel.getLayout(() => {}).then(() => {});

let getPanelOptions: chrome.sidePanel.GetPanelOptions = {
const getPanelOptions: chrome.sidePanel.GetPanelOptions = {
tabId: 123,
};

chrome.sidePanel.getOptions(getPanelOptions, (options: chrome.sidePanel.PanelOptions) => {
console.log("Using callback:");
console.log(options.enabled);
console.log(options.path);
console.log(options.tabId);
});

chrome.sidePanel.getOptions(getPanelOptions).then((options: chrome.sidePanel.PanelOptions) => {
console.log("Using promise:");
console.log(options.enabled);
console.log(options.path);
console.log(options.tabId);
});

chrome.sidePanel.getPanelBehavior((behavior: chrome.sidePanel.PanelBehavior) => {
console.log("Using callback:", behavior.openPanelOnActionClick);
chrome.sidePanel.getOptions(getPanelOptions); // $ExpectType Promise<PanelOptions>
chrome.sidePanel.getOptions(getPanelOptions, (options) => { // $ExpectType void
options.enabled; // $ExpectType boolean | undefined
options.path; // $ExpectType string | undefined
options.tabId; // $ExpectType number | undefined
});
// @ts-expect-error
chrome.sidePanel.getOptions(getPanelOptions, () => {}).then(() => {});

chrome.sidePanel.getPanelBehavior().then((behavior) => {
console.log("Using promise:", behavior.openPanelOnActionClick);
chrome.sidePanel.getPanelBehavior(); // $ExpectType Promise<PanelBehavior>
chrome.sidePanel.getPanelBehavior((behavior) => { // $ExpectType void
behavior.openPanelOnActionClick; // $ExpectType boolean | undefined
});
// @ts-expect-error
chrome.sidePanel.getPanelBehavior(() => {}).then(() => {});

let openOptionsTab: chrome.sidePanel.OpenOptions = {
const openOptionsTab: chrome.sidePanel.OpenOptions = {
tabId: 1234567890,
};

let openOptionsWindow: chrome.sidePanel.OpenOptions = {
const openOptionsWindow: chrome.sidePanel.OpenOptions = {
windowId: 9876543210,
};

let openOptionsTabAndWindow: chrome.sidePanel.OpenOptions = {
const openOptionsTabAndWindow: chrome.sidePanel.OpenOptions = {
tabId: 1234567890,
windowId: 9876543210,
};

chrome.sidePanel.open(openOptionsTab, () => {
console.log("Side panel opened in tab using callback");
});

chrome.sidePanel.open(openOptionsTab).then(() => {
console.log("Side panel opened in tab using promise");
});

chrome.sidePanel.open(openOptionsWindow, () => {
console.log("Side panel opened in window using callback");
});

chrome.sidePanel.open(openOptionsWindow).then(() => {
console.log("Side panel opened in window using promise");
});

chrome.sidePanel.open(openOptionsTabAndWindow, () => {
console.log("Side panel opened in tab in window using callback");
});
chrome.sidePanel.open(openOptionsTab); // $ExpectType Promise<void>
chrome.sidePanel.open(openOptionsWindow); // $ExpectType Promise<void>
chrome.sidePanel.open(openOptionsTabAndWindow); // $ExpectType Promise<void>
chrome.sidePanel.open(openOptionsTab, () => void 0); // $ExpectType void
chrome.sidePanel.open(openOptionsWindow, () => void 0); // $ExpectType void
chrome.sidePanel.open(openOptionsTabAndWindow, () => void 0); // $ExpectType void

chrome.sidePanel.open(openOptionsTabAndWindow).then(() => {
console.log("Side panel opened in tab in window using promise");
});

let setPanelOptions: chrome.sidePanel.PanelOptions = {
const setPanelOptions: chrome.sidePanel.PanelOptions = {
enabled: true,
path: "path/to/sidePanel.html",
tabId: 123,
};

chrome.sidePanel.setOptions(setPanelOptions, () => {
console.log("Options set successfully using callback.");
});

chrome.sidePanel.setOptions(setPanelOptions).then(() => {
console.log("Options set successfully using promise.");
});
chrome.sidePanel.setOptions(setPanelOptions); // $ExpectType Promise<void>
chrome.sidePanel.setOptions(setPanelOptions, () => void 0); // $ExpectType void
// @ts-expect-error
chrome.sidePanel.setOptions(setPanelOptions, () => {}).then(() => {});

let setPanelBehavior: chrome.sidePanel.PanelBehavior = {
const setPanelBehavior: chrome.sidePanel.PanelBehavior = {
openPanelOnActionClick: true,
};

chrome.sidePanel.setPanelBehavior(setPanelBehavior, () => {
console.log("Behavior set successfully using callback.");
});

chrome.sidePanel.setPanelBehavior(setPanelBehavior).then(() => {
console.log("Behavior set successfully using promise.");
});
chrome.sidePanel.setPanelBehavior(setPanelBehavior); // $ExpectType Promise<void>
chrome.sidePanel.setPanelBehavior(setPanelBehavior, () => void 0); // $ExpectType void
// @ts-expect-error
chrome.sidePanel.setPanelBehavior(setPanelBehavior, () => {}).then(() => {});
}

// https://developer.chrome.com/docs/extensions/reference/api/instanceID
Expand Down
2 changes: 1 addition & 1 deletion types/deno/deno-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Deno.mkdirSync("dir"); // $ExpectType void
Deno.readTextFileSync("dir/file.txt"); // $ExpectType string
Deno.readTextFileSync(new URL("./file.txt", import.meta.url)); // $ExpectType string
new Deno.errors.NotFound(); // $ExpectType NotFound
Deno.jupyter.broadcast("type", { "data": 5 }); // $ExpectType Promise<void>
Deno.jupyter.broadcast("type", { "data": 6 }); // $ExpectType Promise<void>
Loading