From 65c25fecb7b55a960b23ea872ea1f2a35feb8aed Mon Sep 17 00:00:00 2001 From: yellott <16868660+yellott@users.noreply.github.com> Date: Fri, 27 Mar 2020 17:46:00 +0200 Subject: [PATCH] [@types/chrome]: Add HAREntry and HARLog to chrome.devtools.network (#43407) --- types/chrome/har-format/index.d.ts | 6 ++++++ types/chrome/index.d.ts | 9 +++++++-- types/chrome/test/index.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 types/chrome/har-format/index.d.ts diff --git a/types/chrome/har-format/index.d.ts b/types/chrome/har-format/index.d.ts new file mode 100644 index 0000000000..c1d5b8fd29 --- /dev/null +++ b/types/chrome/har-format/index.d.ts @@ -0,0 +1,6 @@ +import { Entry, Log } from 'har-format'; + +declare global { + export type HARFormatEntry = Entry; + export type HARFormatLog = Log; +} diff --git a/types/chrome/index.d.ts b/types/chrome/index.d.ts index 1644be7c66..4e0eb3bf78 100644 --- a/types/chrome/index.d.ts +++ b/types/chrome/index.d.ts @@ -14,6 +14,7 @@ // TypeScript Version: 2.4 /// +/// //////////////////// // Global object @@ -1865,8 +1866,12 @@ declare namespace chrome.devtools.inspectedWindow { * Availability: Since Chrome 18. */ declare namespace chrome.devtools.network { + /** Represents a HAR entry for a specific finished request. */ + export interface HAREntry extends HARFormatEntry { } + /** Represents a HAR log that contains all known network requests. */ + export interface HARLog extends HARFormatLog { } /** Represents a network request for a document resource (script, image and so on). See HAR Specification for reference. */ - export interface Request { + export interface Request extends chrome.devtools.network.HAREntry { /** * Returns content of the response body. * @param callback A function that receives the response body when the request completes. @@ -1889,7 +1894,7 @@ declare namespace chrome.devtools.network { * function(object harLog) {...}; * Parameter harLog: A HAR log. See HAR specification for details. */ - export function getHAR(callback: (harLog: Object) => void): void; + export function getHAR(callback: (harLog: HARLog) => void): void; /** Fired when a network request is finished and all request data are available. */ export var onRequestFinished: RequestFinishedEvent; diff --git a/types/chrome/test/index.ts b/types/chrome/test/index.ts index 21b10dc94e..9e3d15cfa4 100644 --- a/types/chrome/test/index.ts +++ b/types/chrome/test/index.ts @@ -439,3 +439,13 @@ function testStorage() { var myOldValue: { x: number } = changes["myKey"].oldValue; }); } + +chrome.devtools.network.onRequestFinished.addListener((request: chrome.devtools.network.Request) => { + request; // $ExpectType Request + console.log('request: ', request); +}); + +chrome.devtools.network.getHAR((harLog: chrome.devtools.network.HARLog) => { + harLog; // $ExpectType HARLog + console.log('harLog: ', harLog) +});