n8n-nodes-smart-browser-automation 1.5.0 → 1.5.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.
@@ -67,7 +67,7 @@ class BrowserSessionManager {
67
67
  this.config = { mcpEndpoint, cdpEndpoint };
68
68
  // Fetch available tools from MCP server
69
69
  const toolsResponse = await this.mcpClient.listTools();
70
- await this.mcpClient.callTool({ name: 'browser_connect_cdp', arguments: { cdpEndpoint: cdpEndpoint || '' } });
70
+ await this.mcpClient.callTool({ name: 'browser_connect_cdp', arguments: { endpoint: cdpEndpoint || '' } });
71
71
  this.tools = toolsResponse.tools;
72
72
  return this.tools;
73
73
  }
@@ -36,66 +36,20 @@ class SmartBrowserAutomation {
36
36
  description: 'Override CDP endpoint from credentials. Use this to connect to a specific browser instance.',
37
37
  },
38
38
  {
39
- displayName: 'Operation',
40
- name: 'operation',
39
+ displayName: 'Tool Name or ID',
40
+ name: 'toolName',
41
41
  type: 'options',
42
- noDataExpression: true,
43
- options: [
44
- {
45
- name: 'All Tools',
46
- value: 'listTools',
47
- description: 'Get all available browser tools from MCP server',
48
- action: 'List all browser tools',
49
- },
50
- {
51
- name: 'Click',
52
- value: 'browser_click',
53
- description: 'Click an element',
54
- action: 'Click element',
55
- },
56
- {
57
- name: 'Connect to Browser',
58
- value: 'browser_connect_cdp',
59
- description: 'Connect to browser via CDP',
60
- action: 'Connect to browser via CDP',
61
- },
62
- {
63
- name: 'Navigate',
64
- value: 'browser_navigate',
65
- description: 'Navigate to a URL',
66
- action: 'Navigate to URL',
67
- },
68
- {
69
- name: 'Take Snapshot',
70
- value: 'browser_snapshot',
71
- description: 'Capture page accessibility snapshot',
72
- action: 'Take snapshot',
73
- },
74
- {
75
- name: 'Type',
76
- value: 'browser_type',
77
- description: 'Type text into an element',
78
- action: 'Type text',
79
- },
80
- ],
81
- default: 'browser_connect_cdp',
42
+ typeOptions: {
43
+ loadOptionsMethod: 'getAvailableTools',
44
+ },
45
+ default: 'browser_navigate',
46
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
82
47
  },
83
48
  {
84
49
  displayName: 'Tool Parameters',
85
50
  name: 'toolParameters',
86
51
  type: 'json',
87
52
  required: true,
88
- displayOptions: {
89
- show: {
90
- operation: [
91
- 'browser_connect_cdp',
92
- 'browser_navigate',
93
- 'browser_click',
94
- 'browser_type',
95
- 'browser_snapshot',
96
- ],
97
- },
98
- },
99
53
  default: '{}',
100
54
  description: 'Parameters to pass to the browser tool in JSON format',
101
55
  },
@@ -124,51 +78,63 @@ class SmartBrowserAutomation {
124
78
  },
125
79
  };
