n8n-nodes-smart-browser-automation 1.0.8 → 1.1.3
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.
|
@@ -66,11 +66,20 @@ class BrowserSessionManager {
|
|
|
66
66
|
if (!this.mcpClient || !this.isInitialized) {
|
|
67
67
|
throw new Error('MCP client not initialized. Please configure credentials first.');
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
try {
|
|
70
|
+
if (this.config.mcpEndpoint?.includes('http')) {
|
|
71
|
+
console.log(`Calling remote tool: ${toolName} on ${this.config.mcpEndpoint}`);
|
|
72
|
+
}
|
|
73
|
+
const result = await this.mcpClient.callTool({
|
|
74
|
+
name: toolName,
|
|
75
|
+
arguments: toolArgs || {}
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error(`MCP Tool Call Error (${toolName}):`, error);
|
|
81
|
+
throw new Error(`MCP Tool Error: ${error.message}${error.data ? ' - ' + JSON.stringify(error.data) : ''}`);
|
|
82
|
+
}
|
|
74
83
|
}
|
|
75
84
|
getTools() {
|
|
76
85
|
return this.tools;
|
|
@@ -60,10 +60,24 @@ class SmartBrowserAutomation {
|
|
|
60
60
|
mode: ['manual'],
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
|
-
default: '',
|
|
64
|
-
description: 'Select the browser automation tool to execute. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
|
63
|
+
default: 'browser_connect_cdp',
|
|
64
|
+
description: 'Select the browser automation tool to execute. Choose "Connect to Browser (CDP)" to initialize/switch browser sessions. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
|
65
65
|
required: true,
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
displayName: 'CDP Endpoint',
|
|
69
|
+
name: 'cdpUrl',
|
|
70
|
+
type: 'string',
|
|
71
|
+
displayOptions: {
|
|
72
|
+
show: {
|
|
73
|
+
mode: ['manual'],
|
|
74
|
+
toolName: ['browser_connect_cdp'],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
default: '',
|
|
78
|
+
placeholder: 'wss://gridnew.doingerp.com/devtools/...',
|
|
79
|
+
description: 'The wss:// or http:// endpoint for the browser CDP connection',
|
|
80
|
+
},
|
|
67
81
|
{
|
|
68
82
|
displayName: 'Tool Arguments',
|
|
69
83
|
name: 'toolArgs',
|
|
@@ -72,6 +86,9 @@ class SmartBrowserAutomation {
|
|
|
72
86
|
show: {
|
|
73
87
|
mode: ['manual'],
|
|
74
88
|
},
|
|
89
|
+
hide: {
|
|
90
|
+
toolName: ['browser_connect_cdp'],
|
|
91
|
+
},
|
|
75
92
|
},
|
|
76
93
|
default: '{}',
|
|
77
94
|
description: 'Arguments for the selected tool in JSON format',
|
|
@@ -108,7 +125,20 @@ class SmartBrowserAutomation {
|
|
|
108
125
|
type: 'collection',
|
|
109
126
|
placeholder: 'Add Option',
|
|
110
127
|
default: {},
|
|
128
|
+
displayOptions: {
|
|
129
|
+
show: {
|
|
130
|
+
mode: ['aiAgent'],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
111
133
|
options: [
|
|
134
|
+
{
|
|
135
|
+
displayName: 'CDP Endpoint',
|
|
136
|
+
name: 'cdpUrl',
|
|
137
|
+
type: 'string',
|
|
138
|
+
default: '',
|
|
139
|
+
placeholder: 'wss://gridnew.doingerp.com/devtools/...',
|
|
140
|
+
description: 'The wss:// or http:// endpoint for the browser CDP connection',
|
|
141
|
+
},
|
|
112
142
|
{
|
|
113
143
|
displayName: 'Enabled Tool Names or IDs',
|
|
114
144
|
name: 'enabledTools',
|
|
@@ -191,7 +221,10 @@ class SmartBrowserAutomation {
|
|
|
191
221
|
const sessionManager = BrowserSessionManager_1.default.getInstance();
|
|
192
222
|
const credentials = await this.getCredentials('smartBrowserAutomationApi');
|
|
193
223
|
await sessionManager.initialize(credentials.mcpEndpoint, true, input.endpoint);
|
|
194
|
-
return {
|
|
224
|
+
return {
|
|
225
|
+
content: [{ type: 'text', text: `Successfully connected to browser at ${input.endpoint}` }],
|
|
226
|
+
isError: false
|
|
227
|
+
};
|
|
195
228
|
}
|
|
196
229
|
};
|
|
197
230
|
return [connectTool, ...tools];
|
|
@@ -209,27 +242,34 @@ class SmartBrowserAutomation {
|
|
|
209
242
|
if (mode === 'manual') {
|
|
210
243
|
// Manual mode: User selects tool and provides arguments
|
|
211
244
|
const toolName = this.getNodeParameter('toolName', i);
|
|
212
|
-
const toolArgsStr = this.getNodeParameter('toolArgs', i);
|
|
213
|
-
let toolArgs;
|
|
214
|
-
try {
|
|
215
|
-
toolArgs = JSON.parse(toolArgsStr);
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in Tool Arguments: ${error.message}`);
|
|
219
|
-
}
|
|
220
245
|
// Special case: Manual Browser Connection
|
|
221
246
|
if (toolName === 'browser_connect_cdp') {
|
|
222
|
-
const endpoint =
|
|
247
|
+
const endpoint = this.getNodeParameter('cdpUrl', i);
|
|
223
248
|
if (!endpoint) {
|
|
224
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Endpoint URL is required for browser_connect_cdp');
|
|
249
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'CDP Endpoint URL is required for browser_connect_cdp');
|
|
250
|
+
}
|
|
251
|
+
if (verbose) {
|
|
252
|
+
console.log(`Connecting to browser CDP: ${endpoint}`);
|
|
225
253
|
}
|
|
226
254
|
await sessionManager.initialize(credentials.mcpEndpoint, true, endpoint);
|
|
227
255
|
returnData.push({
|
|
228
|
-
json: {
|
|
256
|
+
json: {
|
|
257
|
+
success: true,
|
|
258
|
+
message: `Connected to browser at ${endpoint}`,
|
|
259
|
+
timestamp: new Date().toISOString()
|
|
260
|
+
},
|
|
229
261
|
pairedItem: i,
|
|
230
262
|
});
|
|
231
263
|
continue;
|
|
232
264
|
}
|
|
265
|
+
const toolArgsStr = this.getNodeParameter('toolArgs', i);
|
|
266
|
+
let toolArgs;
|
|
267
|
+
try {
|
|
268
|
+
toolArgs = JSON.parse(toolArgsStr);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in Tool Arguments: ${error.message}`);
|
|
272
|
+
}
|
|
233
273
|
// Initialize session if not ready
|
|
234
274
|
if (!sessionManager.isReady()) {
|
|
235
275
|
await sessionManager.initialize(credentials.mcpEndpoint, credentials.browserMode === 'cdp', credentials.cdpEndpoint);
|
|
@@ -239,11 +279,7 @@ class SmartBrowserAutomation {
|
|
|
239
279
|
}
|
|
240
280
|
const result = await sessionManager.callTool(toolName, toolArgs);
|
|
241
281
|
returnData.push({
|
|
242
|
-
json:
|
|
243
|
-
success: true,
|
|
244
|
-
tool: toolName,
|
|
245
|
-
result,
|
|
246
|
-
},
|
|
282
|
+
json: result,
|
|
247
283
|
pairedItem: i,
|
|
248
284
|
});
|
|
249
285
|
}
|
|
@@ -251,13 +287,29 @@ class SmartBrowserAutomation {
|
|
|
251
287
|
// AI Agent mode: Just initialize or close
|
|
252
288
|
const operation = this.getNodeParameter('operation', i);
|
|
253
289
|
if (operation === 'initialize') {
|
|
254
|
-
//
|
|
255
|
-
const cdpUrl = credentials.cdpEndpoint;
|
|
290
|
+
// Pull CDP URL from options if available, fallback to credentials
|
|
291
|
+
const cdpUrl = options.cdpUrl || credentials.cdpEndpoint;
|
|
292
|
+
if (verbose) {
|
|
293
|
+
console.log(`Initializing AI session with CDP: ${cdpUrl}`);
|
|
294
|
+
}
|
|
256
295
|
const tools = await sessionManager.initialize(credentials.mcpEndpoint, true, cdpUrl);
|
|
296
|
+
// New logic: Auto-call browser_connect tool if a URL is provided
|
|
297
|
+
if (options.cdpUrl) {
|
|
298
|
+
if (verbose) {
|
|
299
|
+
console.log(`Auto-calling 'browser_connect_cdp' with endpoint: ${options.cdpUrl}`);
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
await sessionManager.callTool('browser_connect_cdp', { endpoint: options.cdpUrl });
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
console.warn(`Failed to auto-connect browser via tool: ${error.message}`);
|
|
306
|
+
// We don't throw here to allow the AI to potentially fix it or show the error
|
|
307
|
+
}
|
|
308
|
+
}
|
|
257
309
|
returnData.push({
|
|
258
310
|
json: {
|
|
259
311
|
success: true,
|
|
260
|
-
message:
|
|
312
|
+
message: `MCP session initialized. Browser connect tool called for ${cdpUrl}.`,
|
|
261
313
|
toolsCount: tools.length,
|
|
262
314
|
tools: tools.map((t) => ({
|
|
263
315
|
name: t.name,
|
|
@@ -66,16 +66,10 @@ async function createDynamicBrowserTools(credentials) {
|
|
|
66
66
|
async execute(toolInput) {
|
|
67
67
|
try {
|
|
68
68
|
const result = await sessionManager.callTool(toolName, toolInput);
|
|
69
|
-
return
|
|
70
|
-
success: true,
|
|
71
|
-
result: JSON.stringify(result, null, 2),
|
|
72
|
-
};
|
|
69
|
+
return result;
|
|
73
70
|
}
|
|
74
71
|
catch (error) {
|
|
75
|
-
|
|
76
|
-
success: false,
|
|
77
|
-
error: error.message || 'Unknown error occurred',
|
|
78
|
-
};
|
|
72
|
+
throw new Error(error.message || 'Unknown error occurred');
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
};
|