@seekskyworld/open-browser 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +2 -0
- package/Docs/desktop-packages.md +45 -0
- package/Docs/open-browser-api.d.ts +13 -9
- package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +6 -6
- package/README.md +11 -9
- package/README.zh-CN.md +6 -4
- package/access-registry.mjs +8 -3
- package/action-execution.mjs +30 -5
- package/api-contract.mjs +8 -7
- package/browser-extension/_locales/en/messages.json +8 -0
- package/browser-extension/_locales/zh_CN/messages.json +8 -0
- package/browser-extension/i18n.js +84 -0
- package/browser-extension/manifest.json +5 -4
- package/browser-extension/messages.js +266 -0
- package/browser-extension/newtab.css +4 -0
- package/browser-extension/newtab.html +9 -9
- package/browser-extension/newtab.js +38 -35
- package/browser-extension/page-locale.js +23 -0
- package/browser-extension/phase-labels.js +33 -6
- package/browser-extension/popup.css +2 -2
- package/browser-extension/popup.html +25 -25
- package/browser-extension/popup.js +102 -59
- package/browser-extension/tab-action.js +31 -25
- package/browser-extension/worker.js +31 -7
- package/browser-extension/workspace-title.js +2 -2
- package/build-profile.mjs +10 -2
- package/capability-matrix.mjs +1 -1
- package/chromium-host.mjs +26 -19
- package/chromium-shell.mjs +7 -5
- package/cli.mjs +51 -48
- package/contract-validation.mjs +1 -1
- package/control.mjs +9 -8
- package/desktop/Info.plist +4 -2
- package/desktop/Launcher.m +10 -2
- package/desktop/OBControlBar.m +12 -8
- package/desktop/OBLocalization.h +20 -0
- package/desktop/OBPageView.m +2 -1
- package/desktop/WorkspacePanel.m +85 -83
- package/desktop/archive-release.py +5 -1
- package/desktop/build-macos.mjs +17 -8
- package/desktop/build-managed-input.mjs +2 -1
- package/desktop/build-portable.mjs +5 -3
- package/desktop/build-profile.mjs +2 -1
- package/desktop/build.mjs +2 -1
- package/desktop/create-shortcut.ps1 +7 -1
- package/desktop/en.lproj/Localizable.strings +106 -0
- package/desktop/install-menu-entry.mjs +2 -0
- package/desktop/notarize-macos.mjs +70 -29
- package/desktop/package-macos.mjs +4 -3
- package/desktop/sign.mjs +22 -6
- package/desktop/start-profile.mjs +2 -1
- package/desktop/start.mjs +3 -1
- package/desktop/verify-macos-release.mjs +27 -18
- package/desktop/verify-version.mjs +22 -2
- package/desktop/zh-Hans.lproj/Localizable.strings +106 -0
- package/engine-service.mjs +86 -27
- package/hosted/cli.mjs +2 -1
- package/hosted/init.mjs +2 -1
- package/i18n.mjs +41 -0
- package/managed-input.mjs +22 -5
- package/mcp-http.mjs +12 -11
- package/mcp-server.mjs +27 -10
- package/mcp.mjs +1 -0
- package/messages.zh-CN.mjs +175 -0
- package/package.json +9 -5
- package/page-activity.mjs +10 -7
- package/page-observation.mjs +4 -1
- package/paths.mjs +2 -5
- package/receipt-store.mjs +17 -7
- package/runtime.mjs +5 -4
- package/sdk.mjs +57 -46
- package/service.mjs +38 -21
- package/skill-links.mjs +72 -18
- package/skills/open-browser/SKILL.md +10 -97
- package/skills/open-browser/SKILL.zh-CN.md +22 -0
- package/skills/open-browser/references/macos.en.md +3 -0
- package/skills/open-browser/references/macos.md +5 -0
- package/skills/open-browser/references/operations.en.md +54 -0
- package/skills/open-browser/{SKILL.windows.md → references/operations.md} +8 -59
- package/skills/open-browser/references/recovery.en.md +36 -0
- package/skills/open-browser/references/recovery.md +38 -0
- package/skills/open-browser/references/windows.en.md +3 -0
- package/skills/open-browser/references/windows.md +5 -0
- package/skills/open-browser/scripts/bootstrap.mjs +80 -90
- package/skills/open-browser/scripts/guide.mjs +20 -0
- package/skills/open-browser/scripts/open-browser +5 -1
- package/studio/demo-site.mjs +5 -4
- package/studio/index.html +37 -33
- package/studio/index.mjs +10 -3
- package/studio/native-demo.mjs +8 -7
- package/studio/studio.css +3 -0
- package/studio/studio.js +99 -69
- package/system-i18n.mjs +19 -0
- package/tab-adoption.mjs +9 -3
- package/tab-recovery.mjs +100 -0
- package/visual-page.mjs +17 -7
- package/workspace-lifecycle.mjs +18 -2
- package/workspace-state.mjs +57 -16
- package/skills/open-browser/SKILL.macos.md +0 -112
package/build-profile.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { systemMessage as t } from './system-i18n.mjs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
1
3
|
import path from 'node:path';
|
|
2
4
|
import { readFileSync } from 'node:fs';
|
|
3
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -12,12 +14,18 @@ function packagedProfile() {
|
|
|
12
14
|
export const buildProfile = (process.env.OPEN_BROWSER_BUILD_PROFILE || packagedProfile() || 'stable').trim().toLowerCase();
|
|
13
15
|
|
|
14
16
|
if (!allowedProfiles.has(buildProfile)) {
|
|
15
|
-
throw new Error('OPEN_BROWSER_BUILD_PROFILE must be dev or stable');
|
|
17
|
+
throw new Error(t('OPEN_BROWSER_BUILD_PROFILE must be dev or stable'));
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export const isDevelopmentBuild = buildProfile === 'dev';
|
|
19
21
|
|
|
20
22
|
export function scopedBuildRoot(base, profile = buildProfile) {
|
|
21
|
-
if (!allowedProfiles.has(profile)) throw new Error('build profile must be dev or stable');
|
|
23
|
+
if (!allowedProfiles.has(profile)) throw new Error(t('build profile must be dev or stable'));
|
|
22
24
|
return profile === 'dev' ? path.join(base, 'dev') : base;
|
|
23
25
|
}
|
|
26
|
+
|
|
27
|
+
export function profileStateDirectory(id = process.env.OPEN_BROWSER_PROFILE || 'default') {
|
|
28
|
+
if (typeof id !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,47}$/.test(id)) throw new Error('invalid_profile');
|
|
29
|
+
const base = scopedBuildRoot(path.resolve(process.env.OPEN_BROWSER_STATE_DIR || path.join(homedir(), '.open-browser')));
|
|
30
|
+
return id === 'default' ? base : path.join(base, 'profiles', id);
|
|
31
|
+
}
|
package/capability-matrix.mjs
CHANGED
|
@@ -9,7 +9,7 @@ export const readCapabilities = Object.freeze([
|
|
|
9
9
|
|
|
10
10
|
export const desktopCapabilities = Object.freeze([
|
|
11
11
|
'offerCurrentTab', 'listUploads', 'grantUpload', 'revokeUpload', 'respondDialog',
|
|
12
|
-
'listDownloads', 'cancelDownload', 'keepDownload', 'visualStatus',
|
|
12
|
+
'listDownloads', 'cancelDownload', 'keepDownload', 'visualStatus','setPagePixelPermission',
|
|
13
13
|
'diagnoseOperation', 'listWorkspaces', 'getWorkspace', 'takeControl',
|
|
14
14
|
'returnToAgent', 'resolveCredential', 'grantOrigin', 'finishWorkspace',
|
|
15
15
|
'listOperations', 'listEvents', 'eventCursor', 'listAgentHistory', 'closeWorkspace', 'showPage',
|
package/chromium-host.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { interfaceLanguage, locale, setInterfaceLanguage, t } from './i18n.mjs';
|
|
1
2
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
3
|
import { randomUUID } from 'node:crypto';
|
|
3
4
|
|
|
4
5
|
import { managedInput } from './managed-input.mjs';
|
|
5
6
|
import { pageActivity } from './page-activity.mjs';
|
|
6
7
|
import { desktopCapabilities } from './capability-matrix.mjs';
|
|
8
|
+
import { extensionWorkspace } from './workspace-state.mjs';
|
|
7
9
|
|
|
8
10
|
export const extensionId = 'ehmdmliolflappfnmopemgojhbiilmpl';
|
|
9
11
|
const workerUrl = 'chrome-extension://' + extensionId + '/worker.js';
|
|
@@ -12,8 +14,8 @@ const WORKER_EVAL_TIMEOUT_MS = 5000;
|
|
|
12
14
|
|
|
13
15
|
export function classifyExtensionFailure({ dispatched = false } = {}) {
|
|
14
16
|
return dispatched
|
|
15
|
-
? { code: 'host_timeout', message:
|
|
16
|
-
: { code: 'host_unavailable', message:
|
|
17
|
+
? { code: 'host_timeout', message: t("The extension received the request but the local service timed out. Check the service and try again.") }
|
|
18
|
+
: { code: 'host_unavailable', message: t("The extension is disconnected from the local service. Start Open Browser and try again.") };
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
function extensionError(code, message, cause) {
|
|
@@ -28,7 +30,7 @@ async function evaluateWorker(host, pageFunction, arg) {
|
|
|
28
30
|
new Promise((_, reject) => {
|
|
29
31
|
timer = setTimeout(() => reject(extensionError(
|
|
30
32
|
'extension_worker_timeout',
|
|
31
|
-
|
|
33
|
+
t("The extension service worker timed out. Check the extension and try again."),
|
|
32
34
|
)), WORKER_EVAL_TIMEOUT_MS);
|
|
33
35
|
}),
|
|
34
36
|
]);
|
|
@@ -47,12 +49,12 @@ export async function chromiumHost(context) {
|
|
|
47
49
|
try {
|
|
48
50
|
return await context.waitForEvent('serviceworker', { predicate: isHost, timeout: 10000 });
|
|
49
51
|
} catch (cause) {
|
|
50
|
-
throw extensionError('extension_unavailable',
|
|
52
|
+
throw extensionError('extension_unavailable', t("The workspace extension is offline. Restart Open Browser or reload the extension."), cause);
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
55
|
let initial = await worker();
|
|
54
56
|
const currentVersion = host => evaluateWorker(host, () => globalThis.openBrowserGroupVersion);
|
|
55
|
-
if (await currentVersion(initial) !==
|
|
57
|
+
if (await currentVersion(initial) !== 16) {
|
|
56
58
|
// A persistent Chromium profile can start the previous cached MV3 worker.
|
|
57
59
|
const replacement = context.waitForEvent('serviceworker', { predicate: isHost, timeout: 10000 });
|
|
58
60
|
try {
|
|
@@ -61,10 +63,12 @@ export async function chromiumHost(context) {
|
|
|
61
63
|
})]);
|
|
62
64
|
} catch (cause) {
|
|
63
65
|
// Chromium can defer the replacement worker until its next profile launch.
|
|
64
|
-
throw Object.assign(new Error(
|
|
66
|
+
throw Object.assign(new Error(t("The workspace extension requested an update."), { cause }), { code: 'extension_reload' });
|
|
65
67
|
}
|
|
66
|
-
if (await currentVersion(initial) !==
|
|
68
|
+
if (await currentVersion(initial) !== 16) throw new Error(t("Rebuild the Open Browser workspace extension."));
|
|
67
69
|
}
|
|
70
|
+
const updateLanguage = (host, settings) => evaluateWorker(host, value => globalThis.openBrowserSetLocale(value), settings);
|
|
71
|
+
await updateLanguage(initial, interfaceLanguage());
|
|
68
72
|
let stopped = false;
|
|
69
73
|
let lastState;
|
|
70
74
|
const effects = pageActivity();
|
|
@@ -74,7 +78,7 @@ export async function chromiumHost(context) {
|
|
|
74
78
|
// diagnostics override.
|
|
75
79
|
const guardMode = configuredGuard || 'fallback';
|
|
76
80
|
if (!['off', 'fallback', 'native'].includes(guardMode))
|
|
77
|
-
throw extensionError('invalid_input_guard_mode',
|
|
81
|
+
throw extensionError('invalid_input_guard_mode', t("OPEN_BROWSER_INPUT_GUARD must be off, fallback or native."));
|
|
78
82
|
const guarded = guardMode !== 'off';
|
|
79
83
|
const setInputGuard = guarded ? managedInput(context, tab => {
|
|
80
84
|
void worker().then(host => globalThis.openBrowserInputHint
|
|
@@ -88,8 +92,16 @@ export async function chromiumHost(context) {
|
|
|
88
92
|
async function respond(host, request, call) {
|
|
89
93
|
let response;
|
|
90
94
|
try {
|
|
91
|
-
if (
|
|
92
|
-
|
|
95
|
+
if (request.method === 'setInterfaceLanguage') {
|
|
96
|
+
const settings = setInterfaceLanguage(request.params?.preference);
|
|
97
|
+
await updateLanguage(host, settings);
|
|
98
|
+
lastState = undefined;
|
|
99
|
+
changed();
|
|
100
|
+
response = { id: request.id, result: settings };
|
|
101
|
+
} else {
|
|
102
|
+
if (!allowed.has(request.method)) throw Object.assign(new Error(), { code: 'unknown_method' });
|
|
103
|
+
response = { id: request.id, result: await call(request.method, request.params || {}) };
|
|
104
|
+
}
|
|
93
105
|
} catch (error) {
|
|
94
106
|
response = { id: request.id, error: error.code || 'operation_failed' };
|
|
95
107
|
}
|
|
@@ -112,12 +124,7 @@ export async function chromiumHost(context) {
|
|
|
112
124
|
while (!stopped) {
|
|
113
125
|
const startRevision = revision;
|
|
114
126
|
try {
|
|
115
|
-
const state =
|
|
116
|
-
workspaceId, agentName, name, mode, controlGeneration, pages: pages.map(({pageId}) => ({pageId})),
|
|
117
|
-
running: activity.running, currentPageId: activity.current?.pageId, stepKind: activity.current?.stepKind,
|
|
118
|
-
dispatchState: activity.current?.dispatchState, phase: activity.phase, needsCredential: activity.needsCredential,
|
|
119
|
-
needsHumanVerification: activity.needsHumanVerification,
|
|
120
|
-
}));
|
|
127
|
+
const state = await list();
|
|
121
128
|
const signature = JSON.stringify(state);
|
|
122
129
|
if (signature !== lastState) {
|
|
123
130
|
await evaluateWorker(await worker(), items => globalThis.openBrowserSync(items), state);
|
|
@@ -137,7 +144,7 @@ export async function chromiumHost(context) {
|
|
|
137
144
|
let frontRevision = 0;
|
|
138
145
|
while (!stopped) {
|
|
139
146
|
const bar = await frontTab().catch(() => null);
|
|
140
|
-
const signature = JSON.stringify(bar);
|
|
147
|
+
const signature = JSON.stringify([locale, bar]);
|
|
141
148
|
if (!stopped && signature !== lastBar) {
|
|
142
149
|
lastBar = signature;
|
|
143
150
|
send(bar);
|
|
@@ -199,9 +206,9 @@ export async function chromiumHost(context) {
|
|
|
199
206
|
},
|
|
200
207
|
async show() { await evaluateWorker(await worker(), () => globalThis.openBrowserShow()); },
|
|
201
208
|
clickBar,
|
|
202
|
-
start(call, onBar) {
|
|
209
|
+
start(call, onBar, listForSync = async () => (await call('listWorkspaces')).map(ws => extensionWorkspace(ws))) {
|
|
203
210
|
void requests(call);
|
|
204
|
-
void sync(
|
|
211
|
+
void sync(listForSync);
|
|
205
212
|
if (onBar) void watchFrontTab(onBar);
|
|
206
213
|
},
|
|
207
214
|
stop() { stopped = true; changed(); },
|
package/chromium-shell.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { interfaceLanguage, locale, t } from './i18n.mjs';
|
|
1
2
|
import { execFile } from 'node:child_process';
|
|
2
3
|
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import { copyFile, link, lstat, mkdir, mkdtemp, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
@@ -52,7 +53,7 @@ async function macPersistentEngine() {
|
|
|
52
53
|
await run('/usr/bin/codesign', ['--verify', '-R=' + requirement, path.resolve(executable, '../../..')]);
|
|
53
54
|
return executable;
|
|
54
55
|
} catch (cause) {
|
|
55
|
-
throw new Error(
|
|
56
|
+
throw new Error(t("Persistent browsing on macOS requires an Open Browser v2 engine signed with Developer ID. Run npm run build in the project directory and restart."), { cause });
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -73,7 +74,7 @@ async function prepareProfile(profileDir) {
|
|
|
73
74
|
// Its existence is the migration record, even if the user later deletes all bookmarks.
|
|
74
75
|
await mkdir(stateDir, { recursive: true, mode: 0o700 });
|
|
75
76
|
try {
|
|
76
|
-
if (!(await lstat(profileDir)).isDirectory()) throw new Error(
|
|
77
|
+
if (!(await lstat(profileDir)).isDirectory()) throw new Error(t("Invalid Open Browser v2 profile directory."));
|
|
77
78
|
return;
|
|
78
79
|
} catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
79
80
|
const staging = await mkdtemp(path.join(stateDir, '.open-browser-profile-v2-'));
|
|
@@ -111,7 +112,7 @@ async function seedProfile(profileDir) {
|
|
|
111
112
|
finally { await rm(temporary, { force: true }); }
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
export async function launchChromiumShell({ profileDir = defaultProfile, headless = false, netLogPath } = {}) {
|
|
115
|
+
export async function launchChromiumShell({ profileDir = defaultProfile, headless = false, netLogPath, restoreSession = false } = {}) {
|
|
115
116
|
// A locally compiled Dev engine uses an ephemeral profile. It has a distinct
|
|
116
117
|
// executable identity and must never open an installed user's Keychain/profile.
|
|
117
118
|
const customEngine = isDevelopmentBuild && process.env.OPEN_BROWSER_DEV_CHROMIUM;
|
|
@@ -134,7 +135,8 @@ export async function launchChromiumShell({ profileDir = defaultProfile, headles
|
|
|
134
135
|
// the first visible tab is redirected to the open-browser cockpit.
|
|
135
136
|
ignoreDefaultArgs: ['--disable-extensions', '--disable-popup-blocking',
|
|
136
137
|
...(!customEngine ? ['--use-mock-keychain', '--password-store=basic'] : [])],
|
|
137
|
-
args: [...chromiumPrivacyArgs(), '--load-extension=' + extensionDir, '--window-size=1240,860',
|
|
138
|
+
args: [...chromiumPrivacyArgs(), ...(restoreSession ? ['--restore-last-session'] : []), '--load-extension=' + extensionDir, '--window-size=1240,860',
|
|
139
|
+
...(interfaceLanguage().preference !== 'system' || process.env.OPEN_BROWSER_LOCALE ? ['--lang=' + locale] : []),
|
|
138
140
|
...(process.platform === 'linux' ? ['--class=open-browser', '--name=open-browser'] : []),
|
|
139
141
|
...(netLogPath ? ['--log-net-log=' + netLogPath, '--net-log-capture-mode=Default'] : [])],
|
|
140
142
|
});
|
|
@@ -151,7 +153,7 @@ export async function launchChromiumShell({ profileDir = defaultProfile, headles
|
|
|
151
153
|
{url:marker,background:true,focus:false}).then(target => { targetId = target.targetId; })]);
|
|
152
154
|
await page.goto('chrome://settings/appearance');
|
|
153
155
|
const applied = await page.evaluate(() => chrome.settingsPrivate.setPref('bookmark_bar.show_tab_groups',false,''));
|
|
154
|
-
if (!applied) throw new Error(
|
|
156
|
+
if (!applied) throw new Error(t("Could not configure tab groups on the bookmarks bar."));
|
|
155
157
|
} catch (error) {
|
|
156
158
|
await context.close();
|
|
157
159
|
throw error;
|
package/cli.mjs
CHANGED
|
@@ -1,47 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { locale, t } from "./i18n.mjs";
|
|
3
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
4
|
import { createInterface } from 'node:readline';
|
|
4
5
|
import { socketPath, adminTokenPath } from './paths.mjs';
|
|
5
6
|
import { localRequest, agentMethods, OpenBrowserClient, OpenBrowserError } from './sdk.mjs';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
function usage() {
|
|
9
|
+
const commands = agentMethods.join(locale === 'zh-CN' ? '、' : ', ');
|
|
10
|
+
const task = t("Page check");
|
|
11
|
+
return `open-browser <method> [< params.json]
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
${t("Read a JSON object from stdin and write the result to stdout.")}
|
|
14
|
+
${t("Available methods: {0}", commands)}
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
${t("Quick start")}
|
|
17
|
+
echo '{"url":"https://example.org","name":"${task}"}' | open-browser open
|
|
18
|
+
echo '{"workspaceId":"WORKSPACE_ID","pageId":"PAGE_ID"}' | open-browser observe
|
|
19
|
+
echo '{"workspaceId":"WORKSPACE_ID","operationId":"finish-UNIQUE-ID","keepPageIds":[]}' | open-browser finishWorkspace
|
|
16
20
|
|
|
17
|
-
open-browser
|
|
21
|
+
open-browser --json <method> # ${t("Print {result} or {error} to stdout and exit nonzero on failure.")}
|
|
22
|
+
open-browser session # ${t("Read one JSON request per line until stdin closes.")}
|
|
23
|
+
open-browser --schema # ${t("Show method names and parameter schemas.")}
|
|
24
|
+
open-browser skill # ${t("Show the skill guide for this package.")}
|
|
18
25
|
|
|
19
|
-
echo '{"name":"
|
|
20
|
-
echo '{"url":"https://example.org","name":"网页检查"}' | node cli.mjs open
|
|
26
|
+
echo '{"name":"${task}","agentName":"${t("Research assistant")}"}' | node cli.mjs createWorkspace
|
|
21
27
|
node cli.mjs listWorkspaces
|
|
22
28
|
echo '{"workspaceId":"WORKSPACE_ID","url":"https://example.org"}' | node cli.mjs openPage
|
|
23
|
-
echo '{"workspaceId":"WORKSPACE_ID","pageId":"PAGE_ID"}' | node cli.mjs observe
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
凭据在可信的本地控制台设置;使用 fillCredential 和 credentialRef 填写登录字段。
|
|
29
|
-
open-browser skill # 输出与当前包版本匹配的 Skill 指南
|
|
30
|
+
${t("Errors include code, message and an optional nextAction. After a timeout, query getOperation with the original operationId.")}
|
|
31
|
+
${t("Local admin commands: {0}", 'admin.pair, admin.list, admin.grant, admin.revoke, admin.revokeClient, admin.clearHistory, admin.scheduler, admin.setPixelPermission')}
|
|
32
|
+
${t("Bind credentials in the local console. Use fillCredential and credentialRef for sign-in fields.")}
|
|
30
33
|
`;
|
|
31
|
-
|
|
32
|
-
async function printSkillGuide() {
|
|
33
|
-
const platform = process.platform === 'darwin' ? 'macos' : process.platform === 'win32' ? 'windows' : null;
|
|
34
|
-
const candidates = platform
|
|
35
|
-
? [`skills/open-browser/SKILL.${platform}.md`, 'skills/open-browser/SKILL.md']
|
|
36
|
-
: ['skills/open-browser/SKILL.md'];
|
|
37
|
-
for (const relative of candidates) {
|
|
38
|
-
try {
|
|
39
|
-
const guide = await readFile(new URL(relative, import.meta.url), 'utf8');
|
|
40
|
-
process.stdout.write(guide.endsWith('\n') ? guide : guide + '\n');
|
|
41
|
-
return;
|
|
42
|
-
} catch {}
|
|
43
|
-
}
|
|
44
|
-
throw new OpenBrowserError('SKILL_GUIDE_NOT_FOUND', `未找到 Skill 指南。已检查:${candidates.join('、')}`);
|
|
45
34
|
}
|
|
46
35
|
|
|
47
36
|
async function readParams() {
|
|
@@ -50,13 +39,13 @@ async function readParams() {
|
|
|
50
39
|
if (process.stdin.isTTY) return {};
|
|
51
40
|
for await (const chunk of process.stdin) {
|
|
52
41
|
bytes += chunk.length;
|
|
53
|
-
if (bytes > 1024 * 1024) throw new OpenBrowserError('REQUEST_TOO_LARGE',
|
|
42
|
+
if (bytes > 1024 * 1024) throw new OpenBrowserError('REQUEST_TOO_LARGE', t("Standard input exceeds 1 MiB."));
|
|
54
43
|
chunks.push(chunk);
|
|
55
44
|
}
|
|
56
45
|
const text = Buffer.concat(chunks).toString('utf8');
|
|
57
46
|
if (!text.trim()) return {};
|
|
58
47
|
try { return JSON.parse(text); }
|
|
59
|
-
catch { throw new OpenBrowserError('INVALID_JSON',
|
|
48
|
+
catch { throw new OpenBrowserError('INVALID_JSON', t("Standard input must contain a JSON object.")); }
|
|
60
49
|
}
|
|
61
50
|
|
|
62
51
|
async function sessionMain() {
|
|
@@ -67,11 +56,11 @@ async function sessionMain() {
|
|
|
67
56
|
input.on('line', line => {
|
|
68
57
|
tail = tail.then(async () => {
|
|
69
58
|
let frame;
|
|
70
|
-
try { frame = JSON.parse(line); } catch { send({ id: null, error: { code: 'INVALID_JSON', message:
|
|
59
|
+
try { frame = JSON.parse(line); } catch { send({ id: null, error: { code: 'INVALID_JSON', message: t("Each line must be a JSON request.") } }); return; }
|
|
71
60
|
const id = frame?.id;
|
|
72
61
|
if (!(typeof id === 'string' || Number.isSafeInteger(id)) || typeof frame?.method !== 'string' || !frame.method ||
|
|
73
62
|
(frame.params !== undefined && (!frame.params || typeof frame.params !== 'object' || Array.isArray(frame.params)))) {
|
|
74
|
-
send({ id: id ?? null, error: { code: 'INVALID_PARAMS', message:
|
|
63
|
+
send({ id: id ?? null, error: { code: 'INVALID_PARAMS', message: t("A session request needs an id, a method and a params object.") } });
|
|
75
64
|
return;
|
|
76
65
|
}
|
|
77
66
|
try {
|
|
@@ -88,10 +77,17 @@ async function sessionMain() {
|
|
|
88
77
|
api.close();
|
|
89
78
|
}
|
|
90
79
|
|
|
80
|
+
const jsonMode = process.argv[2] === '--json';
|
|
81
|
+
function writeResult(result) {
|
|
82
|
+
process.stdout.write(JSON.stringify(jsonMode ? {result:result ?? null} : result) + '\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
91
85
|
async function main() {
|
|
92
|
-
const [method, ...extra] = process.argv.slice(2);
|
|
86
|
+
const [method, ...extra] = process.argv.slice(jsonMode ? 3 : 2);
|
|
87
|
+
if (jsonMode && !agentMethods.includes(method) && !method?.startsWith('admin.'))
|
|
88
|
+
throw new OpenBrowserError('UNKNOWN_METHOD',t("--json requires an API method name."));
|
|
93
89
|
if (method === 'session') {
|
|
94
|
-
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS',
|
|
90
|
+
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', t("session takes no additional arguments."));
|
|
95
91
|
await sessionMain();
|
|
96
92
|
return;
|
|
97
93
|
}
|
|
@@ -101,39 +97,46 @@ async function main() {
|
|
|
101
97
|
return;
|
|
102
98
|
}
|
|
103
99
|
if (method === 'skill') {
|
|
104
|
-
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS',
|
|
105
|
-
await
|
|
100
|
+
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', t("skill takes no additional arguments."));
|
|
101
|
+
const { readSkillGuide } = await import('./skills/open-browser/scripts/guide.mjs');
|
|
102
|
+
process.stdout.write(await readSkillGuide());
|
|
106
103
|
return;
|
|
107
104
|
}
|
|
108
105
|
if (!method || method === '--help' || method === '-h') {
|
|
109
|
-
process.stdout.write(
|
|
106
|
+
process.stdout.write(usage());
|
|
110
107
|
return;
|
|
111
108
|
}
|
|
112
|
-
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS',
|
|
109
|
+
if (extra.length) throw new OpenBrowserError('INVALID_PARAMS', t("Provide JSON parameters on standard input."));
|
|
113
110
|
if (method.startsWith('admin.')) {
|
|
114
|
-
if (process.env.OPEN_BROWSER_CLIENT_TOKEN_FILE) throw new OpenBrowserError('forbidden',
|
|
111
|
+
if (process.env.OPEN_BROWSER_CLIENT_TOKEN_FILE) throw new OpenBrowserError('forbidden', t("Run this command from a local administrator session."));
|
|
115
112
|
const params = await readParams();
|
|
116
113
|
const {tokenFile, ...args} = params;
|
|
117
114
|
const admin = (name, values) => localRequest(socketPath,adminTokenPath,'/v1/admin',name,values);
|
|
118
|
-
if (method === 'admin.pair' && (typeof tokenFile !== 'string' || !tokenFile)) throw new OpenBrowserError('INVALID_PARAMS',
|
|
115
|
+
if (method === 'admin.pair' && (typeof tokenFile !== 'string' || !tokenFile)) throw new OpenBrowserError('INVALID_PARAMS',t("Provide tokenFile as the path for the new token file."));
|
|
119
116
|
const result = await admin(method.slice(6),args);
|
|
120
117
|
if (method === 'admin.pair') {
|
|
121
118
|
try { await writeFile(tokenFile,result.token + '\n',{flag:'wx',mode:0o600}); }
|
|
122
|
-
catch (error) {
|
|
119
|
+
catch (error) {
|
|
120
|
+
try { await admin('revokeClient', {principalId:result.principalId}); }
|
|
121
|
+
catch {
|
|
122
|
+
throw new OpenBrowserError('PAIR_CLEANUP_FAILED', t("Could not write the token file. Check and revoke {0} with admin.revokeClient.", result.principalId));
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
123
126
|
delete result.token;
|
|
124
127
|
}
|
|
125
|
-
|
|
128
|
+
writeResult(result);
|
|
126
129
|
return;
|
|
127
130
|
}
|
|
128
|
-
if (!agentMethods.includes(method)) throw new OpenBrowserError('UNKNOWN_METHOD',
|
|
131
|
+
if (!agentMethods.includes(method)) throw new OpenBrowserError('UNKNOWN_METHOD', t("Unknown method. Use --help to list commands."));
|
|
129
132
|
const api = new OpenBrowserClient({ fallbackName: 'CLI' });
|
|
130
133
|
const params = await readParams();
|
|
131
134
|
const result = method === 'capabilities' ? await api.capabilities() : await api.call(method, params);
|
|
132
|
-
|
|
135
|
+
writeResult(result);
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
main().catch(error => {
|
|
136
|
-
process.stderr.write(JSON.stringify({ error: {
|
|
139
|
+
(jsonMode ? process.stdout : process.stderr).write(JSON.stringify({ error: {
|
|
137
140
|
code: error.code ?? 'CLI_ERROR', message: error.message,
|
|
138
141
|
...(error.nextAction ? { nextAction: error.nextAction } : {}),
|
|
139
142
|
} }) + '\n');
|
package/contract-validation.mjs
CHANGED
|
@@ -7,7 +7,7 @@ const schemas = new Map(tools.map(tool => [tool.name,tool.inputSchema]));
|
|
|
7
7
|
// Older callers spread a returned page or workspace handle into a subsequent request.
|
|
8
8
|
// Strip only the known read-only handle fields before checking that request.
|
|
9
9
|
const viewFields = new Set(['agentName','name','mode','pages','controlGeneration','activity','blockedOrigins','pageId','origin','title','profile','profileId','profileAlias',
|
|
10
|
-
'pageAvailability','nextAction','scope','accountAlias','ownership','syncState','syncRevision','lastSyncedAt','security','openedByOperationId','openerPageId','documentId','pendingDialogs']);
|
|
10
|
+
'pageAvailability','readyForAgent','nextAction','scope','accountAlias','ownership','syncState','syncRevision','lastSyncedAt','security','openedByOperationId','openerPageId','documentId','pendingDialogs']);
|
|
11
11
|
|
|
12
12
|
export function checkAgentRequest(method, params) {
|
|
13
13
|
const schema = schemas.get(method);
|
package/control.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t } from './i18n.mjs';
|
|
1
2
|
import { pathToFileURL } from 'node:url';
|
|
2
3
|
import { chromium } from 'playwright-core';
|
|
3
4
|
import { engineExecutable } from './runtime.mjs';
|
|
@@ -14,23 +15,23 @@ export async function launchBrowser({ headless = true } = {}) {
|
|
|
14
15
|
|
|
15
16
|
function validate({ tasks, concurrency = 4 }) {
|
|
16
17
|
if (!Array.isArray(tasks) || !tasks.length)
|
|
17
|
-
throw new Error('tasks must be a nonempty array');
|
|
18
|
+
throw new Error(t('tasks must be a nonempty array'));
|
|
18
19
|
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 16)
|
|
19
|
-
throw new Error('concurrency must be an integer between 1 and 16');
|
|
20
|
+
throw new Error(t('concurrency must be an integer between 1 and 16'));
|
|
20
21
|
const ids = new Set();
|
|
21
22
|
for (const task of tasks) {
|
|
22
23
|
if (!task || typeof task.id !== 'string' || !task.id || ids.has(task.id))
|
|
23
|
-
throw new Error('each task needs a unique string id');
|
|
24
|
+
throw new Error(t('each task needs a unique string id'));
|
|
24
25
|
ids.add(task.id);
|
|
25
26
|
if (!URL.canParse(task.url) || !['http:', 'https:'].includes(new URL(task.url).protocol))
|
|
26
|
-
throw new Error('each task needs an HTTP(S) URL');
|
|
27
|
-
if (!Array.isArray(task.steps)) throw new Error('steps must be an array');
|
|
27
|
+
throw new Error(t('each task needs an HTTP(S) URL'));
|
|
28
|
+
if (!Array.isArray(task.steps)) throw new Error(t('steps must be an array'));
|
|
28
29
|
for (const step of task.steps) {
|
|
29
30
|
if (!step || !['fill', 'click', 'read'].includes(step.op) ||
|
|
30
31
|
typeof step.selector !== 'string' || !step.selector.trim())
|
|
31
|
-
throw new Error('each step needs a fill, click or read operation and a selector');
|
|
32
|
+
throw new Error(t('each step needs a fill, click or read operation and a selector'));
|
|
32
33
|
if (step.op === 'fill' && typeof step.value !== 'string')
|
|
33
|
-
throw new Error('fill needs a string value');
|
|
34
|
+
throw new Error(t('fill needs a string value'));
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -87,7 +88,7 @@ async function main() {
|
|
|
87
88
|
for await (const chunk of process.stdin) input += chunk;
|
|
88
89
|
let batch;
|
|
89
90
|
try { batch = JSON.parse(input); }
|
|
90
|
-
catch { throw new Error('stdin must contain a JSON batch'); }
|
|
91
|
+
catch { throw new Error(t('stdin must contain a JSON batch')); }
|
|
91
92
|
validate(batch);
|
|
92
93
|
const browser = await launchBrowser();
|
|
93
94
|
try {
|
package/desktop/Info.plist
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
3
|
<plist version="1.0"><dict>
|
|
4
|
+
<key>CFBundleDevelopmentRegion</key><string>en</string>
|
|
5
|
+
<key>CFBundleLocalizations</key><array><string>en</string><string>zh-Hans</string></array>
|
|
4
6
|
<key>CFBundleIdentifier</key><string>local.open-browser.desktop</string>
|
|
5
7
|
<key>CFBundleName</key><string>open-browser</string>
|
|
6
8
|
<key>CFBundleDisplayName</key><string>open-browser</string>
|
|
7
9
|
<key>CFBundleExecutable</key><string>open-browser</string>
|
|
8
10
|
<key>CFBundlePackageType</key><string>APPL</string>
|
|
9
11
|
<key>CFBundleIconFile</key><string>open-browser.icns</string>
|
|
10
|
-
<key>CFBundleVersion</key><string>
|
|
11
|
-
<key>CFBundleShortVersionString</key><string>0.
|
|
12
|
+
<key>CFBundleVersion</key><string>2</string>
|
|
13
|
+
<key>CFBundleShortVersionString</key><string>0.3.1</string>
|
|
12
14
|
<key>NSHighResolutionCapable</key><true/>
|
|
13
15
|
</dict></plist>
|
package/desktop/Launcher.m
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "OBLocalization.h"
|
|
1
2
|
#import <AppKit/AppKit.h>
|
|
2
3
|
#import <signal.h>
|
|
3
4
|
#import "OBControlBar.h"
|
|
@@ -19,6 +20,9 @@
|
|
|
19
20
|
NSURL *app = [resources URLByAppendingPathComponent:@"app"];
|
|
20
21
|
self.service = [NSTask new];
|
|
21
22
|
self.service.currentDirectoryURL = app;
|
|
23
|
+
NSMutableDictionary *environment = [NSProcessInfo.processInfo.environment mutableCopy];
|
|
24
|
+
environment[@"OPEN_BROWSER_SYSTEM_LOCALE"] = NSBundle.mainBundle.preferredLocalizations.firstObject ?: @"en";
|
|
25
|
+
self.service.environment = environment;
|
|
22
26
|
self.service.executableURL = [resources URLByAppendingPathComponent:@"node/bin/node"];
|
|
23
27
|
self.service.arguments = @[[app URLByAppendingPathComponent:@"service.mjs"].path, @"--chromium", @"--desktop-bar"];
|
|
24
28
|
NSPipe *output = [NSPipe pipe];
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
[owner.bar stop];
|
|
35
39
|
owner.ready = NO;
|
|
36
40
|
if (owner.quitting) { [NSApp replyToApplicationShouldTerminate:YES]; return; }
|
|
37
|
-
if (task.terminationStatus != 0) [owner showError
|
|
41
|
+
if (task.terminationStatus != 0) [owner showError:OBLocalizedString(@"The local browser service exited. Check whether a service started from source is already running.")];
|
|
38
42
|
[NSApp terminate:nil];
|
|
39
43
|
});
|
|
40
44
|
};
|
|
@@ -77,7 +81,11 @@
|
|
|
77
81
|
if (!self.service.running || self.quitting) return;
|
|
78
82
|
NSDictionary *event = [message isKindOfClass:NSDictionary.class] ? message : nil;
|
|
79
83
|
if (ready || [event[@"ready"] isEqual:@YES]) self.ready = YES;
|
|
80
|
-
if ([event[@"event"] isEqual:@"desktop.bar"])
|
|
84
|
+
if ([event[@"event"] isEqual:@"desktop.bar"]) {
|
|
85
|
+
NSString *language = [event[@"locale"] isEqual:@"zh-CN"] ? @"zh-Hans" : @"en";
|
|
86
|
+
[NSUserDefaults.standardUserDefaults registerDefaults:@{@"OpenBrowserServiceLanguage":language}];
|
|
87
|
+
[self.bar update:event[@"bar"]];
|
|
88
|
+
}
|
|
81
89
|
});
|
|
82
90
|
}
|
|
83
91
|
[line setLength:0]; skip = NO;
|
package/desktop/OBControlBar.m
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "OBLocalization.h"
|
|
1
2
|
#import "OBControlBar.h"
|
|
2
3
|
#import <CoreGraphics/CoreGraphics.h>
|
|
3
4
|
#import <sys/sysctl.h>
|
|
@@ -72,7 +73,7 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
72
73
|
_send = [send copy];
|
|
73
74
|
_panel = [[OBPanel alloc] initWithContentRect:NSMakeRect(0, 0, 248, 42)
|
|
74
75
|
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel backing:NSBackingStoreBuffered defer:NO];
|
|
75
|
-
_panel.title = @"
|
|
76
|
+
_panel.title = OBLocalizedString(@"Open Browser control bar");
|
|
76
77
|
_panel.floatingPanel = YES;
|
|
77
78
|
_panel.level = NSFloatingWindowLevel;
|
|
78
79
|
_panel.hidesOnDeactivate = NO;
|
|
@@ -102,14 +103,14 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
102
103
|
_status = [NSTextField labelWithString:@""];
|
|
103
104
|
_status.font = [NSFont systemFontOfSize:12];
|
|
104
105
|
_status.textColor = NSColor.secondaryLabelColor;
|
|
105
|
-
_button = [OBBarButton buttonWithTitle
|
|
106
|
+
_button = [OBBarButton buttonWithTitle:OBLocalizedString(@"Take over") target:self action:@selector(click:)];
|
|
106
107
|
_button.bezelStyle = NSBezelStyleRounded;
|
|
107
108
|
_button.controlSize = NSControlSizeSmall;
|
|
108
109
|
_button.focusRingType = NSFocusRingTypeNone;
|
|
109
|
-
_delivery = [OBBarButton buttonWithTitle
|
|
110
|
+
_delivery = [OBBarButton buttonWithTitle:OBLocalizedString(@"Finish") target:self action:@selector(click:)];
|
|
110
111
|
_delivery.bezelStyle = NSBezelStyleRounded;
|
|
111
112
|
_delivery.controlSize = NSControlSizeSmall;
|
|
112
|
-
_delivery.toolTip = @"
|
|
113
|
+
_delivery.toolTip = OBLocalizedString(@"Finish this agent task and keep its open pages");
|
|
113
114
|
NSStackView *row = [NSStackView stackViewWithViews:@[_dot, _agent, _status, _button, _delivery]];
|
|
114
115
|
row.spacing = 8;
|
|
115
116
|
row.alignment = NSLayoutAttributeCenterY;
|
|
@@ -164,6 +165,9 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
164
165
|
if (![bar[key] isKindOfClass:NSNumber.class] || !isfinite([bar[key] doubleValue])) { bar = nil; break; }
|
|
165
166
|
}
|
|
166
167
|
self.bar = bar;
|
|
168
|
+
self.panel.title = OBLocalizedString(@"Open Browser control bar");
|
|
169
|
+
self.delivery.title = OBLocalizedString(@"Finish");
|
|
170
|
+
self.delivery.toolTip = OBLocalizedString(@"Finish this agent task and keep its open pages");
|
|
167
171
|
if (!bar) {
|
|
168
172
|
self.pending = nil;
|
|
169
173
|
self.button.binding = nil;
|
|
@@ -179,13 +183,13 @@ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ?
|
|
|
179
183
|
self.delivery.binding = delivery;
|
|
180
184
|
if (![self.pending isEqual:binding]) self.pending = nil;
|
|
181
185
|
BOOL human = [bar[@"mode"] isEqual:@"human"], transferring = [bar[@"mode"] isEqual:@"transferring"];
|
|
182
|
-
NSDictionary *states = @{@"actionability"
|
|
183
|
-
@"needs_credential"
|
|
186
|
+
NSDictionary *states = @{@"actionability":OBLocalizedString(@"Checking target"), @"dispatching":OBLocalizedString(@"Dispatching"), @"waiting":OBLocalizedString(@"Waiting for page"), @"verifying":OBLocalizedString(@"Checking result"), @"dispatched":OBLocalizedString(@"Dispatched"), @"running":OBLocalizedString(@"Running"), @"queued":OBLocalizedString(@"Queued"), @"idle":OBLocalizedString(@"Idle"), @"completed":OBLocalizedString(@"Completed"),
|
|
187
|
+
@"needs_visual_permission":OBLocalizedString(@"Screenshot permission required"), @"needs_credential":OBLocalizedString(@"Waiting for credentials"), @"needs_human_verification":OBLocalizedString(@"Human verification required"), @"failed":OBLocalizedString(@"Failed"), @"cancelled":OBLocalizedString(@"Cancelled"), @"outcome_unknown":OBLocalizedString(@"Unverified")};
|
|
184
188
|
self.agent.stringValue = Text(bar[@"agentName"]).length ? bar[@"agentName"] : @"Agent";
|
|
185
189
|
self.agent.toolTip = self.agent.stringValue;
|
|
186
|
-
self.status.stringValue = transferring ? @"
|
|
190
|
+
self.status.stringValue = transferring ? OBLocalizedString(@"Transferring") : human ? OBLocalizedString(@"Human in control") : states[Text(bar[@"phase"])] ?: OBLocalizedString(@"Idle");
|
|
187
191
|
self.button.bezelColor = !human && !transferring && [bar[@"inputBlocked"] boolValue] ? NSColor.systemOrangeColor : nil;
|
|
188
|
-
self.button.title = human ? @"
|
|
192
|
+
self.button.title = human ? OBLocalizedString(@"Return to agent") : OBLocalizedString(@"Take over");
|
|
189
193
|
self.delivery.enabled = !transferring;
|
|
190
194
|
self.button.enabled = !transferring && !self.pending;
|
|
191
195
|
NSColor *color = transferring ? NSColor.systemOrangeColor : human ? NSColor.systemGreenColor : NSColor.systemBlueColor;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
// Finder launches use the app's preferred localization. A source or scripted
|
|
4
|
+
// launch can select the same language as the CLI without changing OS defaults.
|
|
5
|
+
NS_INLINE NSString *OBInterfaceLanguage(void) {
|
|
6
|
+
NSString *selected = [NSUserDefaults.standardUserDefaults stringForKey:@"OpenBrowserServiceLanguage"];
|
|
7
|
+
if ([selected isEqualToString:@"en"] || [selected isEqualToString:@"zh-Hans"]) return selected;
|
|
8
|
+
NSString *override = [NSProcessInfo.processInfo.environment[@"OPEN_BROWSER_LOCALE"]
|
|
9
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
10
|
+
if (!override.length) return NSBundle.mainBundle.preferredLocalizations.firstObject ?: @"en";
|
|
11
|
+
NSString *language = [[override.lowercaseString componentsSeparatedByCharactersInSet:
|
|
12
|
+
[NSCharacterSet characterSetWithCharactersInString:@"-_.@"]] firstObject];
|
|
13
|
+
return [language isEqualToString:@"zh"] ? @"zh-Hans" : @"en";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
NS_INLINE NSString *OBLocalizedString(NSString *key) {
|
|
17
|
+
NSString *path = [NSBundle.mainBundle pathForResource:OBInterfaceLanguage() ofType:@"lproj"];
|
|
18
|
+
NSBundle *bundle = path ? [NSBundle bundleWithPath:path] : NSBundle.mainBundle;
|
|
19
|
+
return [bundle localizedStringForKey:key value:key table:nil];
|
|
20
|
+
}
|
package/desktop/OBPageView.m
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "OBLocalization.h"
|
|
1
2
|
#import "OBPageView.h"
|
|
2
3
|
|
|
3
4
|
@interface OBPageView ()
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
_events = [NSMutableArray array];
|
|
27
28
|
[self setAccessibilityElement:YES];
|
|
28
29
|
[self setAccessibilityRole:NSAccessibilityImageRole];
|
|
29
|
-
[self setAccessibilityLabel
|
|
30
|
+
[self setAccessibilityLabel:OBLocalizedString(@"Workspace web page")];
|
|
30
31
|
[self setAccessibilityIdentifier:@"open-browser-workspace-page"];
|
|
31
32
|
}
|
|
32
33
|
return self;
|