Skip to content

Commit dcfb4b3

Browse files
authored
🤖 Merge PR DefinitelyTyped#73475 [chrome] update devtools.network namespace by @erwanjugand
1 parent 8f957ab commit dcfb4b3

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

‎types/chrome/index.d.ts‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,41 +2772,32 @@ declare namespace chrome {
27722772
* Manifest: "devtools_page"
27732773
*/
27742774
export namespace devtools.network {
2775-
/** Represents a HAR entry for a specific finished request. */
2776-
export interface HAREntry extends HARFormatEntry {}
2777-
/** Represents a HAR log that contains all known network requests. */
2778-
export interface HARLog extends HARFormatLog {}
27792775
/** Represents a network request for a document resource (script, image and so on). See HAR Specification for reference. */
2780-
export interface Request extends chrome.devtools.network.HAREntry {
2781-
/**
2782-
* Returns content of the response body.
2783-
* @param callback A function that receives the response body when the request completes.
2784-
*/
2776+
export interface Request extends HARFormatEntry {
2777+
/** Returns content of the response body. */
27852778
getContent(
27862779
callback: (
2787-
/** Content of the response body (potentially encoded) */
2780+
/** Content of the response body (potentially encoded). */
27882781
content: string,
2789-
/** Empty if content is not encoded, encoding name otherwise. Currently, only base64 is supported */
2782+
/** Empty if content is not encoded, encoding name otherwise. Currently, only base64 is supported. */
27902783
encoding: string,
27912784
) => void,
27922785
): void;
27932786
}
27942787

2795-
export interface RequestFinishedEvent extends chrome.events.Event<(request: Request) => void> {}
2796-
2797-
export interface NavigatedEvent extends chrome.events.Event<(url: string) => void> {}
2798-
2799-
/**
2800-
* Returns HAR log that contains all known network requests.
2801-
* @param callback A function that receives the HAR log when the request completes.
2802-
* Parameter harLog: A HAR log. See HAR specification for details.
2803-
*/
2804-
export function getHAR(callback: (harLog: HARLog) => void): void;
2788+
/** Returns HAR log that contains all known network requests. */
2789+
export function getHAR(
2790+
callback: (
2791+
/** A HAR log. See HAR specification for details. */
2792+
harLog: HARFormatLog,
2793+
) => void,
2794+
): void;
28052795

28062796
/** Fired when a network request is finished and all request data are available. */
2807-
export var onRequestFinished: RequestFinishedEvent;
2797+
export const onRequestFinished: events.Event<(request: Request) => void>;
2798+
28082799
/** Fired when the inspected window navigates to a new page. */
2809-
export var onNavigated: NavigatedEvent;
2800+
export const onNavigated: events.Event<(url: string) => void>;
28102801
}
28112802

28122803
////////////////////

‎types/chrome/test/index.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,17 +1324,8 @@ function testTtsEngine() {
13241324
});
13251325
}
13261326

1327-
function testDevtools() {
1328-
chrome.devtools.network.onRequestFinished.addListener((request: chrome.devtools.network.Request) => {
1329-
request; // $ExpectType Request
1330-
console.log("request: ", request);
1331-
});
1332-
1333-
chrome.devtools.network.getHAR((harLog: chrome.devtools.network.HARLog) => {
1334-
harLog; // $ExpectType HARLog
1335-
console.log("harLog: ", harLog);
1336-
});
1337-
1327+
// https://developer.chrome.com/docs/extensions/reference/api/devtools/recorder
1328+
function testDevtoolsRecorder() {
13381329
const view = chrome.devtools.recorder.createView("title", "replay.html"); // $ExpectType RecorderView
13391330
checkChromeEvent(view.onHidden, () => void 0);
13401331
checkChromeEvent(view.onShown, () => void 0);
@@ -1349,6 +1340,7 @@ function testDevtools() {
13491340
chrome.devtools.recorder.registerRecorderExtensionPlugin(plugin, "MyPlugin", "application/json"); // $ExpectType void
13501341
}
13511342

1343+
// https://developer.chrome.com/docs/extensions/reference/api/devtools/panels
13521344
function testDevtoolsPanels() {
13531345
const title = "title";
13541346
const iconPath = "iconPath";
@@ -1449,6 +1441,21 @@ function testDevtoolsPerformance() {
14491441
checkChromeEvent(chrome.devtools.performance.onProfilingStopped, () => void 0);
14501442
}
14511443

1444+
// https://developer.chrome.com/docs/extensions/reference/api/devtools/network
1445+
function testDevtoolsNetwork() {
1446+
chrome.devtools.network.getHAR((harLog) => {
1447+
harLog; // $ExpectType Log
1448+
});
1449+
1450+
checkChromeEvent(chrome.devtools.network.onNavigated, (url) => {
1451+
url; // $ExpectType string
1452+
});
1453+
1454+
checkChromeEvent(chrome.devtools.network.onRequestFinished, (request) => {
1455+
request; // $ExpectType Request
1456+
});
1457+
}
1458+
14521459
function testAssistiveWindow() {
14531460
chrome.input.ime.setAssistiveWindowProperties({
14541461
contextID: 0,

0 commit comments

Comments
 (0)