n8n-nodes-nvk-browser 1.0.9 → 1.0.10

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.
@@ -51,7 +51,7 @@ exports.runJavaScriptFields = [
51
51
  },
52
52
  required: true,
53
53
  default: '',
54
- description: 'JavaScript code to execute',
54
+ description: 'JavaScript code to execute. If code uses Puppeteer API (page.goto, page.click, etc.), it will run in Node.js context with page object available. Otherwise, it runs in browser context.',
55
55
  displayOptions: {
56
56
  show: {
57
57
  resource: ['page'],
@@ -105,8 +105,38 @@ class RunJavaScript {
105
105
  if (!page) {
106
106
  throw new Error(`Could not get page for profile ${profileId}`);
107
107
  }
108
- // Execute JavaScript
109
- const result = await page.evaluate(javascriptCode);
108
+ // Check if code uses Puppeteer API (page.goto, page.click, etc.)
109
+ // If it does, execute in Node.js context, otherwise execute in browser context
110
+ const usesPuppeteerAPI = /page\.(goto|click|fill|waitFor|evaluate|setViewport|keyboard|mouse|locator|waitForSelector|waitForTimeout)/.test(javascriptCode) ||
111
+ /await\s+page\./.test(javascriptCode) ||
112
+ /puppeteer\./.test(javascriptCode);
113
+ let result;
114
+ if (usesPuppeteerAPI) {
115
+ // Execute in Node.js context with page exposed
116
+ // Check if code is already wrapped in async IIFE or function
117
+ const isWrapped = /^\s*\(?\s*async\s*\([^)]*\)\s*=>/.test(javascriptCode.trim()) ||
118
+ /^\s*\(?\s*async\s*function/.test(javascriptCode.trim());
119
+ if (isWrapped) {
120
+ // Code is already wrapped, just execute it with page in scope
121
+ const asyncFunction = new Function('page', `
122
+ return ${javascriptCode};
123
+ `);
124
+ result = await asyncFunction(page);
125
+ }
126
+ else {
127
+ // Wrap code in async function
128
+ const asyncFunction = new Function('page', `
129
+ return (async () => {
130
+ ${javascriptCode}
131
+ })();
132
+ `);
133
+ result = await asyncFunction(page);
134
+ }
135
+ }
136
+ else {
137
+ // Execute in browser context (original behavior)
138
+ result = await page.evaluate(javascriptCode);
139
+ }
110
140
  returnData.push({
111
141
  json: {
112
142
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-nvk-browser",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "n8n nodes for managing Chrome browser profiles and page interactions",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",