n8n-nodes-smart-browser-automation 1.6.14 → 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 =
|
|
67
|
-
|
|
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(
|
|
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(
|
|
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 ${
|
|
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 ${
|
|
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 };
|