Skip to content

Commit a17b8fa

Browse files
authored
🤖 Merge PR DefinitelyTyped#73784 [chrome] update sessions namespace by @erwanjugand
1 parent f2b36c6 commit a17b8fa

File tree

2 files changed

+59
-81
lines changed

2 files changed

+59
-81
lines changed

types/chrome/index.d.ts

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9729,25 +9729,16 @@ declare namespace chrome {
97299729
*/
97309730
export namespace sessions {
97319731
export interface Filter {
9732-
/**
9733-
* Optional.
9734-
* The maximum number of entries to be fetched in the requested list. Omit this parameter to fetch the maximum number of entries (sessions.MAX_SESSION_RESULTS).
9735-
*/
9732+
/** The maximum number of entries to be fetched in the requested list. Omit this parameter to fetch the maximum number of entries ({@link sessions.MAX_SESSION_RESULTS}). */
97369733
maxResults?: number | undefined;
97379734
}
97389735

97399736
export interface Session {
97409737
/** The time when the window or tab was closed or modified, represented in seconds since the epoch. */
97419738
lastModified: number;
9742-
/**
9743-
* Optional.
9744-
* The tabs.Tab, if this entry describes a tab. Either this or sessions.Session.window will be set.
9745-
*/
9739+
/** The {@link tabs.Tab}, if this entry describes a tab. Either this or {@link sessions.Session.window} will be set. */
97469740
tab?: tabs.Tab | undefined;
9747-
/**
9748-
* Optional.
9749-
* The windows.Window, if this entry describes a window. Either this or sessions.Session.tab will be set.
9750-
*/
9741+
/** The {@link windows.Window}, if this entry describes a window. Either this or {@link sessions.Session.tab} will be set. */
97519742
window?: windows.Window | undefined;
97529743
}
97539744

@@ -9758,69 +9749,39 @@ declare namespace chrome {
97589749
sessions: Session[];
97599750
}
97609751

9761-
export interface SessionChangedEvent extends chrome.events.Event<() => void> {}
9762-
9763-
/** The maximum number of sessions.Session that will be included in a requested list. */
9764-
export var MAX_SESSION_RESULTS: number;
9752+
/** The maximum number of {@link sessions.Session} that will be included in a requested list. */
9753+
export const MAX_SESSION_RESULTS: 25;
97659754

97669755
/**
97679756
* Gets the list of recently closed tabs and/or windows.
9768-
* @return The `getRecentlyClosed` method provides its result via callback or returned as a `Promise` (MV3 only).
9757+
*
9758+
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
97699759
*/
97709760
export function getRecentlyClosed(filter?: Filter): Promise<Session[]>;
9771-
/**
9772-
* Gets the list of recently closed tabs and/or windows.
9773-
* @param callback
9774-
* Parameter sessions: The list of closed entries in reverse order that they were closed (the most recently closed tab or window will be at index 0). The entries may contain either tabs or windows.
9775-
*/
9776-
export function getRecentlyClosed(filter: Filter, callback: (sessions: Session[]) => void): void;
9777-
/**
9778-
* Gets the list of recently closed tabs and/or windows.
9779-
* @param callback
9780-
* Parameter sessions: The list of closed entries in reverse order that they were closed (the most recently closed tab or window will be at index 0). The entries may contain either tabs or windows.
9781-
*/
97829761
export function getRecentlyClosed(callback: (sessions: Session[]) => void): void;
9762+
export function getRecentlyClosed(filter: Filter | undefined, callback: (sessions: Session[]) => void): void;
9763+
97839764
/**
97849765
* Retrieves all devices with synced sessions.
9785-
* @return The `getDevices` method provides its result via callback or returned as a `Promise` (MV3 only).
9766+
*
9767+
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
97869768
*/
97879769
export function getDevices(filter?: Filter): Promise<Device[]>;
9788-
/**
9789-
* Retrieves all devices with synced sessions.
9790-
* @param callback
9791-
* Parameter devices: The list of sessions.Device objects for each synced session, sorted in order from device with most recently modified session to device with least recently modified session. tabs.Tab objects are sorted by recency in the windows.Window of the sessions.Session objects.
9792-
*/
9793-
export function getDevices(filter: Filter, callback: (devices: Device[]) => void): void;
9794-
/**
9795-
* Retrieves all devices with synced sessions.
9796-
* @param callback
9797-
* Parameter devices: The list of sessions.Device objects for each synced session, sorted in order from device with most recently modified session to device with least recently modified session. tabs.Tab objects are sorted by recency in the windows.Window of the sessions.Session objects.
9798-
*/
97999770
export function getDevices(callback: (devices: Device[]) => void): void;
9771+
export function getDevices(filter: Filter | undefined, callback: (devices: Device[]) => void): void;
9772+
98009773
/**
9801-
* Reopens a windows.Window or tabs.Tab.
9802-
* @param sessionId Optional.
9803-
* The windows.Window.sessionId, or tabs.Tab.sessionId to restore. If this parameter is not specified, the most recently closed session is restored.
9804-
* @return The `restore` method provides its result via callback or returned as a `Promise` (MV3 only).
9774+
* Reopens a {@link windows.Window} or {@link tabs.Tab}, with an optional callback to run when the entry has been restored.
9775+
*
9776+
* Can return its result via Promise in Manifest V3 or later since Chrome 96.
9777+
* @param sessionId The {@link windows.Window.sessionId}, or {@link tabs.Tab.sessionId} to restore. If this parameter is not specified, the most recently closed session is restored.
98059778
*/
98069779
export function restore(sessionId?: string): Promise<Session>;
9807-
/**
9808-
* Reopens a windows.Window or tabs.Tab, with an optional callback to run when the entry has been restored.
9809-
* @param sessionId Optional.
9810-
* The windows.Window.sessionId, or tabs.Tab.sessionId to restore. If this parameter is not specified, the most recently closed session is restored.
9811-
* @param callback Optional.
9812-
* Parameter restoredSession: A sessions.Session containing the restored windows.Window or tabs.Tab object.
9813-
*/
9814-
export function restore(sessionId: string, callback: (restoredSession: Session) => void): void;
9815-
/**
9816-
* Reopens a windows.Window or tabs.Tab, with an optional callback to run when the entry has been restored.
9817-
* @param callback Optional.
9818-
* Parameter restoredSession: A sessions.Session containing the restored windows.Window or tabs.Tab object.
9819-
*/
98209780
export function restore(callback: (restoredSession: Session) => void): void;
9781+
export function restore(sessionId: string | undefined, callback: (restoredSession: Session) => void): void;
98219782

98229783
/** Fired when recently closed tabs and/or windows are changed. This event does not monitor synced sessions changes. */
9823-
export var onChanged: SessionChangedEvent;
9784+
export const onChanged: events.Event<() => void>;
98249785
}
98259786

98269787
////////////////////

types/chrome/test/index.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5547,31 +5547,48 @@ function testFileSystemProvider() {
55475547
});
55485548
}
55495549

