@sensaiorg/adapter-chrome 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chrome-adapter.d.ts.map +1 -0
- package/dist/chrome-adapter.js +91 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/tools/chrome-tools.d.ts.map +1 -0
- package/dist/tools/chrome-tools.js +583 -0
- package/dist/tools/chrome-tools.test.d.ts.map +1 -0
- package/dist/tools/chrome-tools.test.js +442 -0
- package/dist/transport/cdp-bridge.d.ts.map +1 -0
- package/dist/transport/cdp-bridge.js +163 -0
- package/package.json +23 -0
- package/src/chrome-adapter.ts +117 -0
- package/src/index.ts +8 -0
- package/src/tools/chrome-tools.test.ts +547 -0
- package/src/tools/chrome-tools.ts +743 -0
- package/src/transport/cdp-bridge.ts +187 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chrome-adapter.d.ts","sourceRoot":"","sources":["../src/chrome-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAKtB,MAAM,WAAW,mBAAmB;IAClC,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,aAAc,YAAW,gBAAgB;IACpD,QAAQ,CAAC,QAAQ,EAAG,QAAQ,CAAU;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAUzC;IAEF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,aAAa,CAAM;IAE3B,QAAQ,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CAAQ;IACvC,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAQ;IAC1C,QAAQ,CAAC,WAAW,EAAE,oBAAoB,GAAG,IAAI,CAAQ;IACzD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAQ;IACjD,QAAQ,CAAC,WAAW,EAAE,oBAAoB,GAAG,IAAI,CAAQ;IACzD,QAAQ,CAAC,UAAU,EAAE,mBAAmB,GAAG,IAAI,CAAQ;IACvD,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAQ;gBAEvC,MAAM,GAAE,mBAAwB;IAWtC,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA+B7C,QAAQ,IAAI,IAAI;IAIhB,WAAW,IAAI,OAAO;IAItB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;CAI/C"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ChromeAdapter — implements IPlatformAdapter for Chrome browser debugging.
|
|
4
|
+
*
|
|
5
|
+
* Communication flow:
|
|
6
|
+
* MCP Server <-> ChromeAdapter <-> WebSocket <-> Chrome Extension <-> chrome.debugger API <-> CDP
|
|
7
|
+
*
|
|
8
|
+
* The Chrome Extension uses chrome.debugger to attach to the active tab and
|
|
9
|
+
* forwards CDP commands/responses through a WebSocket connection to this adapter.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ChromeAdapter = void 0;
|
|
13
|
+
const cdp_bridge_js_1 = require("./transport/cdp-bridge.js");
|
|
14
|
+
const chrome_tools_js_1 = require("./tools/chrome-tools.js");
|
|
15
|
+
class ChromeAdapter {
|
|
16
|
+
platform = "chrome";
|
|
17
|
+
displayName;
|
|
18
|
+
capabilities = {
|
|
19
|
+
uiTree: true, // DOM tree -> UiNode
|
|
20
|
+
logs: true, // Console API messages
|
|
21
|
+
interaction: true, // Input.dispatch* via CDP
|
|
22
|
+
network: true, // Network domain (full request/response)
|
|
23
|
+
performance: true, // Performance domain + Web Vitals
|
|
24
|
+
screenshot: true, // Page.captureScreenshot
|
|
25
|
+
appState: true, // localStorage, cookies, sessionStorage
|
|
26
|
+
hotReload: false, // Not applicable for web (use browser refresh)
|
|
27
|
+
evalCode: true, // Runtime.evaluate
|
|
28
|
+
};
|
|
29
|
+
config;
|
|
30
|
+
bridge;
|
|
31
|
+
collector;
|
|
32
|
+
currentTabUrl = "";
|
|
33
|
+
ui = null; // TODO: DomUiProvider
|
|
34
|
+
logs = null; // TODO: ConsoleLogProvider
|
|
35
|
+
interaction = null; // TODO: CdpInteractionProvider
|
|
36
|
+
network = null; // TODO: CdpNetworkProvider
|
|
37
|
+
performance = null;
|
|
38
|
+
screenshot = null;
|
|
39
|
+
appState = null;
|
|
40
|
+
constructor(config = {}) {
|
|
41
|
+
this.config = {
|
|
42
|
+
wsPort: config.wsPort ?? parseInt(process.env.SENSAI_CHROME_PORT ?? "9230", 10),
|
|
43
|
+
tabUrlPattern: config.tabUrlPattern ?? process.env.SENSAI_CHROME_TAB_URL ?? "",
|
|
44
|
+
};
|
|
45
|
+
this.displayName = `Chrome (port ${this.config.wsPort})`;
|
|
46
|
+
this.bridge = new cdp_bridge_js_1.CdpBridge(this.config.wsPort);
|
|
47
|
+
this.collector = new chrome_tools_js_1.CdpEventCollector();
|
|
48
|
+
}
|
|
49
|
+
async initialize() {
|
|
50
|
+
try {
|
|
51
|
+
const connected = await this.bridge.connect();
|
|
52
|
+
if (connected) {
|
|
53
|
+
this.currentTabUrl = await this.bridge.getCurrentUrl();
|
|
54
|
+
// Enable CDP domains and start collecting console/network events
|
|
55
|
+
await this.collector.enableDomains(this.bridge).catch(() => {
|
|
56
|
+
// Non-fatal: tools will still work, just no buffered events
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
platform: "chrome",
|
|
61
|
+
device: `Chrome Tab: ${this.currentTabUrl || "none"}`,
|
|
62
|
+
connected,
|
|
63
|
+
capabilities: this.capabilities,
|
|
64
|
+
details: {
|
|
65
|
+
wsPort: this.config.wsPort,
|
|
66
|
+
tabUrl: this.currentTabUrl,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return {
|
|
72
|
+
platform: "chrome",
|
|
73
|
+
device: "Chrome (not connected)",
|
|
74
|
+
connected: false,
|
|
75
|
+
capabilities: this.capabilities,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
shutdown() {
|
|
80
|
+
this.bridge.disconnect();
|
|
81
|
+
}
|
|
82
|
+
isConnected() {
|
|
83
|
+
return this.bridge.isConnected();
|
|
84
|
+
}
|
|
85
|
+
registerPlatformTools(server) {
|
|
86
|
+
const prefix = "chrome_";
|
|
87
|
+
(0, chrome_tools_js_1.registerChromeTools)(server, this.bridge, this.collector, prefix);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.ChromeAdapter = ChromeAdapter;
|
|
91
|
+
//# sourceMappingURL=chrome-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @sensai/adapter-chrome — Chrome/web platform adapter for SensAI.
|
|
4
|
+
*
|
|
5
|
+
* Provides debugging tools via Chrome DevTools Protocol (CDP).
|
|
6
|
+
* Communicates with the SensAI Chrome Extension via Native Messaging or WebSocket.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ChromeAdapter = void 0;
|
|
10
|
+
var chrome_adapter_js_1 = require("./chrome-adapter.js");
|
|
11
|
+
Object.defineProperty(exports, "ChromeAdapter", { enumerable: true, get: function () { return chrome_adapter_js_1.ChromeAdapter; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chrome-tools.d.ts","sourceRoot":"","sources":["../../src/tools/chrome-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAI5D,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,YAAY;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAClD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmC;IAClE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAO;IAClC,OAAO,CAAC,cAAc,CAAS;IAE/B,oEAAoE;IAC9D,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IA4GrD,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE;IAKjD,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE;IAMpD,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,WAAW;CASpB;AAID,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GACb,IAAI,CAwiBN"}
|