Appearance
Javascript代码
在浏览器中执行自定义 JavaScript 代码。
超时
设置 JavaScript 代码执行的超时时间,默认为 20000ms(20 秒)。超时后工作流将继续执行后续组件。
执行每个新标签页
每次 MakAgent 新建或切换标签页时都会执行 JavaScript 代码。
注意事项:
- 启用此选项后,JavaScript 代码块不再需要活动标签页即可工作
- 内置函数(如
automaRefData、automaNextBlock等)将不可用

执行上下文
JavaScript 代码
你可以在代码中调用几个内置函数。
automaNextBlock(data, insert?)
js
automaNextBlock(
data?: Object | Object[],
insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;automaNextBlock(
data?: Object | Object[],
insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;告诉工作流继续执行下一个块。
使用 data 数将数据插入表中。此参数可以采用对象或对象数组数据类型。并且对象的键必须在表中表中定义。
参数 insert 用于控制是否将 data 参数中的数据插入到表中,默认为 true。或者,你可以传递一个包含两个可选属性的对象:
insert: 是否向表中插入数据。nextBlockId: 指定要导航到的下一个块的 ID 的字符串。replaceTable: 用第一个参数传递的值替换工作流表值。 例子
js
automaNextBlock({ title: 'Something', count: 200 });
//or
automaNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])
// Continue execution to a specific block
automaNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })automaNextBlock({ title: 'Something', count: 200 });
//or
automaNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])
// Continue execution to a specific block
automaNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })
agentSetVariable(name, value)
设置工作流变量的值。
例子
js
agentSetVariable('name', 'John Doe');
agentSetVariable('prices', [200, 1000, 4000, 900, 200]);
agentSetVariable('profile', { firstName: 'John', lastName: 'Doe' });agentSetVariable('name', 'John Doe');
agentSetVariable('prices', [200, 1000, 4000, 900, 200]);
agentSetVariable('profile', { firstName: 'John', lastName: 'Doe' });automaRefData(keyword, path)
使用此功能可以访问工作流数据,如表、变量等。
阅读更多: 表达式
例子
js
// Get the first row of the table
const firstRow = automaRefData('table', '0');
// Get the last row of the table
const firstRow = automaRefData('table', '$last');
// Get the "name" column on the first row of the table
const firstRow = automaRefData('table', '0.name');
// Get the global data of the workflow
const globalData = automaRefData('globalData');
// Get the iteration data of the loop data block
const data = automaRefData('loopData', 'loopId');
// Get the value of the "text" variable
const value = automaRefData('variables', 'text');// Get the first row of the table
const firstRow = automaRefData('table', '0');
// Get the last row of the table
const firstRow = automaRefData('table', '$last');
// Get the "name" column on the first row of the table
const firstRow = automaRefData('table', '0.name');
// Get the global data of the workflow
const globalData = automaRefData('globalData');
// Get the iteration data of the loop data block
const data = automaRefData('loopData', 'loopId');
// Get the value of the "text" variable
const value = automaRefData('variables', 'text');agentFetch(type, resource)
在扩展后台发起HTTP请求,用它来避免CORS。
type: 请求的响应类型。可能的值text&json;resource: 你希望获取的资源。
例子
js
agentFetch('json', { url: 'https://api.example.com'}).then((result) => {
console.log(result);
})
agentFetch('json', {
url: 'https://api.example.com',
method: 'POST',
body: JSON.stringify({
title: 'Hello world',
}),
})agentFetch('json', { url: 'https://api.example.com'}).then((result) => {
console.log(result);
})
agentFetch('json', {
url: 'https://api.example.com',
method: 'POST',
body: JSON.stringify({
title: 'Hello world',
}),
})agentResetTimeout()
重置执行超时。
预加载脚本
在执行 javascript 代码之前加载一个 javascript 文件。
- URL
javascript 文件的 URL。
MakAgent在线文档