126
80
  async execute() {
81
+ const items = this.getInputData();
127
82
  const returnData = [];
128
83
  const credentials = await this.getCredentials('smartBrowserAutomationApi');
129
84
  const sessionManager = BrowserSessionManager_1.default.getInstance();
130
85
  // Get CDP override or use from credentials
131
86
  const cdpOverride = this.getNodeParameter('cdpOverride', 0, '');
132
- const operation = this.getNodeParameter('operation', 0);
87
+ // Check if AI Agent sent Tool_Parameters in input
88
+ const inputData = items[0]?.json;
89
+ const aiToolParams = inputData?.Tool_Parameters;
90
+ const aiAction = inputData?.action;
91
+ // Determine tool name: prefer AI input, fallback to manual parameter
92
+ let toolName;
93
+ if (aiAction && typeof aiAction === 'string') {
94
+ // AI Agent sent action like "click", "open", etc - map to browser tool
95
+ toolName = aiAction === 'open' ? 'browser_navigate' : `browser_${aiAction}`;
96
+ }
97
+ else {
98
+ // Manual mode or no AI action
99
+ toolName = this.getNodeParameter('toolName', 0);
100
+ }
133
101
  try {
134
102
  // Initialize session if not ready
135
103
  if (!sessionManager.isReady()) {
136
104
  const cdpUrl = cdpOverride || credentials.cdpEndpoint || '';
137
105
  await sessionManager.initialize(credentials.mcpEndpoint, !!cdpUrl, cdpUrl);
138
106
  }
139
- // Handle listTools operation
140
- if (operation === 'listTools') {
141
- const tools = await sessionManager.listTools();
142
- returnData.push({
143
- json: { tools },
144
- });
145
- return [returnData];
146
- }
147
107
  // Handle tool execution
148
108
  let toolParams;
149
109
  try {
150
- const rawParams = this.getNodeParameter('toolParameters', 0);
151
- if (rawParams === undefined || rawParams === null) {
152
- toolParams = {};
110
+ // First check if AI Agent sent Tool_Parameters in input
111
+ if (aiToolParams && typeof aiToolParams === 'object') {
112
+ toolParams = aiToolParams;
153
113
  }
154
- else if (typeof rawParams === 'string') {
155
- if (!rawParams || rawParams.trim() === '') {
114
+ else {
115
+ // Fallback to manual toolParameters field
116
+ const rawParams = this.getNodeParameter('toolParameters', 0);
117
+ if (rawParams === undefined || rawParams === null) {
156
118
  toolParams = {};
157
119
  }
158
- else {
159
- toolParams = JSON.parse(rawParams);
120
+ else if (typeof rawParams === 'string') {
121
+ if (!rawParams || rawParams.trim() === '') {
122
+ toolParams = {};
123
+ }
124
+ else {
125
+ toolParams = JSON.parse(rawParams);
126
+ }
160
127
  }
161
- }
162
- else if (typeof rawParams === 'object') {
163
- // Handle object input (when used as a tool in AI Agent)
164
- toolParams = rawParams;
165
- }
166
- else {
167
- try {
168
- toolParams = JSON.parse(JSON.stringify(rawParams));
128
+ else if (typeof rawParams === 'object') {
129
+ toolParams = rawParams;
169
130
  }
170
- catch (parseError) {
171
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid parameter type: ${typeof rawParams}`);
131
+ else {
132
+ try {
133
+ toolParams = JSON.parse(JSON.stringify(rawParams));
134
+ }
135
+ catch (parseError) {
136
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid parameter type: ${typeof rawParams}`);
137
+ }
172
138
  }
173
139
  }
174
140
  // Ensure toolParams is an object
@@ -182,7 +148,7 @@ class SmartBrowserAutomation {
182
148
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to parse tool parameters: ${error.message}. Make sure the parameters are valid JSON.`);
183
149
  }
184
150
  // Special handling for browser_connect_cdp
185
- if (operation === 'browser_connect_cdp') {
151
+ if (toolName === 'browser_connect_cdp') {
186
152
  const endpoint = toolParams.endpoint || cdpOverride || credentials.cdpEndpoint;
187
153
  if (!endpoint) {
188
154
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'CDP endpoint is required. Provide it in tool parameters or CDP Endpoint Override field.');
@@ -201,7 +167,7 @@ class SmartBrowserAutomation {
201
167
  return [returnData];
202
168
  }
203
169
  // Execute the tool via MCP
204
- const result = await sessionManager.callTool(operation, toolParams);
170
+ const result = await sessionManager.callTool(toolName, toolParams);
205
171
  returnData.push({
206
172
  json: { result },
207
173
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.5.0",
3
+ "version": "1.5.3",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",