n8n-nodes-smart-browser-automation 1.5.1 → 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.
@@ -36,12 +36,14 @@ 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: 'Tool Name',
39
+ displayName: 'Tool Name or ID',
40
40
  name: 'toolName',
41
- type: 'string',
42
- required: true,
41
+ type: 'options',
42
+ typeOptions: {
43
+ loadOptionsMethod: 'getAvailableTools',
44
+ },
43
45
  default: 'browser_navigate',
44
- description: 'Name of the browser tool to execute (e.g., browser_navigate, browser_click, browser_type, browser_snapshot)',
46
+ description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
45
47
  },
46
48
  {
47
49
  displayName: 'Tool Parameters',
@@ -76,12 +78,26 @@ class SmartBrowserAutomation {
76
78
  },
77
79
  };
78
80
  async execute() {
81
+ const items = this.getInputData();
79
82
  const returnData = [];
80
83
  const credentials = await this.getCredentials('smartBrowserAutomationApi');
81
84
  const sessionManager = BrowserSessionManager_1.default.getInstance();
82
85
  // Get CDP override or use from credentials
83
86
  const cdpOverride = this.getNodeParameter('cdpOverride', 0, '');
84
- const toolName = this.getNodeParameter('toolName', 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
+ }
85
101
  try {
86
102
  // Initialize session if not ready
87
103
  if (!sessionManager.isReady()) {
@@ -91,28 +107,34 @@ class SmartBrowserAutomation {
91
107
  // Handle tool execution
92
108
  let toolParams;
93
109
  try {
94
- const rawParams = this.getNodeParameter('toolParameters', 0);
95
- if (rawParams === undefined || rawParams === null) {
96
- toolParams = {};
110
+ // First check if AI Agent sent Tool_Parameters in input
111
+ if (aiToolParams && typeof aiToolParams === 'object') {
112
+ toolParams = aiToolParams;
97
113
  }
98
- else if (typeof rawParams === 'string') {
99
- 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) {
100
118
  toolParams = {};
101
119
  }
102
- else {
103
- 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
+ }
104
127
  }
105
- }
106
- else if (typeof rawParams === 'object') {
107
- // Handle object input (when used as a tool in AI Agent)
108
- toolParams = rawParams;
109
- }
110
- else {
111
- try {
112
- toolParams = JSON.parse(JSON.stringify(rawParams));
128
+ else if (typeof rawParams === 'object') {
129
+ toolParams = rawParams;
113
130
  }
114
- catch (parseError) {
115
- 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
+ }
116
138
  }
117
139
  }
118
140
  // Ensure toolParams is an object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-smart-browser-automation",
3
- "version": "1.5.1",
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",