n8n-nodes-smart-browser-automation 1.6.13 → 1.6.15

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.
@@ -49,6 +49,25 @@ class BrowserSessionManager {
49
49
  return BrowserSessionManager.instance;
50
50
  }
51
51
  async initialize(mcpEndpoint, useCDP, cdpEndpoint) {
52
+ // Validate endpoint inputs early to avoid confusing runtime errors
53
+ const trimmedMcpEndpoint = String(mcpEndpoint ?? '').trim();
54
+ if (!trimmedMcpEndpoint) {
55
+ throw new Error('MCP Endpoint is required');
56
+ }
57
+ if (/^wss?:\/\//i.test(trimmedMcpEndpoint)) {
58
+ throw new Error(`Invalid MCP Endpoint: "${trimmedMcpEndpoint}". ` +
59
+ 'MCP Endpoint must be an http(s) URL (for SSE or Streamable HTTP). ' +
60
+ 'If you are using a browser CDP connection, put the ws(s) URL in the CDP Endpoint field instead.');
61
+ }
62
+ if (useCDP) {
63
+ const trimmedCdp = String(cdpEndpoint ?? '').trim();
64
+ if (!trimmedCdp) {
65
+ throw new Error('CDP endpoint is required when Browser Mode is CDP Connection');
66
+ }
67
+ if (!/^wss?:\/\//i.test(trimmedCdp)) {
68
+ throw new Error(`Invalid CDP Endpoint: "${trimmedCdp}". CDP Endpoint must be a ws(s) URL (e.g. ws://localhost:9222 or wss://.../devtools/...).`);
69
+ }
70
+ }
52
71
  // Only initialize if not already done or config changed
53
72
  if (this.isInitialized &&
54
73
  this.config.mcpEndpoint === mcpEndpoint &&
@@ -63,18 +82,26 @@ class BrowserSessionManager {
63
82
  // Initialize MCP client
64
83
  this.mcpClient = new index_js_1.Client({ name: 'n8n-browser-automation', version: '1.0.0' }, { capabilities: {} });
65
84
  // Determine transport based on endpoint type
66
- const isUrl = mcpEndpoint.startsWith('http://') || mcpEndpoint.startsWith('https://');
67
- const urlIsSse = isUrl && /(^|\/)sse\/?(\?|#|$)/i.test(new URL(mcpEndpoint).pathname);
85
+ const isUrl = trimmedMcpEndpoint.startsWith('http://') || trimmedMcpEndpoint.startsWith('https://');
86
+ let urlIsSse = false;
87
+ if (isUrl) {
88
+ try {
89
+ urlIsSse = /(^|\/)sse\/?(\?|#|$)/i.test(new URL(trimmedMcpEndpoint).pathname);
90
+ }
91
+ catch (e) {
92
+ throw new Error(`Invalid MCP Endpoint: "${trimmedMcpEndpoint}". MCP Endpoint must be a valid http(s) URL (or a local file path for stdio).`);
93
+ }
94
+ }
68
95
  if (isUrl) {
69
96
  if (urlIsSse) {
70
97
  // Connect via SSE
71
98
  const { SSEClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/sse.js')));
72
- this.transport = new SSEClientTransport(new URL(mcpEndpoint));
99
+ this.transport = new SSEClientTransport(new URL(trimmedMcpEndpoint));
73
100
  }
74
101
  else {
75
102
  // Connect via Streamable HTTP
76
103
  const { StreamableHTTPClientTransport } = await Promise.resolve().then(() => __importStar(require('@modelcontextprotocol/sdk/client/streamableHttp.js')));
77
- this.transport = new StreamableHTTPClientTransport(new URL(mcpEndpoint));
104
+ this.transport = new StreamableHTTPClientTransport(new URL(trimmedMcpEndpoint));
78
105
  }
79
106
  }
80
107
  else {
@@ -95,7 +122,7 @@ class BrowserSessionManager {
95
122
  // Remote servers often need a moment to register the session before accepting POST calls
96
123
  if (isUrl) {
97
124
  if (process.env.NODE_ENV !== 'production') {
98
- console.log(`[MCP] Connected to ${mcpEndpoint}. Waiting for session stabilization...`);
125
+ console.log(`[MCP] Connected to ${trimmedMcpEndpoint}. Waiting for session stabilization...`);
99
126
  }
100
127
  await new Promise(resolve => setTimeout(resolve, 2000));
101
128
  }
@@ -103,7 +130,7 @@ class BrowserSessionManager {
103
130
  catch (error) {
104
131
  this.isInitialized = false;
105
132
  const transportType = isUrl ? (urlIsSse ? 'SSE' : 'Streamable HTTP') : 'Stdio';
106
- throw new Error(`Failed to connect to MCP server via ${transportType} at ${mcpEndpoint}. Error: ${error.message}`);
133
+ throw new Error(`Failed to connect to MCP server via ${transportType} at ${trimmedMcpEndpoint}. Error: ${error.message}`);
107
134
  }
108
135
  this.isInitialized = true;
109
136
  this.config = { mcpEndpoint, useCDP, cdpEndpoint };
@@ -52,13 +52,8 @@ async function importDynamicStructuredTool() {
52
52
  }
53
53
  }
54
54
  async function importToolkitBase() {
55
- try {
56
- return await Promise.resolve().then(() => __importStar(require('langchain/agents')));
57
- }
58
- catch {
59
- // Fallback: older/newer builds might export Toolkit elsewhere; keep as a last resort.
60
- return await Promise.resolve().then(() => __importStar(require('langchain/agents')));
61
- }
55
+ // n8n uses Toolkit from @langchain/classic/agents internally.
56
+ return await Promise.resolve().then(() => __importStar(require('@langchain/classic/agents')));
62
57
  }
63
58
  class SmartBrowserAutomationTools {
64
59
  description = {
@@ -70,8 +65,9 @@ class SmartBrowserAutomationTools {
70
65
  defaults: {
71
66
  name: 'Browser Automation Tools',
72
67
  },
73
- inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
74
- outputs: [{ type: n8n_workflow_1.NodeConnectionTypes.AiTool, displayName: 'Tools' }],
68
+ inputs: [],
69
+ outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
70
+ outputNames: ['Tools'],
75
71
  icon: 'file:smartBrowserAutomation.svg',
76
72
  credentials: [
77
73
  {
@@ -124,10 +120,13 @@ class SmartBrowserAutomationTools {
124
120
  });
125
121
  }));
126
122
  class SmartBrowserAutomationToolkit extends Toolkit {
127
- tools;
128
- constructor(tools) {
123
+ _tools;
124
+ constructor(_tools) {
129
125
  super();
130
- this.tools = tools;
126
+ this._tools = _tools;
127
+ }
128
+ getTools() {
129
+ return this._tools;
131
130
  }
132
131
  }
133
132
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.6.13",
3
+ "version": "1.6.15",
4
4
  "description": "n8n node for AI-driven browser automation using MCP",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",