Skip to content

fix(agent-tars): browser-use mcp need MacOS accessibility #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ jobs:
if: matrix.os == 'macos-latest'
run: npm install -g appdmg
- name: Install dependencies
run: npm exec turbo run bootstrap
run: pnpm install
- name: Run e2e
run: npm exec turbo run ui-tars-desktop#test:e2e
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: npm exec turbo run bootstrap
run: pnpm install
- name: Run typecheck
run: npm exec turbo run typecheck
- name: Run test
Expand Down
8 changes: 7 additions & 1 deletion apps/agent-tars/docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ This guide will walk you through the process of setting up your first Agent TARS

Before you begin, you will need to set some necessary configuration.

Enable the Accessibility permission of **Agent TARS** in MacOS:
- System Settings -> Privacy & Security -> **Accessibility**

![accessibility-permission.png](https://github.com/user-attachments/assets/77e171d2-dffb-4905-98c0-92c5ab00e333)


You can click the left-bottom button to open the configuration page:

![setting-icon.png](https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/agent-tars/setting-icon.jpeg)
Expand Down Expand Up @@ -38,7 +44,7 @@ We also support **Human In the Loop**, that means you can interact with the agen

![human-in-the-loop.jpeg](https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/agent-tars/human-in-the-loop.jpeg)

## Share Your Thread
## Share Your Thead

You can share your thread with others by the share button on the top menu.

Expand Down
6 changes: 5 additions & 1 deletion apps/agent-tars/forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const keepModules = new Set([
'@mixmark-io/domino',
'@modelcontextprotocol/sdk',
]);
const needSubDependencies = ['@tavily/core', '@modelcontextprotocol/sdk'];
const needSubDependencies = [
'@tavily/core',
'@modelcontextprotocol/sdk',
'@computer-use/node-mac-permissions',
];
const keepLanguages = new Set(['en', 'en_GB', 'en-US', 'en_US']);
const ignorePattern = new RegExp(
`^/node_modules/(?!${[...keepModules].join('|')})`,
Expand Down
1 change: 1 addition & 0 deletions apps/agent-tars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"@tavily/core": "0.3.1",
"@computer-use/node-mac-permissions": "2.2.2",
"@agent-infra/mcp-server-commands": "workspace:*",
"@agent-infra/mcp-server-filesystem": "workspace:*",
"@agent-infra/mcp-server-browser": "workspace:*"
Expand Down
17 changes: 16 additions & 1 deletion apps/agent-tars/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,23 @@ function createWindow(): void {
}
}

const initializeApp = async () => {
if (process.platform === 'darwin') {
app.setAccessibilitySupportEnabled(true);
const { ensurePermissions } = await import('@main/utils/systemPermissions');

const ensureScreenCapturePermission = ensurePermissions();
console.info(
'ensureScreenCapturePermission',
ensureScreenCapturePermission,
);
}
};

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
app.whenReady().then(async () => {
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron');

Expand All @@ -77,6 +90,8 @@ app.whenReady().then(() => {
optimizer.watchWindowShortcuts(window);
});

await initializeApp();

// IPC test
ipcMain.on('ping', () => console.log('pong'));
registerIpcMain(ipcRoutes);
Expand Down
52 changes: 52 additions & 0 deletions apps/agent-tars/src/main/utils/systemPermissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
import permissions from '@computer-use/node-mac-permissions';

let hasAccessibilityPermission = false;

const wrapWithWarning =
(message, nativeFunction) =>
(...args) => {
console.warn(message);
return nativeFunction(...args);
};

const askForAccessibility = (nativeFunction, functionName) => {
const accessibilityStatus = permissions.getAuthStatus('accessibility');
console.info('[accessibilityStatus]', accessibilityStatus);

if (accessibilityStatus === 'authorized') {
hasAccessibilityPermission = true;
return nativeFunction;
} else if (
accessibilityStatus === 'not determined' ||
accessibilityStatus === 'denied'
) {
hasAccessibilityPermission = false;
permissions.askForAccessibilityAccess();
return wrapWithWarning(
`##### WARNING! The application running this script tries to access accessibility features to execute ${functionName}! Please grant requested access for further information. #####`,
nativeFunction,
);
}
};

export const ensurePermissions = (): {
accessibility: boolean;
} => {
if (process.env.CI === 'e2e') {
return {
accessibility: true,
};
}

askForAccessibility(() => {}, 'execute accessibility');

console.info('hasAccessibilityPermission', hasAccessibilityPermission);

return {
accessibility: hasAccessibilityPermission,
};
};
2 changes: 1 addition & 1 deletion apps/ui-tars/src/main/utils/systemPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const askForScreenRecording = (nativeFunction, functionName) => {
hasScreenRecordingPermission = false;
permissions.askForScreenCaptureAccess();
return wrapWithWarning(
`##### WARNING! The application running this script tries to screen recording features to execute ${functionName}! Please grant the requested access and visit https://github.com/nut-tree/nut.js#macos for further information. #####`,
`##### WARNING! The application running this script tries to screen recording features to execute ${functionName}! Please grant the requested access for further information. #####`,
nativeFunction,
);
}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.