5550-
// https://developer.chrome.com/docs/extensions/reference/sessions/
5550+
// https://developer.chrome.com/docs/extensions/reference/api/sessions
55515551
function testSessions() {
5552-
const myMax = { maxResults: 1 };
5553-
chrome.sessions.getDevices(devices => {});
5554-
chrome.sessions.getDevices({}, devices => {});
5555-
chrome.sessions.getDevices(myMax, devices => {});
5556-
chrome.sessions.getRecentlyClosed(sessions => {});
5557-
chrome.sessions.getRecentlyClosed({}, sessions => {});
5558-
chrome.sessions.getRecentlyClosed(myMax, sessions => {});
5559-
chrome.sessions.restore(restoredSession => {});
5560-
chrome.sessions.restore("myString", restoredSession => {});
5561-
chrome.sessions.onChanged.addListener(() => {});
5562-
}
5552+
chrome.sessions.MAX_SESSION_RESULTS === 25;
5553+
5554+
const filter: chrome.sessions.Filter = { maxResults: 1 };
5555+
5556+
chrome.sessions.getDevices(); // $ExpectType Promise<Device[]>
5557+
chrome.sessions.getDevices(filter); // $ExpectType Promise<Device[]>
5558+
chrome.sessions.getDevices(([device]) => { // $ExpectType void
5559+
device.deviceName; // $ExpectType string
5560+
device.sessions; // $ExpectType Session[]
5561+
});
5562+
chrome.sessions.getDevices(filter, devices => { // $ExpectType void
5563+
devices; // $ExpectType Device[]
5564+
});
5565+
// @ts-expect-error
5566+
chrome.sessions.getDevices(() => {}).then(() => {});
5567+
5568+
chrome.sessions.getRecentlyClosed(); // $ExpectType Promise<Session[]>
5569+
chrome.sessions.getRecentlyClosed(filter); // $ExpectType Promise<Session[]>
5570+
chrome.sessions.getRecentlyClosed((sessions) => { // $ExpectType void
5571+
sessions; // $ExpectType Session[]
5572+
});
5573+
chrome.sessions.getRecentlyClosed(filter, sessions => { // $ExpectType void
5574+
sessions; // $ExpectType Session[]
5575+
});
5576+
// @ts-expect-error
5577+
chrome.sessions.getRecentlyClosed(() => {}).then(() => {});
5578+
5579+
const sessionId = "id";
5580+
chrome.sessions.restore(); // $ExpectType Promise<Session>
5581+
chrome.sessions.restore(sessionId); // $ExpectType Promise<Session>
5582+
chrome.sessions.restore((restoredSession) => { // $ExpectType void
5583+
restoredSession.lastModified; // $ExpectType number
5584+
restoredSession.tab; // $ExpectType Tab | undefined
5585+
restoredSession.window; // $ExpectType Window | undefined
5586+
});
5587+
chrome.sessions.restore(sessionId, (restoredSession) => { // $ExpectType void
5588+
restoredSession; // $ExpectType Session
5589+
});
55635590

5564-
// https://developer.chrome.com/docs/extensions/reference/sessions/
5565-
async function testSessionsForPromise() {
5566-
const myMax = { maxResults: 1 };
5567-
await chrome.sessions.getDevices();
5568-
await chrome.sessions.getDevices({});
5569-
await chrome.sessions.getDevices(myMax);
5570-
await chrome.sessions.getRecentlyClosed();
5571-
await chrome.sessions.getRecentlyClosed({});
5572-
await chrome.sessions.getRecentlyClosed(myMax);
5573-
await chrome.sessions.restore();
5574-
await chrome.sessions.restore("myString");
5591+
checkChromeEvent(chrome.sessions.onChanged, () => void 0);
55755592
}
55765593

55775594
// https://developer.chrome.com/docs/extensions/reference/api/sidePanel

0 commit comments

Comments
 (0)