Workflow scripting: Node tasks and browser identity
For people who write or edit Workflow files. Run Node code and npm packages with ctx.node.run, and open pages in an incognito tab or a chosen browser profile.
Coming in the next version
Both features on this page arrive in the next release. They aren't available in the current version yet.
For most people, having your Agent write the Workflow is enough. See Let a Workflow run your routine jobs. This page is for anyone who wants to read or edit a .workflow.js file themselves. You can also hand this page to your Agent and have it follow along.
Run Node tasks in a Workflow
Some things are beyond the built-in ctx.http and ctx.files, like reading a verification email over IMAP or parsing a file with an npm package. For those, write a Node task in the same .workflow.js and call it with ctx.node.run.
export const meta = {
name: 'Read verification code',
description: 'Read the latest verification code over IMAP.',
capabilities: { node: { allowed: true, dependencies: { imapflow: '2.12.2' } } },
};
export const nodeTasks = {
async readCode(request) {
const { ImapFlow } = await import('imapflow'); // only import dynamically inside a task
// ...regular Node code; built-ins like net, tls and fs work
return { status: 'matched', code: '123456' };
},
};
export default async function run(ctx) {
const reply = await ctx.node.run({ task: 'readCode', input: { accountFile: ctx.input.accountFile } });
return { status: reply.status };
}Things to know:
- Declare it first: set
meta.capabilities.node.allowedtotrue. List npm packages underdependencieswith exact versions, like2.12.2, not^2.12.0. - The first run needs internet: Floatboat installs the packages for you and caches them after that. Only pure-JavaScript packages work, and their install scripts never run.
- Same power as Bash: Node tasks run in a separate process on your computer and can do as much as
ctx.bash. The working folder is the system temp folder, so use full paths for files. You can't usectx.*inside a task. - Everything in and out is JSON: the return value goes only to your Workflow code. Run history records the task name, input keys and timing, not the return value, so it's a fine place for short-lived secrets like a verification code. Still, don't print passwords to the console or put them in Workflow input, since input goes into the run history.
- Test Run doesn't really run it: during a Test Run,
ctx.node.runreturns{ dryRun: true, skipped: true, task }. - Error codes:
NODE_TASK_NOT_FOUND(wrong task name),NODE_TASK_TIMEOUT,NODE_TASK_CANCELLED(the run was canceled), andNODE_DEPENDENCY_INSTALL_FAILED(usually a network problem, or a package that isn't pure JS). Errors your task throws with acodecome back unchanged.
Use an incognito tab or a chosen browser profile
By default, a Workflow opens pages with this space's browser profile and sign-ins. Now you can also pass options to openUrl:
- Incognito: pass
incognito: true. Each run gets its own incognito space with no sign-ins, closed and wiped when the run ends. Good for checking what a signed-out visitor sees. - A chosen profile: pass
profile: 'profile name'to use a profile you set up in browser settings, like the one signed in to your work account. Your Agent can use the same profiles.
Declare them first in the Workflow manifest: browser.incognito: true for incognito, and the profile names under browser.profiles. Using them without declaring them is an error. New windows opened from an incognito tab are incognito too.