Skip to content
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
9 changes: 7 additions & 2 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"manifestVersion": 1,
"id": "wdh",
"version": "0.1.0",
"version": "0.1.1",
"apiVersion": 1,
"entrypoint": "src/cli.mjs",
"node": ">=24",
"capabilities": ["web.browser", "web.capture", "web.debugger", "web.fingerprint"],
"capabilities": [
"web.browser",
"web.capture",
"web.debugger",
"web.fingerprint"
],
"browserBinariesIncluded": false
}
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decrypthub/wdh",
"version": "0.1.0",
"version": "0.1.1",
"type": "module",
"license": "MIT",
"description": "Standalone browser analysis MCP runtime with optional CloakBrowser",
Expand Down
14 changes: 13 additions & 1 deletion src/service.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class WebRuntime {
case 'hello':
return {
apiVersion: API_VERSION,
capabilities: { pageTabs: true },
version: VERSION,
tools: BROWSER_TOOLS.map(({ name, description, schema, group }) => ({
name,
Expand All @@ -187,8 +188,19 @@ export class WebRuntime {
await this.browser.navigate(args.url);
return this.status();
case 'select':
await this.browser.setActive(this.browser.pages[args.index]);
{
const index = args.pageId ? this.status().pages.findIndex(p => p.id === args.pageId) : args.index;
if (!Number.isInteger(index) || !this.browser.pages[index]) throw Error('浏览器标签页已关闭,请重新列出');
await this.browser.selectPage(index);
}
return this.status();
case 'close-page': {
const index = this.status().pages.findIndex(p => p.id === args.pageId);
const page = this.browser.pages[index];
if (!page) throw Error('浏览器标签页已关闭,请重新列出');
await page.close();
return this.status();
}
case 'new-page':
await this.browser.newPage(args.url);
return this.status();
Expand Down
19 changes: 19 additions & 0 deletions test/page-tabs.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { WebRuntime } from '../src/service.mjs';
test('desktop page IDs survive reordering, select brings the page forward, and close rejects stale IDs', async t => {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'wdh-tabs-'));
t.after(() => { assert.equal(path.dirname(directory), os.tmpdir()); fs.rmSync(directory, { recursive: true, force: true }); });
const runtime = new WebRuntime({ root: directory, dataDir: directory, desktop: true });
const seen = [], makePage = name => ({ url: () => 'https://' + name + '.test', bringToFront: async () => seen.push(name), close: async () => { runtime.browser.pages = runtime.browser.pages.filter(p => p !== pages[name]); } });
const pages = { a: makePage('a'), b: makePage('b') }; runtime.browser.pages = [pages.a, pages.b]; runtime.browser.activePage = pages.a;
const a = runtime.status().pages[0].id, b = runtime.status().pages[1].id;
assert.equal((await runtime.control('hello')).capabilities.pageTabs, true);
runtime.browser.pages.reverse(); await runtime.control('select', { pageId: a, index: 0 }); assert.deepEqual(seen, ['a']); assert.equal(runtime.browser.activePage, pages.a);
await runtime.control('close-page', { pageId: b }); assert.equal(runtime.browser.pages.includes(pages.b), false);
await assert.rejects(runtime.control('close-page', { pageId: b }), /已关闭/);
await assert.rejects(runtime.control('select', { pageId: b }), /已关闭/);
});
Loading