Skip to content

Commit

Permalink
update custom body
Browse files Browse the repository at this point in the history
  • Loading branch information
minhlucvanncc committed Oct 1, 2024
1 parent 98da8e3 commit 2765219
Show file tree
Hide file tree
Showing 4 changed files with 2,682 additions and 89 deletions.
176 changes: 147 additions & 29 deletions nodes.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const path = require('path');

module.exports = {
packageName: 'n8n-nodes-browserless',
credentials: {
browserlessApi: {
displayName: 'Browserless API',
name: 'browserlessApi',
className: 'BrowserlessApi',
},
},
credentials: {
browserlessApi: {
displayName: 'Browserless API',
name: 'browserlessApi',
className: 'BrowserlessApi',
},
},
nodes: {
browserless: {
displayName: 'Browserless',
Expand All @@ -20,40 +20,158 @@ module.exports = {
baseUrl: '=\{\{$credentials.url\}\}',
targetDir: path.resolve(__dirname, 'nodes/Browserless/v2'),
version: 2,
tags: ['Browser REST APIs'],
operations: [{
summary: '/chrome/scrape',
}],
tags: ['Browser REST APIs'],
operations: [
{
summary: '/chrome/scrape',
}
],
credentials: [{
displayName: 'Browserless API',
name: 'browserlessApi',
required: true,
}],
propertiesOrder: [
"operation",
"url",
"timeout",
"userAgent",
"viewport",
"emulateMediaType",
"setJavaScriptEnabled",
"setExtraHTTPHeaders",
"cookies",
"authenticate",
"gotoOptions",
"blockAds",
"rejectRequestPattern",
"rejectResourceTypes",
"requestInterceptors",
"waitForSelector",
"waitForTimeout",
"waitForFunction",
"waitForEvent",
"html",
"elements",
"addScriptTag",
"addStyleTag",
"bestAttempt",
"launch",
"debugOpts"
],
},
},
overwrites: {
operations: [
// remove all token
{
match: {
name: 'token',
},
set: false,
}
],
// remove all token
{
match: {
name: 'token',
},
set: false,
},
{
match: {
name: 'launch',
},
add: {
method: 'additional',
field: {
name: 'enableLaunch',
displayName: 'Enable Launch',
type: 'boolean',
default: false,
description: 'Launch a new browser instance',
}
}
},
{
match: {
name: 'setExtraHTTPHeaders'
},
set: {
type: 'fixedCollection',
placeholder: 'Add Header',
default: {},
typeOptions: {
multipleValues: true,
},
description: 'Set extra HTTP headers',
routing: {
request: {
body: {
setExtraHTTPHeaders: '={{$value.headers}}',
},
},
},
options: [
{
displayName: 'Set Extra HTTP Headers',
name: 'headers',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the header',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the header',
},
],
}
],
}
},
{
match: {
name: 'cookies'
},
set: (field) => ({
...field,
type: 'json',
default: '[]',
description: 'Array of cookie objects expected by cookie-editor extension',
typeOptions: {},
options: [],
routing: {
request: {
body: {
cookies: '={{ (JSON.parse($value) || []).reduce((a, c) => ({ ...a, [c.name]: c.value }), {}) }}',
},
},
},
}),
add: {
method: 'additional',
field: {
name: 'enableCookies',
displayName: 'Enable Cookies',
type: 'boolean',
default: false,
description: 'Enable cookies',
}
}
}
],
},
deleteFolders: [''],
normalizeFn: (s) => {
// /a /b => /b
// /abc /def => /def
const slugs = s.split(' ');
// only if both slugs are single words and start with a slash
if (slugs.every(slug => slug.startsWith('/'))) {
return slugs[slugs.length - 1];
}
normalizeFn: (s) => {
// /a /b => /b
// /abc /def => /def
const slugs = s.split(' ');
// only if both slugs are single words and start with a slash
if (slugs.every(slug => slug.startsWith('/'))) {
return slugs[slugs.length - 1];
}

return s;
},
return s;
},
normalizeActionFn: (_, opName) => {
// /a /b => /b
return opName;
Expand Down
Loading

0 comments on commit 2765219

Please sign in to comment.