Skip to content

Commit c68a4e7

Browse files
authored
🤖 Merge PR DefinitelyTyped#72261 [Chrome] add devtools.recorder namespace by @erwanjugand
1 parent eaeda19 commit c68a4e7

File tree

2 files changed

+99
-15
lines changed

2 files changed

+99
-15
lines changed

‎types/chrome/index.d.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,71 @@ declare namespace chrome {
30713071
export var themeName: "default" | "dark";
30723072
}
30733073

3074+
////////////////////
3075+
// Dev Tools - Recorder
3076+
////////////////////
3077+
/**
3078+
* Use the `chrome.devtools.recorder` API to customize the Recorder panel in DevTools.
3079+
* @since Chrome 105
3080+
*/
3081+
export namespace devtools.recorder {
3082+
/** A plugin interface that the Recorder panel invokes to customize the Recorder panel. */
3083+
export interface RecorderExtensionPlugin {
3084+
/**
3085+
* Allows the extension to implement custom replay functionality.
3086+
*
3087+
* @param recording A recording of the user interaction with the page. This should match [Puppeteer's recording schema](https://github.com/puppeteer/replay/blob/main/docs/api/interfaces/Schema.UserFlow.md).
3088+
* @since Chrome 112
3089+
*/
3090+
replay?(recording: object): void;
3091+
3092+
/**
3093+
* Converts a recording from the Recorder panel format into a string.
3094+
* @param recording A recording of the user interaction with the page. This should match [Puppeteer's recording schema](https://github.com/puppeteer/replay/blob/main/docs/api/interfaces/Schema.UserFlow.md).
3095+
*/
3096+
stringify?(recording: object): void;
3097+
3098+
/**
3099+
* Converts a step of the recording from the Recorder panel format into a string.
3100+
* @param step A step of the recording of a user interaction with the page. This should match [Puppeteer's step schema](https://github.com/puppeteer/replay/blob/main/docs/api/modules/Schema.md#step).
3101+
*/
3102+
stringifyStep?(step: object): void;
3103+
}
3104+
3105+
/**
3106+
* Represents a view created by extension to be embedded inside the Recorder panel.
3107+
* @since Chrome 112
3108+
*/
3109+
export interface RecorderView {
3110+
/** Fired when the view is hidden. */
3111+
onHidden: events.Event<() => void>;
3112+
/** Fired when the view is shown. */
3113+
onShown: events.Event<() => void>;
3114+
/** Indicates that the extension wants to show this view in the Recorder panel. */
3115+
show(): void;
3116+
}
3117+
3118+
/**
3119+
* Creates a view that can handle the replay. This view will be embedded inside the Recorder panel.
3120+
* @param title Title that is displayed next to the extension icon in the Developer Tools toolbar.
3121+
* @param pagePath Path of the panel's HTML page relative to the extension directory.
3122+
* @since Chrome 112
3123+
*/
3124+
export function createView(title: string, pagePath: string): RecorderView;
3125+
3126+
/**
3127+
* Registers a Recorder extension plugin.
3128+
* @param plugin An instance implementing the RecorderExtensionPlugin interface.
3129+
* @param name The name of the plugin.
3130+
* @param mediaType The media type of the string content that the plugin produces.
3131+
*/
3132+
export function registerRecorderExtensionPlugin(
3133+
plugin: RecorderExtensionPlugin,
3134+
name: string,
3135+
mediaType: string,
3136+
): void;
3137+
}
3138+
30743139
////////////////////
30753140
// Document Scan
30763141
////////////////////

‎types/chrome/test/index.ts‎

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,25 +1314,25 @@ function testRuntimeOnMessageAddListener() {
13141314
});
13151315
}
13161316

1317-
chrome.devtools.network.onRequestFinished.addListener((request: chrome.devtools.network.Request) => {
1318-
request; // $ExpectType Request
1319-
console.log("request: ", request);
1320-
});
1317+
function testDevtools() {
1318+
chrome.devtools.network.onRequestFinished.addListener((request: chrome.devtools.network.Request) => {
1319+
request; // $ExpectType Request
1320+
console.log("request: ", request);
1321+
});
13211322

1322-
chrome.devtools.performance.onProfilingStarted.addListener(() => {
1323-
console.log("Profiling started");
1324-
});
1323+
chrome.devtools.performance.onProfilingStarted.addListener(() => {
1324+
console.log("Profiling started");
1325+
});
13251326

1326-
chrome.devtools.performance.onProfilingStopped.addListener(() => {
1327-
console.log("Profiling stopped");
1328-
});
1327+
chrome.devtools.performance.onProfilingStopped.addListener(() => {
1328+
console.log("Profiling stopped");
1329+
});
13291330

1330-
chrome.devtools.network.getHAR((harLog: chrome.devtools.network.HARLog) => {
1331-
harLog; // $ExpectType HARLog
1332-
console.log("harLog: ", harLog);
1333-
});
1331+
chrome.devtools.network.getHAR((harLog: chrome.devtools.network.HARLog) => {
1332+
harLog; // $ExpectType HARLog
1333+
console.log("harLog: ", harLog);
1334+
});
13341335

1335-
function testDevtools() {
13361336
chrome.devtools.inspectedWindow.eval("1+1", undefined, result => {
13371337
console.log(result);
13381338
});
@@ -1344,6 +1344,25 @@ function testDevtools() {
13441344
ignoreCache: true,
13451345
injectedScript: "console.log(\"Hello World!\")",
13461346
});
1347+
1348+
const view = chrome.devtools.recorder.createView("title", "replay.html"); // $ExpectType RecorderView
1349+
view.onHidden.addListener(() => {}); // $ExpectType void
1350+
view.onHidden.removeListener(() => {}); // $ExpectType void
1351+
view.onHidden.hasListener(() => {}); // $ExpectType boolean
1352+
view.onHidden.hasListeners(); // $ExpectType boolean
1353+
view.onShown.addListener(() => {}); // $ExpectType void
1354+
view.onShown.removeListener(() => {}); // $ExpectType void
1355+
view.onShown.hasListener(() => {}); // $ExpectType boolean
1356+
view.onShown.hasListeners(); // $ExpectType boolean
1357+
view.show(); // $ExpectType void
1358+
1359+
const plugin: chrome.devtools.recorder.RecorderExtensionPlugin = {
1360+
replay: () => {},
1361+
stringify: () => {},
1362+
stringifyStep: () => {},
1363+
};
1364+
chrome.devtools.recorder.registerRecorderExtensionPlugin({}, "MyPlugin", "application/json"); // $ExpectType void
1365+
chrome.devtools.recorder.registerRecorderExtensionPlugin(plugin, "MyPlugin", "application/json"); // $ExpectType void
13471366
}
13481367

13491368
function testAssistiveWindow() {

0 commit comments

Comments
 (0)