n8n-nodes-smart-browser-automation 1.0.8 → 1.1.2

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
- const result = await this.mcpClient.callTool({
70
- name: toolName,
71
- arguments: toolArgs || {}
72
- });
73
- return result;
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',
@@ -209,27 +239,34 @@ class SmartBrowserAutomation {
209
239
  if (mode === 'manual') {
210
240
  // Manual mode: User selects tool and provides arguments
211
241
  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
242
  // Special case: Manual Browser Connection
221
243
  if (toolName === 'browser_connect_cdp') {
222
- const endpoint = toolArgs.endpoint;
244
+ const endpoint = this.getNodeParameter('cdpUrl', i);
223
245
  if (!endpoint) {
224
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Endpoint URL is required for browser_connect_cdp');
246
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'CDP Endpoint URL is required for browser_connect_cdp');
247
+ }
248
+ if (verbose) {
249
+ console.log(`Connecting to browser CDP: ${endpoint}`);
225
250
  }
226
251
  await sessionManager.initialize(credentials.mcpEndpoint, true, endpoint);
227
252
  returnData.push({
228
- json: { success: true, message: `Connected to browser at ${endpoint}` },
253
+ json: {
254
+ success: true,
255
+ message: `Connected to browser at ${endpoint}`,
256
+ timestamp: new Date().toISOString()
257
+ },
229
258
  pairedItem: i,
230
259
  });
231
260
  continue;
232
261
  }
262
+ const toolArgsStr = this.getNodeParameter('toolArgs', i);
263
+ let toolArgs;
264
+ try {
265
+ toolArgs = JSON.parse(toolArgsStr);
266
+ }
267
+ catch (error) {
268
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in Tool Arguments: ${error.message}`);
269
+ }
233
270
  // Initialize session if not ready
234
271
  if (!sessionManager.isReady()) {
235
272
  await sessionManager.initialize(credentials.mcpEndpoint, credentials.browserMode === 'cdp', credentials.cdpEndpoint);
@@ -251,13 +288,29 @@ class SmartBrowserAutomation {
251
288
  // AI Agent mode: Just initialize or close
252
289
  const operation = this.getNodeParameter('operation', i);
253
290
  if (operation === 'initialize') {
254
- // In AI mode, we use the credentials or fallback to nothing
255
- const cdpUrl = credentials.cdpEndpoint;
291
+ // Pull CDP URL from options if available, fallback to credentials
292
+ const cdpUrl = options.cdpUrl || credentials.cdpEndpoint;
293
+ if (verbose) {
294
+ console.log(`Initializing AI session with CDP: ${cdpUrl}`);
295
+ }
256
296
  const tools = await sessionManager.initialize(credentials.mcpEndpoint, true, cdpUrl);
297
+ // New logic: Auto-call browser_connect tool if a URL is provided
298
+ if (options.cdpUrl) {
299
+ if (verbose) {
300
+ console.log(`Auto-calling 'browser_connect' with endpoint: ${options.cdpUrl}`);
301
+ }
302
+ try {
303
+ await sessionManager.callTool('browser_connect', { endpoint: options.cdpUrl });
304
+ }
305
+ catch (error) {
306
+ console.warn(`Failed to auto-connect browser via tool: ${error.message}`);
307
+ // We don't throw here to allow the AI to potentially fix it or show the error
308
+ }
309
+ }
257
310
  returnData.push({
258
311
  json: {
259
312
  success: true,
260
- message: 'Browser session initialized. Tools are now available to AI Agent.',
313
+ message: `MCP session initialized. Browser connect tool called for ${cdpUrl}.`,
261
314
  toolsCount: tools.length,
262
315
  tools: tools.map((t) => ({
263
316
  name: t.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.0.8",
3
+ "version": "1.1.2",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",