-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathdevtools-discovery.js
More file actions
82 lines (78 loc) · 2.38 KB
/
Copy pathdevtools-discovery.js
File metadata and controls
82 lines (78 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* DevTools Discovery module for Optimization Detective.
*
* Exposes the URL Metric being collected for the current page load to Chrome DevTools for
* agents, via its third-party tools API, so that an AI agent can inspect it while debugging
* page performance.
*
* @since n.e.x.t
*
* @see https://developer.chrome.com/docs/devtools/agents/use-cases/third-party-tools
*/
/**
* Extension name.
*
* @since n.e.x.t
*
* @type {string}
*/
export const name = 'DevTools Discovery';
/**
* @typedef {import("./types.ts").InitializeCallback} InitializeCallback
* @typedef {import("./types.ts").InitializeArgs} InitializeArgs
*/
/**
* Event dispatched by Chrome DevTools for agents to discover third-party tools.
*
* This is a new, experimental, Chrome-only browser API not yet reflected in TypeScript's DOM lib.
*
* @typedef {Event & { respondWith: (toolGroup: Object) => void }} DevtoolsToolDiscoveryEvent
*/
/**
* Initializes extension.
*
* @since n.e.x.t
*
* @type {InitializeCallback}
* @param {InitializeArgs} args Args.
*/
export async function initialize( { getRootData, getElementData } ) {
window.addEventListener( 'devtoolstooldiscovery', ( event ) => {
const discoveryEvent = /** @type {DevtoolsToolDiscoveryEvent} */ (
event
);
discoveryEvent.respondWith( {
name: 'Optimization Detective',
description:
'Inspect the URL Metric being collected by Optimization Detective for the current page load.',
tools: [
{
name: 'get_od_url_metric',
description:
'Returns the URL Metric (viewport dimensions and tracked element LCP/intersection data) collected so far for the current page load, or null if none has been collected yet.',
inputSchema: { type: 'object', properties: {} },
execute: async () => getRootData(),
},
{
name: 'get_od_element_data',
description:
'Returns the tracked LCP/intersection data for a single element, identified by its XPath as found in its data-od-xpath attribute, or null if the element is not tracked.',
inputSchema: {
type: 'object',
properties: {
xpath: {
type: 'string',
description:
'XPath of the element, as found in its data-od-xpath attribute.',
},
},
required: [ 'xpath' ],
},
execute: async (
/** @type {{ xpath: string }} */ { xpath }
) => getElementData( xpath ),
},
],
} );
} );
}