@midscene/computer 1.4.7 → 1.4.8-beta-20260226063853.0
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/dist/es/cli.mjs +24 -9
- package/dist/es/index.mjs +24 -9
- package/dist/es/mcp-server.mjs +24 -9
- package/dist/lib/cli.js +23 -8
- package/dist/lib/index.js +23 -8
- package/dist/lib/mcp-server.js +23 -8
- package/package.json +3 -3
package/dist/es/cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { execSync, spawn } from "node:child_process";
|
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import { actionHoverParamSchema, defineAction, defineActionClearInput, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
10
10
|
import { sleep } from "@midscene/core/utils";
|
|
11
|
-
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
11
|
+
import { createImgBase64ByFormat, imageInfoOfBase64 } from "@midscene/shared/img";
|
|
12
12
|
import screenshot_desktop from "screenshot-desktop";
|
|
13
13
|
import { existsSync } from "node:fs";
|
|
14
14
|
const debugXvfb = getDebug('computer:xvfb');
|
|
@@ -88,12 +88,9 @@ function _define_property(obj, key, value) {
|
|
|
88
88
|
else obj[key] = value;
|
|
89
89
|
return obj;
|
|
90
90
|
}
|
|
91
|
-
const SMOOTH_MOVE_STEPS_TAP = 8;
|
|
92
91
|
const SMOOTH_MOVE_STEPS_MOUSE_MOVE = 10;
|
|
93
|
-
const SMOOTH_MOVE_DELAY_TAP = 8;
|
|
94
92
|
const SMOOTH_MOVE_DELAY_MOUSE_MOVE = 10;
|
|
95
93
|
const MOUSE_MOVE_EFFECT_WAIT = 300;
|
|
96
|
-
const CLICK_HOLD_DURATION = 50;
|
|
97
94
|
const INPUT_FOCUS_DELAY = 300;
|
|
98
95
|
const INPUT_CLEAR_DELAY = 150;
|
|
99
96
|
const SCROLL_REPEAT_COUNT = 10;
|
|
@@ -270,11 +267,22 @@ class ComputerDevice {
|
|
|
270
267
|
const size = await this.size();
|
|
271
268
|
const displays = await ComputerDevice.listDisplays();
|
|
272
269
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
270
|
+
let dpiInfo = '';
|
|
271
|
+
try {
|
|
272
|
+
const screenshotB64 = await this.screenshotBase64();
|
|
273
|
+
const imgInfo = await imageInfoOfBase64(screenshotB64);
|
|
274
|
+
const scaleX = imgInfo.width / size.width;
|
|
275
|
+
const scaleY = imgInfo.height / size.height;
|
|
276
|
+
dpiInfo = `\nScreenshot Size: ${imgInfo.width}x${imgInfo.height} (scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)})`;
|
|
277
|
+
if (1 !== scaleX || 1 !== scaleY) console.warn(`[ComputerDevice] DPI scaling detected! Screen: ${size.width}x${size.height}, Screenshot: ${imgInfo.width}x${imgInfo.height}, Scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)}`);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
dpiInfo = '\nScreenshot Size: unknown (check failed)';
|
|
280
|
+
}
|
|
273
281
|
this.description = `
|
|
274
282
|
Type: Computer
|
|
275
283
|
Platform: ${process.platform}
|
|
276
284
|
Display: ${this.displayId || 'Primary'}
|
|
277
|
-
Screen Size: ${size.width}x${size.height}
|
|
285
|
+
Screen Size: ${size.width}x${size.height}${dpiInfo}
|
|
278
286
|
Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ') : 'Unknown'}${headlessInfo}
|
|
279
287
|
`;
|
|
280
288
|
debugDevice('Computer device connected', this.description);
|
|
@@ -392,10 +400,17 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
392
400
|
const [x, y] = element.center;
|
|
393
401
|
const targetX = Math.round(x);
|
|
394
402
|
const targetY = Math.round(y);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
403
|
+
try {
|
|
404
|
+
const activeHandle = libnut.getActiveWindow();
|
|
405
|
+
const title = libnut.getWindowTitle(activeHandle);
|
|
406
|
+
const rect = libnut.getWindowRect(activeHandle);
|
|
407
|
+
debugDevice(`Tap(${targetX}, ${targetY}) activeWindow: handle=${activeHandle}, title="${title}", rect=(${rect.x},${rect.y},${rect.width},${rect.height})`);
|
|
408
|
+
} catch (e) {
|
|
409
|
+
debugDevice(`Tap(${targetX}, ${targetY}) failed to get window info: ${e}`);
|
|
410
|
+
}
|
|
411
|
+
libnut.moveMouse(targetX, targetY);
|
|
412
|
+
await sleep(100);
|
|
413
|
+
libnut.mouseClick('left');
|
|
399
414
|
}),
|
|
400
415
|
defineActionDoubleClick(async (param)=>{
|
|
401
416
|
node_assert(libnut, 'libnut not initialized');
|
package/dist/es/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import { getMidsceneLocationSchema, z } from "@midscene/core";
|
|
5
5
|
import { actionHoverParamSchema, defineAction, defineActionClearInput, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
6
6
|
import { sleep } from "@midscene/core/utils";
|
|
7
|
-
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
7
|
+
import { createImgBase64ByFormat, imageInfoOfBase64 } from "@midscene/shared/img";
|
|
8
8
|
import { getDebug } from "@midscene/shared/logger";
|
|
9
9
|
import screenshot_desktop from "screenshot-desktop";
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
@@ -87,12 +87,9 @@ function _define_property(obj, key, value) {
|
|
|
87
87
|
else obj[key] = value;
|
|
88
88
|
return obj;
|
|
89
89
|
}
|
|
90
|
-
const SMOOTH_MOVE_STEPS_TAP = 8;
|
|
91
90
|
const SMOOTH_MOVE_STEPS_MOUSE_MOVE = 10;
|
|
92
|
-
const SMOOTH_MOVE_DELAY_TAP = 8;
|
|
93
91
|
const SMOOTH_MOVE_DELAY_MOUSE_MOVE = 10;
|
|
94
92
|
const MOUSE_MOVE_EFFECT_WAIT = 300;
|
|
95
|
-
const CLICK_HOLD_DURATION = 50;
|
|
96
93
|
const INPUT_FOCUS_DELAY = 300;
|
|
97
94
|
const INPUT_CLEAR_DELAY = 150;
|
|
98
95
|
const SCROLL_REPEAT_COUNT = 10;
|
|
@@ -269,11 +266,22 @@ class ComputerDevice {
|
|
|
269
266
|
const size = await this.size();
|
|
270
267
|
const displays = await ComputerDevice.listDisplays();
|
|
271
268
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
269
|
+
let dpiInfo = '';
|
|
270
|
+
try {
|
|
271
|
+
const screenshotB64 = await this.screenshotBase64();
|
|
272
|
+
const imgInfo = await imageInfoOfBase64(screenshotB64);
|
|
273
|
+
const scaleX = imgInfo.width / size.width;
|
|
274
|
+
const scaleY = imgInfo.height / size.height;
|
|
275
|
+
dpiInfo = `\nScreenshot Size: ${imgInfo.width}x${imgInfo.height} (scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)})`;
|
|
276
|
+
if (1 !== scaleX || 1 !== scaleY) console.warn(`[ComputerDevice] DPI scaling detected! Screen: ${size.width}x${size.height}, Screenshot: ${imgInfo.width}x${imgInfo.height}, Scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)}`);
|
|
277
|
+
} catch (e) {
|
|
278
|
+
dpiInfo = '\nScreenshot Size: unknown (check failed)';
|
|
279
|
+
}
|
|
272
280
|
this.description = `
|
|
273
281
|
Type: Computer
|
|
274
282
|
Platform: ${process.platform}
|
|
275
283
|
Display: ${this.displayId || 'Primary'}
|
|
276
|
-
Screen Size: ${size.width}x${size.height}
|
|
284
|
+
Screen Size: ${size.width}x${size.height}${dpiInfo}
|
|
277
285
|
Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ') : 'Unknown'}${headlessInfo}
|
|
278
286
|
`;
|
|
279
287
|
debugDevice('Computer device connected', this.description);
|
|
@@ -391,10 +399,17 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
391
399
|
const [x, y] = element.center;
|
|
392
400
|
const targetX = Math.round(x);
|
|
393
401
|
const targetY = Math.round(y);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
402
|
+
try {
|
|
403
|
+
const activeHandle = device_libnut.getActiveWindow();
|
|
404
|
+
const title = device_libnut.getWindowTitle(activeHandle);
|
|
405
|
+
const rect = device_libnut.getWindowRect(activeHandle);
|
|
406
|
+
debugDevice(`Tap(${targetX}, ${targetY}) activeWindow: handle=${activeHandle}, title="${title}", rect=(${rect.x},${rect.y},${rect.width},${rect.height})`);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
debugDevice(`Tap(${targetX}, ${targetY}) failed to get window info: ${e}`);
|
|
409
|
+
}
|
|
410
|
+
device_libnut.moveMouse(targetX, targetY);
|
|
411
|
+
await sleep(100);
|
|
412
|
+
device_libnut.mouseClick('left');
|
|
398
413
|
}),
|
|
399
414
|
defineActionDoubleClick(async (param)=>{
|
|
400
415
|
node_assert(device_libnut, 'libnut not initialized');
|
package/dist/es/mcp-server.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { createRequire } from "node:module";
|
|
|
6
6
|
import { getMidsceneLocationSchema, z } from "@midscene/core";
|
|
7
7
|
import { actionHoverParamSchema, defineAction, defineActionClearInput, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
8
8
|
import { sleep } from "@midscene/core/utils";
|
|
9
|
-
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
9
|
+
import { createImgBase64ByFormat, imageInfoOfBase64 } from "@midscene/shared/img";
|
|
10
10
|
import { getDebug } from "@midscene/shared/logger";
|
|
11
11
|
import screenshot_desktop from "screenshot-desktop";
|
|
12
12
|
import { existsSync } from "node:fs";
|
|
@@ -87,12 +87,9 @@ function _define_property(obj, key, value) {
|
|
|
87
87
|
else obj[key] = value;
|
|
88
88
|
return obj;
|
|
89
89
|
}
|
|
90
|
-
const SMOOTH_MOVE_STEPS_TAP = 8;
|
|
91
90
|
const SMOOTH_MOVE_STEPS_MOUSE_MOVE = 10;
|
|
92
|
-
const SMOOTH_MOVE_DELAY_TAP = 8;
|
|
93
91
|
const SMOOTH_MOVE_DELAY_MOUSE_MOVE = 10;
|
|
94
92
|
const MOUSE_MOVE_EFFECT_WAIT = 300;
|
|
95
|
-
const CLICK_HOLD_DURATION = 50;
|
|
96
93
|
const INPUT_FOCUS_DELAY = 300;
|
|
97
94
|
const INPUT_CLEAR_DELAY = 150;
|
|
98
95
|
const SCROLL_REPEAT_COUNT = 10;
|
|
@@ -269,11 +266,22 @@ class ComputerDevice {
|
|
|
269
266
|
const size = await this.size();
|
|
270
267
|
const displays = await ComputerDevice.listDisplays();
|
|
271
268
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
269
|
+
let dpiInfo = '';
|
|
270
|
+
try {
|
|
271
|
+
const screenshotB64 = await this.screenshotBase64();
|
|
272
|
+
const imgInfo = await imageInfoOfBase64(screenshotB64);
|
|
273
|
+
const scaleX = imgInfo.width / size.width;
|
|
274
|
+
const scaleY = imgInfo.height / size.height;
|
|
275
|
+
dpiInfo = `\nScreenshot Size: ${imgInfo.width}x${imgInfo.height} (scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)})`;
|
|
276
|
+
if (1 !== scaleX || 1 !== scaleY) console.warn(`[ComputerDevice] DPI scaling detected! Screen: ${size.width}x${size.height}, Screenshot: ${imgInfo.width}x${imgInfo.height}, Scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)}`);
|
|
277
|
+
} catch (e) {
|
|
278
|
+
dpiInfo = '\nScreenshot Size: unknown (check failed)';
|
|
279
|
+
}
|
|
272
280
|
this.description = `
|
|
273
281
|
Type: Computer
|
|
274
282
|
Platform: ${process.platform}
|
|
275
283
|
Display: ${this.displayId || 'Primary'}
|
|
276
|
-
Screen Size: ${size.width}x${size.height}
|
|
284
|
+
Screen Size: ${size.width}x${size.height}${dpiInfo}
|
|
277
285
|
Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ') : 'Unknown'}${headlessInfo}
|
|
278
286
|
`;
|
|
279
287
|
debugDevice('Computer device connected', this.description);
|
|
@@ -391,10 +399,17 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
391
399
|
const [x, y] = element.center;
|
|
392
400
|
const targetX = Math.round(x);
|
|
393
401
|
const targetY = Math.round(y);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
402
|
+
try {
|
|
403
|
+
const activeHandle = libnut.getActiveWindow();
|
|
404
|
+
const title = libnut.getWindowTitle(activeHandle);
|
|
405
|
+
const rect = libnut.getWindowRect(activeHandle);
|
|
406
|
+
debugDevice(`Tap(${targetX}, ${targetY}) activeWindow: handle=${activeHandle}, title="${title}", rect=(${rect.x},${rect.y},${rect.width},${rect.height})`);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
debugDevice(`Tap(${targetX}, ${targetY}) failed to get window info: ${e}`);
|
|
409
|
+
}
|
|
410
|
+
libnut.moveMouse(targetX, targetY);
|
|
411
|
+
await sleep(100);
|
|
412
|
+
libnut.mouseClick('left');
|
|
398
413
|
}),
|
|
399
414
|
defineActionDoubleClick(async (param)=>{
|
|
400
415
|
node_assert(libnut, 'libnut not initialized');
|
package/dist/lib/cli.js
CHANGED
|
@@ -116,12 +116,9 @@ function _define_property(obj, key, value) {
|
|
|
116
116
|
else obj[key] = value;
|
|
117
117
|
return obj;
|
|
118
118
|
}
|
|
119
|
-
const SMOOTH_MOVE_STEPS_TAP = 8;
|
|
120
119
|
const SMOOTH_MOVE_STEPS_MOUSE_MOVE = 10;
|
|
121
|
-
const SMOOTH_MOVE_DELAY_TAP = 8;
|
|
122
120
|
const SMOOTH_MOVE_DELAY_MOUSE_MOVE = 10;
|
|
123
121
|
const MOUSE_MOVE_EFFECT_WAIT = 300;
|
|
124
|
-
const CLICK_HOLD_DURATION = 50;
|
|
125
122
|
const INPUT_FOCUS_DELAY = 300;
|
|
126
123
|
const INPUT_CLEAR_DELAY = 150;
|
|
127
124
|
const SCROLL_REPEAT_COUNT = 10;
|
|
@@ -298,11 +295,22 @@ class ComputerDevice {
|
|
|
298
295
|
const size = await this.size();
|
|
299
296
|
const displays = await ComputerDevice.listDisplays();
|
|
300
297
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
298
|
+
let dpiInfo = '';
|
|
299
|
+
try {
|
|
300
|
+
const screenshotB64 = await this.screenshotBase64();
|
|
301
|
+
const imgInfo = await (0, img_namespaceObject.imageInfoOfBase64)(screenshotB64);
|
|
302
|
+
const scaleX = imgInfo.width / size.width;
|
|
303
|
+
const scaleY = imgInfo.height / size.height;
|
|
304
|
+
dpiInfo = `\nScreenshot Size: ${imgInfo.width}x${imgInfo.height} (scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)})`;
|
|
305
|
+
if (1 !== scaleX || 1 !== scaleY) console.warn(`[ComputerDevice] DPI scaling detected! Screen: ${size.width}x${size.height}, Screenshot: ${imgInfo.width}x${imgInfo.height}, Scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)}`);
|
|
306
|
+
} catch (e) {
|
|
307
|
+
dpiInfo = '\nScreenshot Size: unknown (check failed)';
|
|
308
|
+
}
|
|
301
309
|
this.description = `
|
|
302
310
|
Type: Computer
|
|
303
311
|
Platform: ${process.platform}
|
|
304
312
|
Display: ${this.displayId || 'Primary'}
|
|
305
|
-
Screen Size: ${size.width}x${size.height}
|
|
313
|
+
Screen Size: ${size.width}x${size.height}${dpiInfo}
|
|
306
314
|
Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ') : 'Unknown'}${headlessInfo}
|
|
307
315
|
`;
|
|
308
316
|
debugDevice('Computer device connected', this.description);
|
|
@@ -420,10 +428,17 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
420
428
|
const [x, y] = element.center;
|
|
421
429
|
const targetX = Math.round(x);
|
|
422
430
|
const targetY = Math.round(y);
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
431
|
+
try {
|
|
432
|
+
const activeHandle = libnut.getActiveWindow();
|
|
433
|
+
const title = libnut.getWindowTitle(activeHandle);
|
|
434
|
+
const rect = libnut.getWindowRect(activeHandle);
|
|
435
|
+
debugDevice(`Tap(${targetX}, ${targetY}) activeWindow: handle=${activeHandle}, title="${title}", rect=(${rect.x},${rect.y},${rect.width},${rect.height})`);
|
|
436
|
+
} catch (e) {
|
|
437
|
+
debugDevice(`Tap(${targetX}, ${targetY}) failed to get window info: ${e}`);
|
|
438
|
+
}
|
|
439
|
+
libnut.moveMouse(targetX, targetY);
|
|
440
|
+
await (0, utils_namespaceObject.sleep)(100);
|
|
441
|
+
libnut.mouseClick('left');
|
|
427
442
|
}),
|
|
428
443
|
(0, device_namespaceObject.defineActionDoubleClick)(async (param)=>{
|
|
429
444
|
external_node_assert_default()(libnut, 'libnut not initialized');
|
package/dist/lib/index.js
CHANGED
|
@@ -135,12 +135,9 @@ function _define_property(obj, key, value) {
|
|
|
135
135
|
else obj[key] = value;
|
|
136
136
|
return obj;
|
|
137
137
|
}
|
|
138
|
-
const SMOOTH_MOVE_STEPS_TAP = 8;
|
|
139
138
|
const SMOOTH_MOVE_STEPS_MOUSE_MOVE = 10;
|
|
140
|
-
const SMOOTH_MOVE_DELAY_TAP = 8;
|
|
141
139
|
const SMOOTH_MOVE_DELAY_MOUSE_MOVE = 10;
|
|
142
140
|
const MOUSE_MOVE_EFFECT_WAIT = 300;
|
|
143
|
-
const CLICK_HOLD_DURATION = 50;
|
|
144
141
|
const INPUT_FOCUS_DELAY = 300;
|
|
145
142
|
const INPUT_CLEAR_DELAY = 150;
|
|
146
143
|
const SCROLL_REPEAT_COUNT = 10;
|
|
@@ -317,11 +314,22 @@ class ComputerDevice {
|
|
|
317
314
|
const size = await this.size();
|
|
318
315
|
const displays = await ComputerDevice.listDisplays();
|
|
319
316
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
317
|
+
let dpiInfo = '';
|
|
318
|
+
try {
|
|
319
|
+
const screenshotB64 = await this.screenshotBase64();
|
|
320
|
+
const imgInfo = await (0, img_namespaceObject.imageInfoOfBase64)(screenshotB64);
|
|
321
|
+
const scaleX = imgInfo.width / size.width;
|
|
322
|
+
const scaleY = imgInfo.height / size.height;
|
|
323
|
+
dpiInfo = `\nScreenshot Size: ${imgInfo.width}x${imgInfo.height} (scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)})`;
|
|
324
|
+
if (1 !== scaleX || 1 !== scaleY) console.warn(`[ComputerDevice] DPI scaling detected! Screen: ${size.width}x${size.height}, Screenshot: ${imgInfo.width}x${imgInfo.height}, Scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)}`);
|
|
325
|
+
} catch (e) {
|
|
326
|
+
dpiInfo = '\nScreenshot Size: unknown (check failed)';
|
|
327
|
+
}
|
|
320
328
|
this.description = `
|
|
321
329
|
Type: Computer
|
|
322
330
|
Platform: ${process.platform}
|
|
323
331
|
Display: ${this.displayId || 'Primary'}
|
|
324
|
-
Screen Size: ${size.width}x${size.height}
|
|
332
|
+
Screen Size: ${size.width}x${size.height}${dpiInfo}
|
|
325
333
|
Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ') : 'Unknown'}${headlessInfo}
|
|
326
334
|
`;
|
|
327
335
|
debugDevice('Computer device connected', this.description);
|
|
@@ -439,10 +447,17 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
439
447
|
const [x, y] = element.center;
|
|
440
448
|
const targetX = Math.round(x);
|
|
441
449
|
const targetY = Math.round(y);
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
450
|
+
try {
|
|
451
|
+
const activeHandle = device_libnut.getActiveWindow();
|
|
452
|
+
const title = device_libnut.getWindowTitle(activeHandle);
|
|
453
|
+
const rect = device_libnut.getWindowRect(activeHandle);
|
|
454
|
+
debugDevice(`Tap(${targetX}, ${targetY}) activeWindow: handle=${activeHandle}, title="${title}", rect=(${rect.x},${rect.y},${rect.width},${rect.height})`);
|
|
455
|
+
} catch (e) {
|
|
456
|
+
debugDevice(`Tap(${targetX}, ${targetY}) failed to get window info: ${e}`);
|
|
457
|
+
}
|
|
458
|
+
device_libnut.moveMouse(targetX, targetY);
|
|
459
|
+
await (0, utils_namespaceObject.sleep)(100);
|
|
460
|
+
device_libnut.mouseClick('left');
|
|
446
461
|
}),
|
|
447
462
|
(0, device_namespaceObject.defineActionDoubleClick)(async (param)=>{
|
|
448
463
|
external_node_assert_default()(device_libnut, 'libnut not initialized');
|
package/dist/lib/mcp-server.js
CHANGED
|
@@ -131,12 +131,9 @@ function _define_property(obj, key, value) {
|
|
|
131
131
|
else obj[key] = value;
|
|
132
132
|
return obj;
|
|
133
133
|
}
|
|
134
|
-
const SMOOTH_MOVE_STEPS_TAP = 8;
|
|
135
134
|
const SMOOTH_MOVE_STEPS_MOUSE_MOVE = 10;
|
|
136
|
-
const SMOOTH_MOVE_DELAY_TAP = 8;
|
|
137
135
|
const SMOOTH_MOVE_DELAY_MOUSE_MOVE = 10;
|
|
138
136
|
const MOUSE_MOVE_EFFECT_WAIT = 300;
|
|
139
|
-
const CLICK_HOLD_DURATION = 50;
|
|
140
137
|
const INPUT_FOCUS_DELAY = 300;
|
|
141
138
|
const INPUT_CLEAR_DELAY = 150;
|
|
142
139
|
const SCROLL_REPEAT_COUNT = 10;
|
|
@@ -313,11 +310,22 @@ class ComputerDevice {
|
|
|
313
310
|
const size = await this.size();
|
|
314
311
|
const displays = await ComputerDevice.listDisplays();
|
|
315
312
|
const headlessInfo = this.xvfbInstance ? `\nHeadless: true (Xvfb on ${this.xvfbInstance.display})` : '';
|
|
313
|
+
let dpiInfo = '';
|
|
314
|
+
try {
|
|
315
|
+
const screenshotB64 = await this.screenshotBase64();
|
|
316
|
+
const imgInfo = await (0, img_namespaceObject.imageInfoOfBase64)(screenshotB64);
|
|
317
|
+
const scaleX = imgInfo.width / size.width;
|
|
318
|
+
const scaleY = imgInfo.height / size.height;
|
|
319
|
+
dpiInfo = `\nScreenshot Size: ${imgInfo.width}x${imgInfo.height} (scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)})`;
|
|
320
|
+
if (1 !== scaleX || 1 !== scaleY) console.warn(`[ComputerDevice] DPI scaling detected! Screen: ${size.width}x${size.height}, Screenshot: ${imgInfo.width}x${imgInfo.height}, Scale: ${scaleX.toFixed(2)}x${scaleY.toFixed(2)}`);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
dpiInfo = '\nScreenshot Size: unknown (check failed)';
|
|
323
|
+
}
|
|
316
324
|
this.description = `
|
|
317
325
|
Type: Computer
|
|
318
326
|
Platform: ${process.platform}
|
|
319
327
|
Display: ${this.displayId || 'Primary'}
|
|
320
|
-
Screen Size: ${size.width}x${size.height}
|
|
328
|
+
Screen Size: ${size.width}x${size.height}${dpiInfo}
|
|
321
329
|
Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ') : 'Unknown'}${headlessInfo}
|
|
322
330
|
`;
|
|
323
331
|
debugDevice('Computer device connected', this.description);
|
|
@@ -435,10 +443,17 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
435
443
|
const [x, y] = element.center;
|
|
436
444
|
const targetX = Math.round(x);
|
|
437
445
|
const targetY = Math.round(y);
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
446
|
+
try {
|
|
447
|
+
const activeHandle = libnut.getActiveWindow();
|
|
448
|
+
const title = libnut.getWindowTitle(activeHandle);
|
|
449
|
+
const rect = libnut.getWindowRect(activeHandle);
|
|
450
|
+
debugDevice(`Tap(${targetX}, ${targetY}) activeWindow: handle=${activeHandle}, title="${title}", rect=(${rect.x},${rect.y},${rect.width},${rect.height})`);
|
|
451
|
+
} catch (e) {
|
|
452
|
+
debugDevice(`Tap(${targetX}, ${targetY}) failed to get window info: ${e}`);
|
|
453
|
+
}
|
|
454
|
+
libnut.moveMouse(targetX, targetY);
|
|
455
|
+
await (0, utils_namespaceObject.sleep)(100);
|
|
456
|
+
libnut.mouseClick('left');
|
|
442
457
|
}),
|
|
443
458
|
(0, device_namespaceObject.defineActionDoubleClick)(async (param)=>{
|
|
444
459
|
external_node_assert_default()(libnut, 'libnut not initialized');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/computer",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.8-beta-20260226063853.0",
|
|
4
4
|
"description": "Midscene.js Computer Desktop Automation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@computer-use/libnut": "^4.2.0",
|
|
37
37
|
"clipboardy": "^4.0.0",
|
|
38
38
|
"screenshot-desktop": "^1.15.3",
|
|
39
|
-
"@midscene/shared": "1.4.
|
|
40
|
-
"@midscene/core": "1.4.
|
|
39
|
+
"@midscene/shared": "1.4.8-beta-20260226063853.0",
|
|
40
|
+
"@midscene/core": "1.4.8-beta-20260226063853.0"
|
|
41
41
|
},
|
|
42
42
|
"optionalDependencies": {
|
|
43
43
|
"node-mac-permissions": "2.5.0"
|