ohos-playwright-mcp 0.2.2 → 0.2.3
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/package.json +1 -1
- package/server.mjs +16 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohos-playwright-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "MCP server for HarmonyOS / OpenHarmony ArkWeb — playwright-core over CDP. 61 tools: navigation, input, network, cookies, storage, snapshot, tracing. The ohos counterpart of @playwright/mcp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/server.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { createRequire } from 'node:module'
|
|
9
9
|
import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
10
|
-
import { dirname } from 'node:path'
|
|
10
|
+
import { dirname, join } from 'node:path'
|
|
11
11
|
import { tmpdir } from 'node:os'
|
|
12
12
|
|
|
13
13
|
const require = createRequire(import.meta.url)
|
|
@@ -223,8 +223,10 @@ tool('evaluate', 'Evaluate JavaScript on the page. `expression` may be an expres
|
|
|
223
223
|
async ({ expression }) => withRetryOnNavigation(async () => {
|
|
224
224
|
const page = await getPage()
|
|
225
225
|
const looksLikeFn = /^\s*(\([^)]*\)\s*=>|async\s|function\b)/.test(expression)
|
|
226
|
-
const
|
|
227
|
-
|
|
226
|
+
const looksLikeIIFE = /^\s*\(\s*(\(|async\s|function\b)/.test(expression)
|
|
227
|
+
const shouldInvoke = looksLikeFn && !looksLikeIIFE
|
|
228
|
+
const r = await page.evaluate(shouldInvoke ? `(${expression})()` : expression)
|
|
229
|
+
return JSON.stringify(r, null, 2) ?? 'undefined'
|
|
228
230
|
}))
|
|
229
231
|
|
|
230
232
|
async function withRetryOnNavigation(fn) {
|
|
@@ -245,13 +247,14 @@ tool('get_html', 'Return document.documentElement.outerHTML.',
|
|
|
245
247
|
sObj({}),
|
|
246
248
|
async () => withRetryOnNavigation(async () => (await getPage()).content()))
|
|
247
249
|
|
|
248
|
-
tool('screenshot', 'Take a PNG screenshot.
|
|
250
|
+
tool('screenshot', 'Take a PNG screenshot. Default saves to a tmp path (ArkWeb resolutions often exceed MCP clients\' inline-image size limit). Pass `path` to choose location, or `inline: true` to return base64. Uses raw CDP to skip Playwright font-wait (which hangs on some ArkWeb pages).',
|
|
249
251
|
sObj({
|
|
250
|
-
path: sStr('save to this path
|
|
252
|
+
path: sStr('save to this path (overrides default tmp location)'),
|
|
251
253
|
full_page: sBool('capture full scrollable page', false),
|
|
252
254
|
selector: sStr('limit to an element matching this selector'),
|
|
255
|
+
inline: sBool('return base64 image instead of saving to disk (may exceed client size limits)', false),
|
|
253
256
|
}),
|
|
254
|
-
async ({ path, full_page, selector }) => {
|
|
257
|
+
async ({ path, full_page, selector, inline }) => {
|
|
255
258
|
const page = await getPage()
|
|
256
259
|
let buf
|
|
257
260
|
if (selector) {
|
|
@@ -263,12 +266,13 @@ tool('screenshot', 'Take a PNG screenshot. If `path` given, save to disk; else r
|
|
|
263
266
|
buf = Buffer.from(r.data, 'base64')
|
|
264
267
|
} finally { await session.detach().catch(() => {}) }
|
|
265
268
|
}
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
writeFileSync(path, buf)
|
|
269
|
-
return `saved ${buf.length} bytes to ${path}`
|
|
269
|
+
if (inline) {
|
|
270
|
+
return { content: [{ type: 'image', data: buf.toString('base64'), mimeType: 'image/png' }] }
|
|
270
271
|
}
|
|
271
|
-
|
|
272
|
+
const outPath = path ?? join(tmpdir(), `ohos-screenshot-${Date.now()}.png`)
|
|
273
|
+
mkdirSync(dirname(outPath), { recursive: true })
|
|
274
|
+
writeFileSync(outPath, buf)
|
|
275
|
+
return `saved ${buf.length} bytes to ${outPath}`
|
|
272
276
|
})
|
|
273
277
|
|
|
274
278
|
// -------------------- tabs/pages --------------------
|
|
@@ -704,7 +708,7 @@ async function handle(msg) {
|
|
|
704
708
|
try {
|
|
705
709
|
switch (msg.method) {
|
|
706
710
|
case 'initialize':
|
|
707
|
-
return { protocolVersion: '2024-11-05', capabilities: { tools: {} }, serverInfo: { name: '
|
|
711
|
+
return { protocolVersion: '2024-11-05', capabilities: { tools: {} }, serverInfo: { name: 'ohos-playwright-mcp', version: '0.2.3' } }
|
|
708
712
|
case 'notifications/initialized':
|
|
709
713
|
return null
|
|
710
714
|
case 'tools/list':
|