mcp-chrome-bridger 1.0.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/README.md +183 -0
- package/dist/README.md +25 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +185 -0
- package/dist/cli.js.map +1 -0
- package/dist/constant/index.d.ts +38 -0
- package/dist/constant/index.js +47 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/file-handler.d.ts +37 -0
- package/dist/file-handler.js +245 -0
- package/dist/file-handler.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/mcp-server-stdio.d.ts +50 -0
- package/dist/mcp/mcp-server-stdio.js +141 -0
- package/dist/mcp/mcp-server-stdio.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +25 -0
- package/dist/mcp/mcp-server.js +23 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/register-tools.d.ts +2 -0
- package/dist/mcp/register-tools.js +51 -0
- package/dist/mcp/register-tools.js.map +1 -0
- package/dist/mcp/stdio-config.json +3 -0
- package/dist/native-messaging-host.d.ts +42 -0
- package/dist/native-messaging-host.js +287 -0
- package/dist/native-messaging-host.js.map +1 -0
- package/dist/run_host.bat +95 -0
- package/dist/run_host.sh +141 -0
- package/dist/scripts/browser-config.d.ts +28 -0
- package/dist/scripts/browser-config.js +229 -0
- package/dist/scripts/browser-config.js.map +1 -0
- package/dist/scripts/build.d.ts +1 -0
- package/dist/scripts/build.js +119 -0
- package/dist/scripts/build.js.map +1 -0
- package/dist/scripts/constant.d.ts +5 -0
- package/dist/scripts/constant.js +9 -0
- package/dist/scripts/constant.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +2 -0
- package/dist/scripts/postinstall.js +231 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/scripts/register-dev.d.ts +1 -0
- package/dist/scripts/register-dev.js +5 -0
- package/dist/scripts/register-dev.js.map +1 -0
- package/dist/scripts/register.d.ts +2 -0
- package/dist/scripts/register.js +22 -0
- package/dist/scripts/register.js.map +1 -0
- package/dist/scripts/utils.d.ts +37 -0
- package/dist/scripts/utils.js +380 -0
- package/dist/scripts/utils.js.map +1 -0
- package/dist/server/index.d.ts +20 -0
- package/dist/server/index.js +250 -0
- package/dist/server/index.js.map +1 -0
- package/dist/util/logger.d.ts +1 -0
- package/dist/util/logger.js +43 -0
- package/dist/util/logger.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NativeMessagingHost = void 0;
|
|
7
|
+
const process_1 = require("process");
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const chrome_mcp_shared_1 = require("chrome-mcp-shared");
|
|
10
|
+
const constant_1 = require("./constant");
|
|
11
|
+
const file_handler_1 = __importDefault(require("./file-handler"));
|
|
12
|
+
class NativeMessagingHost {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.associatedServer = null;
|
|
15
|
+
this.pendingRequests = new Map();
|
|
16
|
+
}
|
|
17
|
+
setServer(serverInstance) {
|
|
18
|
+
this.associatedServer = serverInstance;
|
|
19
|
+
}
|
|
20
|
+
// add message handler to wait for start server
|
|
21
|
+
start() {
|
|
22
|
+
try {
|
|
23
|
+
this.setupMessageHandling();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
setupMessageHandling() {
|
|
30
|
+
let buffer = Buffer.alloc(0);
|
|
31
|
+
let expectedLength = -1;
|
|
32
|
+
process_1.stdin.on('readable', () => {
|
|
33
|
+
let chunk;
|
|
34
|
+
while ((chunk = process_1.stdin.read()) !== null) {
|
|
35
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
36
|
+
if (expectedLength === -1 && buffer.length >= 4) {
|
|
37
|
+
expectedLength = buffer.readUInt32LE(0);
|
|
38
|
+
buffer = buffer.slice(4);
|
|
39
|
+
}
|
|
40
|
+
if (expectedLength !== -1 && buffer.length >= expectedLength) {
|
|
41
|
+
const messageBuffer = buffer.slice(0, expectedLength);
|
|
42
|
+
buffer = buffer.slice(expectedLength);
|
|
43
|
+
try {
|
|
44
|
+
const message = JSON.parse(messageBuffer.toString());
|
|
45
|
+
this.handleMessage(message);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
this.sendError(`Failed to parse message: ${error.message}`);
|
|
49
|
+
}
|
|
50
|
+
expectedLength = -1; // reset to get next data
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
process_1.stdin.on('end', () => {
|
|
55
|
+
this.cleanup();
|
|
56
|
+
});
|
|
57
|
+
process_1.stdin.on('error', () => {
|
|
58
|
+
this.cleanup();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async handleMessage(message) {
|
|
62
|
+
var _a;
|
|
63
|
+
if (!message || typeof message !== 'object') {
|
|
64
|
+
this.sendError('Invalid message format');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (message.responseToRequestId) {
|
|
68
|
+
const requestId = message.responseToRequestId;
|
|
69
|
+
const pending = this.pendingRequests.get(requestId);
|
|
70
|
+
if (pending) {
|
|
71
|
+
clearTimeout(pending.timeoutId);
|
|
72
|
+
if (message.error) {
|
|
73
|
+
pending.reject(new Error(message.error));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
pending.resolve(message.payload);
|
|
77
|
+
}
|
|
78
|
+
this.pendingRequests.delete(requestId);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// just ignore
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Handle directive messages from Chrome
|
|
86
|
+
try {
|
|
87
|
+
switch (message.type) {
|
|
88
|
+
case chrome_mcp_shared_1.NativeMessageType.START:
|
|
89
|
+
await this.startServer(((_a = message.payload) === null || _a === void 0 ? void 0 : _a.port) || 3000);
|
|
90
|
+
break;
|
|
91
|
+
case chrome_mcp_shared_1.NativeMessageType.STOP:
|
|
92
|
+
await this.stopServer();
|
|
93
|
+
break;
|
|
94
|
+
// Keep ping/pong for simple liveness detection, but this differs from request-response pattern
|
|
95
|
+
case 'ping_from_extension':
|
|
96
|
+
this.sendMessage({ type: 'pong_to_extension' });
|
|
97
|
+
break;
|
|
98
|
+
case 'file_operation':
|
|
99
|
+
await this.handleFileOperation(message);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
// Double check when message type is not supported
|
|
103
|
+
if (!message.responseToRequestId) {
|
|
104
|
+
this.sendError(`Unknown message type or non-response message: ${message.type || 'no type'}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
this.sendError(`Failed to handle directive message: ${error.message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Handle file operations from the extension
|
|
114
|
+
*/
|
|
115
|
+
async handleFileOperation(message) {
|
|
116
|
+
try {
|
|
117
|
+
const result = await file_handler_1.default.handleFileRequest(message.payload);
|
|
118
|
+
if (message.requestId) {
|
|
119
|
+
// Send response back with the request ID
|
|
120
|
+
this.sendMessage({
|
|
121
|
+
type: 'file_operation_response',
|
|
122
|
+
responseToRequestId: message.requestId,
|
|
123
|
+
payload: result,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// No request ID, just send result
|
|
128
|
+
this.sendMessage({
|
|
129
|
+
type: 'file_operation_result',
|
|
130
|
+
payload: result,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
const errorResponse = {
|
|
136
|
+
success: false,
|
|
137
|
+
error: error.message || 'Unknown error during file operation',
|
|
138
|
+
};
|
|
139
|
+
if (message.requestId) {
|
|
140
|
+
this.sendMessage({
|
|
141
|
+
type: 'file_operation_response',
|
|
142
|
+
responseToRequestId: message.requestId,
|
|
143
|
+
error: errorResponse.error,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.sendError(`File operation failed: ${errorResponse.error}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Send request to Chrome and wait for response
|
|
153
|
+
* @param messagePayload Data to send to Chrome
|
|
154
|
+
* @param timeoutMs Timeout for waiting response (milliseconds)
|
|
155
|
+
* @returns Promise, resolves to Chrome's returned payload on success, rejects on failure
|
|
156
|
+
*/
|
|
157
|
+
sendRequestToExtensionAndWait(messagePayload, messageType = 'request_data', timeoutMs = constant_1.TIMEOUTS.DEFAULT_REQUEST_TIMEOUT) {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
const requestId = (0, uuid_1.v4)(); // Generate unique request ID
|
|
160
|
+
const timeoutId = setTimeout(() => {
|
|
161
|
+
this.pendingRequests.delete(requestId); // Remove from Map after timeout
|
|
162
|
+
reject(new Error(`Request timed out after ${timeoutMs}ms`));
|
|
163
|
+
}, timeoutMs);
|
|
164
|
+
// Store request's resolve/reject functions and timeout ID
|
|
165
|
+
this.pendingRequests.set(requestId, { resolve, reject, timeoutId });
|
|
166
|
+
// Send message with requestId to Chrome
|
|
167
|
+
this.sendMessage({
|
|
168
|
+
type: messageType, // Define a request type, e.g. 'request_data'
|
|
169
|
+
payload: messagePayload,
|
|
170
|
+
requestId: requestId, // <--- Key: include request ID
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Start Fastify server (now accepts Server instance)
|
|
176
|
+
*/
|
|
177
|
+
async startServer(port) {
|
|
178
|
+
if (!this.associatedServer) {
|
|
179
|
+
this.sendError('Internal error: server instance not set');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
if (this.associatedServer.isRunning) {
|
|
184
|
+
this.sendMessage({
|
|
185
|
+
type: chrome_mcp_shared_1.NativeMessageType.ERROR,
|
|
186
|
+
payload: { message: 'Server is already running' },
|
|
187
|
+
});
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
await this.associatedServer.start(port, this);
|
|
191
|
+
this.sendMessage({
|
|
192
|
+
type: chrome_mcp_shared_1.NativeMessageType.SERVER_STARTED,
|
|
193
|
+
payload: { port },
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
this.sendError(`Failed to start server: ${error.message}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Stop Fastify server
|
|
202
|
+
*/
|
|
203
|
+
async stopServer() {
|
|
204
|
+
if (!this.associatedServer) {
|
|
205
|
+
this.sendError('Internal error: server instance not set');
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
// Check status through associatedServer
|
|
210
|
+
if (!this.associatedServer.isRunning) {
|
|
211
|
+
this.sendMessage({
|
|
212
|
+
type: chrome_mcp_shared_1.NativeMessageType.ERROR,
|
|
213
|
+
payload: { message: 'Server is not running' },
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
await this.associatedServer.stop();
|
|
218
|
+
// this.serverStarted = false; // Server should update its own status after successful stop
|
|
219
|
+
this.sendMessage({ type: chrome_mcp_shared_1.NativeMessageType.SERVER_STOPPED }); // Distinguish from previous 'stopped'
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
this.sendError(`Failed to stop server: ${error.message}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Send message to Chrome extension
|
|
227
|
+
*/
|
|
228
|
+
sendMessage(message) {
|
|
229
|
+
try {
|
|
230
|
+
const messageString = JSON.stringify(message);
|
|
231
|
+
const messageBuffer = Buffer.from(messageString);
|
|
232
|
+
const headerBuffer = Buffer.alloc(4);
|
|
233
|
+
headerBuffer.writeUInt32LE(messageBuffer.length, 0);
|
|
234
|
+
// Ensure atomic write
|
|
235
|
+
process_1.stdout.write(Buffer.concat([headerBuffer, messageBuffer]), (err) => {
|
|
236
|
+
if (err) {
|
|
237
|
+
// Consider how to handle write failure, may affect request completion
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// Message sent successfully, no action needed
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
// Catch JSON.stringify or Buffer operation errors
|
|
246
|
+
// If preparation stage fails, associated request may never be sent
|
|
247
|
+
// Need to consider whether to reject corresponding Promise (if called within sendRequestToExtensionAndWait)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Send error message to Chrome extension (mainly for sending non-request-response type errors)
|
|
252
|
+
*/
|
|
253
|
+
sendError(errorMessage) {
|
|
254
|
+
this.sendMessage({
|
|
255
|
+
type: chrome_mcp_shared_1.NativeMessageType.ERROR_FROM_NATIVE_HOST, // Use more explicit type
|
|
256
|
+
payload: { message: errorMessage },
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Clean up resources
|
|
261
|
+
*/
|
|
262
|
+
cleanup() {
|
|
263
|
+
// Reject all pending requests
|
|
264
|
+
this.pendingRequests.forEach((pending) => {
|
|
265
|
+
clearTimeout(pending.timeoutId);
|
|
266
|
+
pending.reject(new Error('Native host is shutting down or Chrome disconnected.'));
|
|
267
|
+
});
|
|
268
|
+
this.pendingRequests.clear();
|
|
269
|
+
if (this.associatedServer && this.associatedServer.isRunning) {
|
|
270
|
+
this.associatedServer
|
|
271
|
+
.stop()
|
|
272
|
+
.then(() => {
|
|
273
|
+
process.exit(0);
|
|
274
|
+
})
|
|
275
|
+
.catch(() => {
|
|
276
|
+
process.exit(1);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
process.exit(0);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.NativeMessagingHost = NativeMessagingHost;
|
|
285
|
+
const nativeMessagingHostInstance = new NativeMessagingHost();
|
|
286
|
+
exports.default = nativeMessagingHostInstance;
|
|
287
|
+
//# sourceMappingURL=native-messaging-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-messaging-host.js","sourceRoot":"","sources":["../src/native-messaging-host.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAwC;AAExC,+BAAoC;AACpC,yDAAsD;AACtD,yCAAsC;AACtC,kEAAyC;AAQzC,MAAa,mBAAmB;IAAhC;QACU,qBAAgB,GAAkB,IAAI,CAAC;QACvC,oBAAe,GAAgC,IAAI,GAAG,EAAE,CAAC;IAoSnE,CAAC;IAlSQ,SAAS,CAAC,cAAsB;QACrC,IAAI,CAAC,gBAAgB,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,+CAA+C;IACxC,KAAK;QACV,IAAI,CAAC;YACH,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,cAAc,GAAG,CAAC,CAAC,CAAC;QAExB,eAAK,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;YACxB,IAAI,KAAK,CAAC;YACV,OAAO,CAAC,KAAK,GAAG,eAAK,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;gBACvC,MAAM,GAAG,MAAM,CAAC,MAAM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EAAE;gBACT,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAtSD,kDAsSC;AAED,MAAM,2BAA2B,GAAG,IAAI,mBAAmB,EAAE,CAAC;AAC9D,kBAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
REM Setup paths
|
|
5
|
+
set "SCRIPT_DIR=%~dp0"
|
|
6
|
+
if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
|
|
7
|
+
set "LOG_DIR=%SCRIPT_DIR%\logs"
|
|
8
|
+
set "NODE_SCRIPT=%SCRIPT_DIR%\index.js"
|
|
9
|
+
|
|
10
|
+
if not exist "%LOG_DIR%" md "%LOG_DIR%"
|
|
11
|
+
|
|
12
|
+
REM Generate timestamp
|
|
13
|
+
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format 'yyyyMMdd_HHmmss'"') do set "TIMESTAMP=%%i"
|
|
14
|
+
set "WRAPPER_LOG=%LOG_DIR%\native_host_wrapper_windows_%TIMESTAMP%.log"
|
|
15
|
+
set "STDERR_LOG=%LOG_DIR%\native_host_stderr_windows_%TIMESTAMP%.log"
|
|
16
|
+
|
|
17
|
+
REM Initial logging
|
|
18
|
+
echo Wrapper script called at %DATE% %TIME% > "%WRAPPER_LOG%"
|
|
19
|
+
echo SCRIPT_DIR: %SCRIPT_DIR% >> "%WRAPPER_LOG%"
|
|
20
|
+
echo LOG_DIR: %LOG_DIR% >> "%WRAPPER_LOG%"
|
|
21
|
+
echo NODE_SCRIPT: %NODE_SCRIPT% >> "%WRAPPER_LOG%"
|
|
22
|
+
echo Initial PATH: %PATH% >> "%WRAPPER_LOG%"
|
|
23
|
+
echo User: %USERNAME% >> "%WRAPPER_LOG%"
|
|
24
|
+
echo Current PWD: %CD% >> "%WRAPPER_LOG%"
|
|
25
|
+
|
|
26
|
+
REM Node.js discovery
|
|
27
|
+
set "NODE_EXEC="
|
|
28
|
+
|
|
29
|
+
REM Priority 1: Installation-time node path
|
|
30
|
+
set "NODE_PATH_FILE=%SCRIPT_DIR%\node_path.txt"
|
|
31
|
+
echo Checking installation-time node path >> "%WRAPPER_LOG%"
|
|
32
|
+
if exist "%NODE_PATH_FILE%" (
|
|
33
|
+
set /p EXPECTED_NODE=<"%NODE_PATH_FILE%"
|
|
34
|
+
if exist "!EXPECTED_NODE!" (
|
|
35
|
+
set "NODE_EXEC=!EXPECTED_NODE!"
|
|
36
|
+
echo Found installation-time node at !NODE_EXEC! >> "%WRAPPER_LOG%"
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
REM Priority 1.5: Fallback to relative path
|
|
41
|
+
if not defined NODE_EXEC (
|
|
42
|
+
set "EXPECTED_NODE=%SCRIPT_DIR%\..\..\..\node.exe"
|
|
43
|
+
echo Checking relative path >> "%WRAPPER_LOG%"
|
|
44
|
+
if exist "%EXPECTED_NODE%" (
|
|
45
|
+
set "NODE_EXEC=%EXPECTED_NODE%"
|
|
46
|
+
echo Found node at relative path: !NODE_EXEC! >> "%WRAPPER_LOG%"
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
REM Priority 2: where command
|
|
51
|
+
if not defined NODE_EXEC (
|
|
52
|
+
echo Trying 'where node.exe' >> "%WRAPPER_LOG%"
|
|
53
|
+
for /f "delims=" %%i in ('where node.exe 2^>nul') do (
|
|
54
|
+
if not defined NODE_EXEC (
|
|
55
|
+
set "NODE_EXEC=%%i"
|
|
56
|
+
echo Found node using 'where': !NODE_EXEC! >> "%WRAPPER_LOG%"
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
REM Priority 3: Common paths
|
|
62
|
+
if not defined NODE_EXEC (
|
|
63
|
+
if exist "%ProgramFiles%\nodejs\node.exe" (
|
|
64
|
+
set "NODE_EXEC=%ProgramFiles%\nodejs\node.exe"
|
|
65
|
+
echo Found node at !NODE_EXEC! >> "%WRAPPER_LOG%"
|
|
66
|
+
) else if exist "%ProgramFiles(x86)%\nodejs\node.exe" (
|
|
67
|
+
set "NODE_EXEC=%ProgramFiles(x86)%\nodejs\node.exe"
|
|
68
|
+
echo Found node at !NODE_EXEC! >> "%WRAPPER_LOG%"
|
|
69
|
+
) else if exist "%LOCALAPPDATA%\Programs\nodejs\node.exe" (
|
|
70
|
+
set "NODE_EXEC=%LOCALAPPDATA%\Programs\nodejs\node.exe"
|
|
71
|
+
echo Found node at !NODE_EXEC! >> "%WRAPPER_LOG%"
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
REM Validation
|
|
76
|
+
if not defined NODE_EXEC (
|
|
77
|
+
echo ERROR: Node.js executable not found! >> "%WRAPPER_LOG%"
|
|
78
|
+
exit /B 1
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
echo Using Node executable: %NODE_EXEC% >> "%WRAPPER_LOG%"
|
|
82
|
+
call "%NODE_EXEC%" -v >> "%WRAPPER_LOG%" 2>>&1
|
|
83
|
+
|
|
84
|
+
if not exist "%NODE_SCRIPT%" (
|
|
85
|
+
echo ERROR: Node.js script not found at %NODE_SCRIPT% >> "%WRAPPER_LOG%"
|
|
86
|
+
exit /B 1
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
echo Executing: "%NODE_EXEC%" "%NODE_SCRIPT%" >> "%WRAPPER_LOG%"
|
|
90
|
+
call "%NODE_EXEC%" "%NODE_SCRIPT%" 2>> "%STDERR_LOG%"
|
|
91
|
+
set "EXIT_CODE=%ERRORLEVEL%"
|
|
92
|
+
|
|
93
|
+
echo Exit code: %EXIT_CODE% >> "%WRAPPER_LOG%"
|
|
94
|
+
endlocal
|
|
95
|
+
exit /B %EXIT_CODE%
|
package/dist/run_host.sh
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Configuration
|
|
4
|
+
ENABLE_LOG_ROTATION="true"
|
|
5
|
+
LOG_RETENTION_COUNT=5
|
|
6
|
+
|
|
7
|
+
# Setup paths
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
9
|
+
LOG_DIR="${SCRIPT_DIR}/logs"
|
|
10
|
+
mkdir -p "${LOG_DIR}"
|
|
11
|
+
|
|
12
|
+
# Log rotation
|
|
13
|
+
if [ "${ENABLE_LOG_ROTATION}" = "true" ]; then
|
|
14
|
+
ls -tp "${LOG_DIR}/native_host_wrapper_macos_"* 2>/dev/null | tail -n +$((LOG_RETENTION_COUNT + 1)) | xargs -I {} rm -- {}
|
|
15
|
+
ls -tp "${LOG_DIR}/native_host_stderr_macos_"* 2>/dev/null | tail -n +$((LOG_RETENTION_COUNT + 1)) | xargs -I {} rm -- {}
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# Logging setup
|
|
19
|
+
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
|
20
|
+
WRAPPER_LOG="${LOG_DIR}/native_host_wrapper_macos_${TIMESTAMP}.log"
|
|
21
|
+
STDERR_LOG="${LOG_DIR}/native_host_stderr_macos_${TIMESTAMP}.log"
|
|
22
|
+
NODE_SCRIPT="${SCRIPT_DIR}/index.js"
|
|
23
|
+
|
|
24
|
+
# Initial logging
|
|
25
|
+
{
|
|
26
|
+
echo "--- Wrapper script called at $(date) ---"
|
|
27
|
+
echo "SCRIPT_DIR: ${SCRIPT_DIR}"
|
|
28
|
+
echo "LOG_DIR: ${LOG_DIR}"
|
|
29
|
+
echo "NODE_SCRIPT: ${NODE_SCRIPT}"
|
|
30
|
+
echo "Initial PATH: ${PATH}"
|
|
31
|
+
echo "User: $(whoami)"
|
|
32
|
+
echo "Current PWD: $(pwd)"
|
|
33
|
+
} > "${WRAPPER_LOG}"
|
|
34
|
+
|
|
35
|
+
# Node.js discovery
|
|
36
|
+
NODE_EXEC=""
|
|
37
|
+
|
|
38
|
+
# Priority 1: Installation-time node path
|
|
39
|
+
NODE_PATH_FILE="${SCRIPT_DIR}/node_path.txt"
|
|
40
|
+
echo "Searching for Node.js..." >> "${WRAPPER_LOG}"
|
|
41
|
+
echo "[Priority 1] Checking installation-time node path" >> "${WRAPPER_LOG}"
|
|
42
|
+
if [ -f "${NODE_PATH_FILE}" ]; then
|
|
43
|
+
EXPECTED_NODE=$(cat "${NODE_PATH_FILE}" 2>/dev/null | tr -d '\n\r')
|
|
44
|
+
if [ -n "${EXPECTED_NODE}" ] && [ -x "${EXPECTED_NODE}" ]; then
|
|
45
|
+
NODE_EXEC="${EXPECTED_NODE}"
|
|
46
|
+
echo "Found installation-time node at ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
47
|
+
fi
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# Priority 1.5: Fallback to relative path
|
|
51
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
52
|
+
EXPECTED_NODE="${SCRIPT_DIR}/../../../bin/node"
|
|
53
|
+
echo "[Priority 1.5] Checking relative path" >> "${WRAPPER_LOG}"
|
|
54
|
+
if [ -x "${EXPECTED_NODE}" ]; then
|
|
55
|
+
NODE_EXEC="${EXPECTED_NODE}"
|
|
56
|
+
echo "Found node at relative path: ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
57
|
+
fi
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# Priority 2: NVM
|
|
61
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
62
|
+
echo "[Priority 2] Checking NVM" >> "${WRAPPER_LOG}"
|
|
63
|
+
NVM_DIR="$HOME/.nvm"
|
|
64
|
+
if [ -d "${NVM_DIR}" ]; then
|
|
65
|
+
# Try default version first
|
|
66
|
+
if [ -L "${NVM_DIR}/alias/default" ]; then
|
|
67
|
+
NVM_DEFAULT_VERSION=$(readlink "${NVM_DIR}/alias/default")
|
|
68
|
+
NVM_DEFAULT_NODE="${NVM_DIR}/versions/node/${NVM_DEFAULT_VERSION}/bin/node"
|
|
69
|
+
if [ -x "${NVM_DEFAULT_NODE}" ]; then
|
|
70
|
+
NODE_EXEC="${NVM_DEFAULT_NODE}"
|
|
71
|
+
echo "Found NVM default node: ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
72
|
+
fi
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# Fallback to latest version
|
|
76
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
77
|
+
LATEST_NVM_VERSION_PATH=$(ls -d ${NVM_DIR}/versions/node/v* 2>/dev/null | sort -V | tail -n 1)
|
|
78
|
+
if [ -n "${LATEST_NVM_VERSION_PATH}" ] && [ -x "${LATEST_NVM_VERSION_PATH}/bin/node" ]; then
|
|
79
|
+
NODE_EXEC="${LATEST_NVM_VERSION_PATH}/bin/node"
|
|
80
|
+
echo "Found NVM latest node: ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
81
|
+
fi
|
|
82
|
+
fi
|
|
83
|
+
fi
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
# Priority 3: Common paths
|
|
87
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
88
|
+
echo "[Priority 3] Checking common paths" >> "${WRAPPER_LOG}"
|
|
89
|
+
COMMON_NODE_PATHS=(
|
|
90
|
+
"/opt/homebrew/bin/node"
|
|
91
|
+
"/usr/local/bin/node"
|
|
92
|
+
)
|
|
93
|
+
for path_to_node in "${COMMON_NODE_PATHS[@]}"; do
|
|
94
|
+
if [ -x "${path_to_node}" ]; then
|
|
95
|
+
NODE_EXEC="${path_to_node}"
|
|
96
|
+
echo "Found node at: ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
97
|
+
break
|
|
98
|
+
fi
|
|
99
|
+
done
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
# Priority 4: command -v
|
|
103
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
104
|
+
echo "[Priority 4] Trying 'command -v node'" >> "${WRAPPER_LOG}"
|
|
105
|
+
if command -v node &>/dev/null; then
|
|
106
|
+
NODE_EXEC=$(command -v node)
|
|
107
|
+
echo "Found node using 'command -v': ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
108
|
+
fi
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
# Priority 5: PATH search
|
|
112
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
113
|
+
echo "[Priority 5] Searching PATH" >> "${WRAPPER_LOG}"
|
|
114
|
+
OLD_IFS=$IFS
|
|
115
|
+
IFS=:
|
|
116
|
+
for path_in_env in $PATH; do
|
|
117
|
+
if [ -x "${path_in_env}/node" ]; then
|
|
118
|
+
NODE_EXEC="${path_in_env}/node"
|
|
119
|
+
echo "Found node in PATH: ${NODE_EXEC}" >> "${WRAPPER_LOG}"
|
|
120
|
+
break
|
|
121
|
+
fi
|
|
122
|
+
done
|
|
123
|
+
IFS=$OLD_IFS
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
# Execution
|
|
127
|
+
if [ -z "${NODE_EXEC}" ]; then
|
|
128
|
+
{
|
|
129
|
+
echo "ERROR: Node.js executable not found!"
|
|
130
|
+
echo "Searched: installation path, relative path, NVM, common paths, command -v, PATH"
|
|
131
|
+
} >> "${WRAPPER_LOG}"
|
|
132
|
+
exit 1
|
|
133
|
+
fi
|
|
134
|
+
|
|
135
|
+
{
|
|
136
|
+
echo "Using Node executable: ${NODE_EXEC}"
|
|
137
|
+
echo "Node version: $(${NODE_EXEC} -v)"
|
|
138
|
+
echo "Executing: ${NODE_EXEC} ${NODE_SCRIPT}"
|
|
139
|
+
} >> "${WRAPPER_LOG}"
|
|
140
|
+
|
|
141
|
+
exec "${NODE_EXEC}" "${NODE_SCRIPT}" 2>> "${STDERR_LOG}"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare enum BrowserType {
|
|
2
|
+
CHROME = "chrome",
|
|
3
|
+
CHROMIUM = "chromium"
|
|
4
|
+
}
|
|
5
|
+
export interface BrowserConfig {
|
|
6
|
+
type: BrowserType;
|
|
7
|
+
displayName: string;
|
|
8
|
+
userManifestPath: string;
|
|
9
|
+
systemManifestPath: string;
|
|
10
|
+
registryKey?: string;
|
|
11
|
+
systemRegistryKey?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get browser configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare function getBrowserConfig(browser: BrowserType): BrowserConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Detect installed browsers on the system
|
|
19
|
+
*/
|
|
20
|
+
export declare function detectInstalledBrowsers(): BrowserType[];
|
|
21
|
+
/**
|
|
22
|
+
* Get all supported browser configs
|
|
23
|
+
*/
|
|
24
|
+
export declare function getAllBrowserConfigs(): BrowserConfig[];
|
|
25
|
+
/**
|
|
26
|
+
* Parse browser type from string
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseBrowserType(browserStr: string): BrowserType | undefined;
|