@midscene/web 1.17.5-beta-20261102094111.0 → 1.17.6
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/agent-tools-cdp.mjs +16 -9
- package/dist/es/agent-tools-cdp.mjs.map +1 -1
- package/dist/es/agent-tools-puppeteer.mjs +14 -7
- package/dist/es/agent-tools-puppeteer.mjs.map +1 -1
- package/dist/es/agent-tools-tabs.mjs +83 -0
- package/dist/es/agent-tools-tabs.mjs.map +1 -0
- package/dist/es/agent-tools.mjs +65 -31
- package/dist/es/agent-tools.mjs.map +1 -1
- package/dist/es/bridge-mode/common.mjs.map +1 -1
- package/dist/es/bridge-mode/io-client.mjs +1 -1
- package/dist/es/bridge-mode/io-server.mjs +2 -2
- package/dist/es/bridge-mode/io-server.mjs.map +1 -1
- package/dist/es/bridge-mode/page-browser-side.mjs +6 -4
- package/dist/es/bridge-mode/page-browser-side.mjs.map +1 -1
- package/dist/es/cdp-target-store.mjs +12 -5
- package/dist/es/cdp-target-store.mjs.map +1 -1
- package/dist/es/cli.mjs +1 -1
- package/dist/es/playwright/reporter/index.mjs +4 -59
- package/dist/es/playwright/reporter/index.mjs.map +1 -1
- package/dist/es/puppeteer/base-page.mjs +45 -118
- package/dist/es/puppeteer/base-page.mjs.map +1 -1
- package/dist/lib/agent-tools-cdp.js +17 -10
- package/dist/lib/agent-tools-cdp.js.map +1 -1
- package/dist/lib/agent-tools-puppeteer.js +15 -8
- package/dist/lib/agent-tools-puppeteer.js.map +1 -1
- package/dist/lib/agent-tools-tabs.js +126 -0
- package/dist/lib/agent-tools-tabs.js.map +1 -0
- package/dist/lib/agent-tools.js +65 -31
- package/dist/lib/agent-tools.js.map +1 -1
- package/dist/lib/bridge-mode/common.js.map +1 -1
- package/dist/lib/bridge-mode/io-client.js +1 -1
- package/dist/lib/bridge-mode/io-server.js +2 -2
- package/dist/lib/bridge-mode/io-server.js.map +1 -1
- package/dist/lib/bridge-mode/page-browser-side.js +6 -4
- package/dist/lib/bridge-mode/page-browser-side.js.map +1 -1
- package/dist/lib/cdp-target-store.js +12 -5
- package/dist/lib/cdp-target-store.js.map +1 -1
- package/dist/lib/cli.js +1 -1
- package/dist/lib/playwright/reporter/index.js +2 -57
- package/dist/lib/playwright/reporter/index.js.map +1 -1
- package/dist/lib/puppeteer/base-page.js +44 -117
- package/dist/lib/puppeteer/base-page.js.map +1 -1
- package/dist/types/agent-tools-cdp.d.ts +3 -3
- package/dist/types/agent-tools-cdp.d.ts.map +1 -1
- package/dist/types/agent-tools-puppeteer.d.ts +3 -3
- package/dist/types/agent-tools-puppeteer.d.ts.map +1 -1
- package/dist/types/agent-tools-tabs.d.ts +20 -0
- package/dist/types/agent-tools-tabs.d.ts.map +1 -0
- package/dist/types/agent-tools.d.ts +3 -0
- package/dist/types/agent-tools.d.ts.map +1 -1
- package/dist/types/bridge-mode/common.d.ts +5 -0
- package/dist/types/bridge-mode/common.d.ts.map +1 -1
- package/dist/types/bridge-mode/page-browser-side.d.ts.map +1 -1
- package/dist/types/cdp-target-store.d.ts.map +1 -1
- package/dist/types/playwright/reporter/index.d.ts +0 -2
- package/dist/types/playwright/reporter/index.d.ts.map +1 -1
- package/dist/types/puppeteer/base-page.d.ts +0 -3
- package/dist/types/puppeteer/base-page.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -215,71 +215,44 @@ class Page {
|
|
|
215
215
|
return captureElementSnapshot;
|
|
216
216
|
}
|
|
217
217
|
async size() {
|
|
218
|
-
|
|
219
|
-
const sizeInfo = await this.evaluate(()=>({
|
|
218
|
+
return this.evaluate(()=>({
|
|
220
219
|
width: window.innerWidth,
|
|
221
220
|
height: window.innerHeight
|
|
222
221
|
}));
|
|
223
|
-
this.viewportSize = sizeInfo;
|
|
224
|
-
return sizeInfo;
|
|
225
222
|
}
|
|
226
223
|
async screenshotBase64() {
|
|
227
224
|
const imgType = 'jpeg';
|
|
228
225
|
const quality = 90;
|
|
229
226
|
const startTime = Date.now();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
227
|
+
debugPage('screenshotBase64 begin');
|
|
228
|
+
let base64;
|
|
229
|
+
if ('puppeteer' === this.interfaceType) {
|
|
230
|
+
const result = await (0, external_screenshot_js_namespaceObject.capturePuppeteerScreenshot)(this.underlyingPage, {
|
|
231
|
+
type: imgType,
|
|
232
|
+
quality,
|
|
233
|
+
encoding: 'base64'
|
|
234
|
+
});
|
|
235
|
+
base64 = (0, img_namespaceObject.createImgBase64ByFormat)(imgType, result);
|
|
236
|
+
} else if ('playwright' === this.interfaceType) {
|
|
237
|
+
const page = this.underlyingPage;
|
|
238
|
+
try {
|
|
239
|
+
const buffer = await page.screenshot({
|
|
240
240
|
type: imgType,
|
|
241
241
|
quality,
|
|
242
|
-
|
|
242
|
+
timeout: 10000
|
|
243
243
|
});
|
|
244
|
-
base64 = (0, img_namespaceObject.createImgBase64ByFormat)(imgType,
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
257
|
-
warnPage(`[Midscene] Playwright screenshot failed: ${errorMsg}. Falling back to CDP screenshot.`);
|
|
258
|
-
debugPage('playwright screenshot failed, trying CDP fallback: %s', error);
|
|
259
|
-
source = 'cdp-fallback';
|
|
260
|
-
debugPage('screenshotBase64 fallback %o', {
|
|
261
|
-
...operation,
|
|
262
|
-
source
|
|
263
|
-
});
|
|
264
|
-
base64 = await this.screenshotBase64ByPlaywrightCdp(imgType, quality);
|
|
265
|
-
}
|
|
266
|
-
} else throw new Error('Unsupported page type for screenshot');
|
|
267
|
-
const endTime = Date.now();
|
|
268
|
-
debugPage('screenshotBase64 end %o', {
|
|
269
|
-
...operation,
|
|
270
|
-
source,
|
|
271
|
-
durationMs: endTime - startTime,
|
|
272
|
-
screenshotHash: (0, shared_utils_namespaceObject.sha256Hex)(base64).slice(0, 16)
|
|
273
|
-
});
|
|
274
|
-
return base64;
|
|
275
|
-
} catch (error) {
|
|
276
|
-
debugPage('screenshotBase64 error %o', {
|
|
277
|
-
...operation,
|
|
278
|
-
source,
|
|
279
|
-
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
280
|
-
});
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
244
|
+
base64 = (0, img_namespaceObject.createImgBase64ByFormat)(imgType, buffer.toString('base64'));
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (isClosedPageError(error) || page.isClosed()) throw error;
|
|
247
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
248
|
+
console.warn(`[Midscene] Playwright screenshot failed: ${errorMsg}. Falling back to CDP screenshot.`);
|
|
249
|
+
debugPage('playwright screenshot failed, trying CDP fallback: %s', error);
|
|
250
|
+
base64 = await this.screenshotBase64ByPlaywrightCdp(imgType, quality);
|
|
251
|
+
}
|
|
252
|
+
} else throw new Error('Unsupported page type for screenshot');
|
|
253
|
+
const endTime = Date.now();
|
|
254
|
+
debugPage(`screenshotBase64 end, cost: ${endTime - startTime}ms`);
|
|
255
|
+
return base64;
|
|
283
256
|
}
|
|
284
257
|
async screenshotBase64ByPlaywrightCdp(imgType, quality) {
|
|
285
258
|
const client = await this.createPageCdpSession('CDP screenshot fallback');
|
|
@@ -576,47 +549,23 @@ class Page {
|
|
|
576
549
|
get mouse() {
|
|
577
550
|
return {
|
|
578
551
|
click: async (x, y, options)=>{
|
|
579
|
-
|
|
580
|
-
const operation = {
|
|
581
|
-
pageId: this.diagnosticPageId,
|
|
582
|
-
operationId: ++this.diagnosticOperationSequence
|
|
583
|
-
};
|
|
584
|
-
debugPage('mouse click begin %o', operation);
|
|
552
|
+
await this.mouse.move(x, y);
|
|
585
553
|
const { button = 'left', count = 1 } = options || {};
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
554
|
+
debugPage(`mouse click ${x}, ${y}, ${button}, ${count}`);
|
|
555
|
+
if (2 === count && 'playwright' === this.interfaceType) await this.underlyingPage.mouse.dblclick(x, y, {
|
|
556
|
+
button
|
|
557
|
+
});
|
|
558
|
+
else if ('puppeteer' === this.interfaceType) {
|
|
559
|
+
const page = this.underlyingPage;
|
|
560
|
+
if ('left' === button && 1 === count) await page.mouse.click(x, y);
|
|
561
|
+
else await page.mouse.click(x, y, {
|
|
592
562
|
button,
|
|
593
563
|
count
|
|
594
564
|
});
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const page = this.underlyingPage;
|
|
600
|
-
if ('left' === button && 1 === count) await page.mouse.click(x, y);
|
|
601
|
-
else await page.mouse.click(x, y, {
|
|
602
|
-
button,
|
|
603
|
-
count
|
|
604
|
-
});
|
|
605
|
-
} else if ('playwright' === this.interfaceType) await this.underlyingPage.mouse.click(x, y, {
|
|
606
|
-
button,
|
|
607
|
-
clickCount: count
|
|
608
|
-
});
|
|
609
|
-
debugPage('mouse click returned %o', {
|
|
610
|
-
...operation,
|
|
611
|
-
durationMs: Date.now() - startedAt
|
|
612
|
-
});
|
|
613
|
-
} catch (error) {
|
|
614
|
-
debugPage('mouse click error %o', {
|
|
615
|
-
...operation,
|
|
616
|
-
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
617
|
-
});
|
|
618
|
-
throw error;
|
|
619
|
-
}
|
|
565
|
+
} else if ('playwright' === this.interfaceType) await this.underlyingPage.mouse.click(x, y, {
|
|
566
|
+
button,
|
|
567
|
+
clickCount: count
|
|
568
|
+
});
|
|
620
569
|
},
|
|
621
570
|
wheel: async (deltaX, deltaY)=>{
|
|
622
571
|
debugPage(`mouse wheel ${deltaX}, ${deltaY}`);
|
|
@@ -855,29 +804,10 @@ class Page {
|
|
|
855
804
|
if (this.onBeforeInvokeAction) await this.onBeforeInvokeAction(name, param);
|
|
856
805
|
}
|
|
857
806
|
async defaultActionWait(name, _param) {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
actionName: name
|
|
863
|
-
};
|
|
864
|
-
debugPage('defaultActionWait begin %o', operation);
|
|
865
|
-
try {
|
|
866
|
-
await Promise.all([
|
|
867
|
-
this.waitForNavigation('afterInvokeAction', name),
|
|
868
|
-
this.waitForNetworkIdle('afterInvokeAction', name)
|
|
869
|
-
]);
|
|
870
|
-
debugPage('defaultActionWait end %o', {
|
|
871
|
-
...operation,
|
|
872
|
-
durationMs: Date.now() - startedAt
|
|
873
|
-
});
|
|
874
|
-
} catch (error) {
|
|
875
|
-
debugPage('defaultActionWait error %o', {
|
|
876
|
-
...operation,
|
|
877
|
-
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
878
|
-
});
|
|
879
|
-
throw error;
|
|
880
|
-
}
|
|
807
|
+
await Promise.all([
|
|
808
|
+
this.waitForNavigation('afterInvokeAction', name),
|
|
809
|
+
this.waitForNetworkIdle('afterInvokeAction', name)
|
|
810
|
+
]);
|
|
881
811
|
}
|
|
882
812
|
async afterInvokeAction(name, param) {
|
|
883
813
|
if (this.onAfterInvokeAction) await this.onAfterInvokeAction(name, param);
|
|
@@ -1053,11 +983,8 @@ class Page {
|
|
|
1053
983
|
}
|
|
1054
984
|
constructor(underlyingPage, interfaceType, opts){
|
|
1055
985
|
_define_property(this, "underlyingPage", void 0);
|
|
1056
|
-
_define_property(this, "diagnosticPageId", (0, shared_utils_namespaceObject.uuid)());
|
|
1057
|
-
_define_property(this, "diagnosticOperationSequence", 0);
|
|
1058
986
|
_define_property(this, "waitForNavigationTimeout", void 0);
|
|
1059
987
|
_define_property(this, "waitForNetworkIdleTimeout", void 0);
|
|
1060
|
-
_define_property(this, "viewportSize", void 0);
|
|
1061
988
|
_define_property(this, "onBeforeInvokeAction", void 0);
|
|
1062
989
|
_define_property(this, "onAfterInvokeAction", void 0);
|
|
1063
990
|
_define_property(this, "customActions", void 0);
|