n8n-nodes-smart-browser-automation 1.0.2 → 1.0.6

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.
@@ -33,9 +33,18 @@ class BrowserSessionManager {
33
33
  this.transport = new stdio_js_1.StdioClientTransport({
34
34
  command: 'node',
35
35
  args: [mcpEndpoint],
36
- env: useCDP && cdpEndpoint ? { CDP_URL: cdpEndpoint } : undefined
36
+ env: {
37
+ ...process.env,
38
+ ...(useCDP && cdpEndpoint ? { CDP_URL: cdpEndpoint } : {})
39
+ }
37
40
  });
38
- await this.mcpClient.connect(this.transport);
41
+ try {
42
+ await this.mcpClient.connect(this.transport);
43
+ }
44
+ catch (error) {
45
+ this.isInitialized = false;
46
+ throw new Error(`Failed to connect to MCP server at ${mcpEndpoint}. Ensure the path is correct and accessible within your n8n environment. Error: ${error.message}`);
47
+ }
39
48
  // Fetch available tools from MCP server
40
49
  const toolsResponse = await this.mcpClient.listTools();
41
50
  this.tools = toolsResponse.tools || [];
@@ -19,7 +19,7 @@ class SmartBrowserAutomation {
19
19
  },
20
20
  inputs: ['main'],
21
21
  outputs: ['main'],
22
- icon: 'fa:browser',
22
+ icon: 'file:smartBrowserAutomation.svg',
23
23
  credentials: [
24
24
  {
25
25
  name: 'smartBrowserAutomationApi',
@@ -103,11 +103,38 @@ class SmartBrowserAutomation {
103
103
  default: 'initialize',
104
104
  },
105
105
  {
106
- displayName: 'Verbose',
107
- name: 'verbose',
108
- type: 'boolean',
109
- default: false,
110
- description: 'Whether to enable detailed logging',
106
+ displayName: 'Options',
107
+ name: 'options',
108
+ type: 'collection',
109
+ placeholder: 'Add Option',
110
+ default: {},
111
+ options: [
112
+ {
113
+ displayName: 'CDP Endpoint',
114
+ name: 'cdpUrl',
115
+ type: 'string',
116
+ default: '',
117
+ placeholder: 'wss://...',
118
+ description: 'The CDP URL to connect to. Overrides the one in credentials if provided.',
119
+ },
120
+ {
121
+ displayName: 'Enabled Tool Names or IDs',
122
+ name: 'enabledTools',
123
+ type: 'multiOptions',
124
+ typeOptions: {
125
+ loadOptionsMethod: 'getAvailableTools',
126
+ },
127
+ default: [],
128
+ description: 'Select which tools to expose to the AI Agent or Manual list. Leave empty for all. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
129
+ },
130
+ {
131
+ displayName: 'Verbose',
132
+ name: 'verbose',
133
+ type: 'boolean',
134
+ default: false,
135
+ description: 'Whether to enable detailed logging',
136
+ },
137
+ ],
111
138
  },
112
139
  ],
113
140
  };
@@ -136,12 +163,36 @@ class SmartBrowserAutomation {
136
163
  // Expose tools to AI Agent nodes
137
164
  async getTools() {
138
165
  const credentials = await this.getCredentials('smartBrowserAutomationApi');
139
- const tools = await (0, DynamicBrowserTools_1.createDynamicBrowserTools)(credentials);
140
- // Ensure tools have the required structure for n8n AI node
141
- return tools.map(tool => ({
142
- ...tool,
143
- // n8n expects name, description and properties at the top level
144
- }));
166
+ const options = this.getNodeParameter('options', 0, {});
167
+ const enabledTools = options.enabledTools || [];
168
+ let tools = await (0, DynamicBrowserTools_1.createDynamicBrowserTools)(credentials);
169
+ // Filter tools if a selection was made
170
+ if (enabledTools.length > 0) {
171
+ tools = tools.filter(tool => enabledTools.includes(tool.name));
172
+ }
173
+ // Add a custom tool for the AI to connect to a specific CDP URL
174
+ const connectTool = {
175
+ name: 'browser_cdp_connect',
176
+ displayName: 'Connect to Browser (CDP)',
177
+ description: 'Connect to a specific browser instance using a CDP URL (wss://...)',
178
+ properties: [
179
+ {
180
+ displayName: 'Endpoint URL',
181
+ name: 'endpoint',
182
+ type: 'string',
183
+ default: '',
184
+ required: true,
185
+ description: 'The wss:// or http:// endpoint for the browser CDP connection',
186
+ },
187
+ ],
188
+ async execute(input) {
189
+ const sessionManager = BrowserSessionManager_1.default.getInstance();
190
+ const credentials = await this.getCredentials('smartBrowserAutomationApi');
191
+ await sessionManager.initialize(credentials.mcpEndpoint, true, input.endpoint);
192
+ return { success: true, message: `Connected to browser at ${input.endpoint}` };
193
+ }
194
+ };
195
+ return [connectTool, ...tools];
145
196
  }
146
197
  async execute() {
147
198
  const items = this.getInputData();
@@ -151,11 +202,12 @@ class SmartBrowserAutomation {
151
202
  const mode = this.getNodeParameter('mode', 0);
152
203
  for (let i = 0; i < items.length; i++) {
153
204
  try {
205
+ const options = this.getNodeParameter('options', i, {});
206
+ const verbose = options.verbose || false;
154
207
  if (mode === 'manual') {
155
208
  // Manual mode: User selects tool and provides arguments
156
209
  const toolName = this.getNodeParameter('toolName', i);
157
210
  const toolArgsStr = this.getNodeParameter('toolArgs', i);
158
- const verbose = this.getNodeParameter('verbose', i, false);
159
211
  // Initialize session if not ready
160
212
  if (!sessionManager.isReady()) {
161
213
  await sessionManager.initialize(credentials.mcpEndpoint, credentials.browserMode === 'cdp', credentials.cdpEndpoint);
@@ -165,10 +217,10 @@ class SmartBrowserAutomation {
165
217
  toolArgs = JSON.parse(toolArgsStr);
166
218
  }
167
219
  catch (error) {
168
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in Tool Arguments: ${error.message} `);
220
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Invalid JSON in Tool Arguments: ${error.message}`);
169
221
  }
170
222
  if (verbose) {
171
- console.log(`Executing tool: ${toolName} with args: `, toolArgs);
223
+ console.log(`Executing tool: ${toolName} with args:`, toolArgs);
172
224
  }
173
225
  const result = await sessionManager.callTool(toolName, toolArgs);
174
226
  returnData.push({
@@ -184,7 +236,9 @@ class SmartBrowserAutomation {
184
236
  // AI Agent mode: Just initialize or close
185
237
  const operation = this.getNodeParameter('operation', i);
186
238
  if (operation === 'initialize') {
187
- const tools = await sessionManager.initialize(credentials.mcpEndpoint, credentials.browserMode === 'cdp', credentials.cdpEndpoint);
239
+ const cdpUrl = options.cdpUrl || credentials.cdpEndpoint;
240
+ const tools = await sessionManager.initialize(credentials.mcpEndpoint, true, // Force CDP if using initialize in AI mode
241
+ cdpUrl);
188
242
  returnData.push({
189
243
  json: {
190
244
  success: true,
@@ -0,0 +1,11 @@
1
+ <svg width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect x="4" y="10" width="56" height="44" rx="4" fill="#6366F1"/>
3
+ <rect x="4" y="10" width="56" height="10" rx="4" fill="#4F46E5"/>
4
+ <circle cx="10" cy="15" r="2" fill="#F87171"/>
5
+ <circle cx="16" cy="15" r="2" fill="#FBBF24"/>
6
+ <circle cx="22" cy="15" r="2" fill="#34D399"/>
7
+ <path d="M32 28C38.6274 28 44 33.3726 44 40C44 46.6274 38.6274 52 32 52C25.3726 52 20 46.6274 20 40C20 33.3726 25.3726 28 32 28Z" fill="white" fill-opacity="0.2"/>
8
+ <path d="M32 32C36.4183 32 40 35.5817 40 40C40 44.4183 36.4183 48 32 48C27.5817 48 24 44.4183 24 40C24 35.5817 27.5817 32 32 32Z" fill="white"/>
9
+ <path d="M32 37L35 40L32 43" stroke="#4F46E5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
10
+ <path d="M29 37L32 40L29 43" stroke="#4F46E5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" transform="rotate(180 30.5 40) translate(-3 0)"/>
11
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.0.2",
3
+ "version": "1.0.6",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",