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 2 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
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 and visit https://github.com/nut-tree/nut.js#macos 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,
};
};
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.

Loading