@rpascene/web 0.30.8
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/README.md +9 -0
- package/bin/midscene-playground +3 -0
- package/dist/es/bin.mjs +26 -0
- package/dist/es/bin.mjs.map +1 -0
- package/dist/es/bridge-mode/agent-cli-side.mjs +117 -0
- package/dist/es/bridge-mode/agent-cli-side.mjs.map +1 -0
- package/dist/es/bridge-mode/browser.mjs +2 -0
- package/dist/es/bridge-mode/common.mjs +37 -0
- package/dist/es/bridge-mode/common.mjs.map +1 -0
- package/dist/es/bridge-mode/index.mjs +4 -0
- package/dist/es/bridge-mode/io-client.mjs +101 -0
- package/dist/es/bridge-mode/io-client.mjs.map +1 -0
- package/dist/es/bridge-mode/io-server.mjs +208 -0
- package/dist/es/bridge-mode/io-server.mjs.map +1 -0
- package/dist/es/bridge-mode/page-browser-side.mjs +103 -0
- package/dist/es/bridge-mode/page-browser-side.mjs.map +1 -0
- package/dist/es/chrome-extension/agent.mjs +9 -0
- package/dist/es/chrome-extension/agent.mjs.map +1 -0
- package/dist/es/chrome-extension/cdpInput.mjs +174 -0
- package/dist/es/chrome-extension/cdpInput.mjs.LICENSE.txt +5 -0
- package/dist/es/chrome-extension/cdpInput.mjs.map +1 -0
- package/dist/es/chrome-extension/dynamic-scripts.mjs +37 -0
- package/dist/es/chrome-extension/dynamic-scripts.mjs.map +1 -0
- package/dist/es/chrome-extension/index.mjs +5 -0
- package/dist/es/chrome-extension/page.mjs +633 -0
- package/dist/es/chrome-extension/page.mjs.map +1 -0
- package/dist/es/index.mjs +6 -0
- package/dist/es/playwright/ai-fixture.mjs +325 -0
- package/dist/es/playwright/ai-fixture.mjs.map +1 -0
- package/dist/es/playwright/index.mjs +23 -0
- package/dist/es/playwright/index.mjs.map +1 -0
- package/dist/es/playwright/page.mjs +9 -0
- package/dist/es/playwright/page.mjs.map +1 -0
- package/dist/es/playwright/reporter/index.mjs +90 -0
- package/dist/es/playwright/reporter/index.mjs.map +1 -0
- package/dist/es/puppeteer/agent-launcher.mjs +132 -0
- package/dist/es/puppeteer/agent-launcher.mjs.map +1 -0
- package/dist/es/puppeteer/base-page.mjs +491 -0
- package/dist/es/puppeteer/base-page.mjs.map +1 -0
- package/dist/es/puppeteer/index.mjs +17 -0
- package/dist/es/puppeteer/index.mjs.map +1 -0
- package/dist/es/puppeteer/page.mjs +9 -0
- package/dist/es/puppeteer/page.mjs.map +1 -0
- package/dist/es/static/index.mjs +3 -0
- package/dist/es/static/static-agent.mjs +10 -0
- package/dist/es/static/static-agent.mjs.map +1 -0
- package/dist/es/static/static-page.mjs +132 -0
- package/dist/es/static/static-page.mjs.map +1 -0
- package/dist/es/web-element.mjs +96 -0
- package/dist/es/web-element.mjs.map +1 -0
- package/dist/es/web-page.mjs +206 -0
- package/dist/es/web-page.mjs.map +1 -0
- package/dist/lib/bin.js +54 -0
- package/dist/lib/bin.js.map +1 -0
- package/dist/lib/bridge-mode/agent-cli-side.js +154 -0
- package/dist/lib/bridge-mode/agent-cli-side.js.map +1 -0
- package/dist/lib/bridge-mode/browser.js +38 -0
- package/dist/lib/bridge-mode/browser.js.map +1 -0
- package/dist/lib/bridge-mode/common.js +95 -0
- package/dist/lib/bridge-mode/common.js.map +1 -0
- package/dist/lib/bridge-mode/index.js +46 -0
- package/dist/lib/bridge-mode/index.js.map +1 -0
- package/dist/lib/bridge-mode/io-client.js +135 -0
- package/dist/lib/bridge-mode/io-client.js.map +1 -0
- package/dist/lib/bridge-mode/io-server.js +245 -0
- package/dist/lib/bridge-mode/io-server.js.map +1 -0
- package/dist/lib/bridge-mode/page-browser-side.js +147 -0
- package/dist/lib/bridge-mode/page-browser-side.js.map +1 -0
- package/dist/lib/chrome-extension/agent.js +43 -0
- package/dist/lib/chrome-extension/agent.js.map +1 -0
- package/dist/lib/chrome-extension/cdpInput.js +208 -0
- package/dist/lib/chrome-extension/cdpInput.js.LICENSE.txt +5 -0
- package/dist/lib/chrome-extension/cdpInput.js.map +1 -0
- package/dist/lib/chrome-extension/dynamic-scripts.js +77 -0
- package/dist/lib/chrome-extension/dynamic-scripts.js.map +1 -0
- package/dist/lib/chrome-extension/index.js +60 -0
- package/dist/lib/chrome-extension/index.js.map +1 -0
- package/dist/lib/chrome-extension/page.js +667 -0
- package/dist/lib/chrome-extension/page.js.map +1 -0
- package/dist/lib/index.js +60 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/playwright/ai-fixture.js +362 -0
- package/dist/lib/playwright/ai-fixture.js.map +1 -0
- package/dist/lib/playwright/index.js +66 -0
- package/dist/lib/playwright/index.js.map +1 -0
- package/dist/lib/playwright/page.js +43 -0
- package/dist/lib/playwright/page.js.map +1 -0
- package/dist/lib/playwright/reporter/index.js +124 -0
- package/dist/lib/playwright/reporter/index.js.map +1 -0
- package/dist/lib/puppeteer/agent-launcher.js +194 -0
- package/dist/lib/puppeteer/agent-launcher.js.map +1 -0
- package/dist/lib/puppeteer/base-page.js +531 -0
- package/dist/lib/puppeteer/base-page.js.map +1 -0
- package/dist/lib/puppeteer/index.js +57 -0
- package/dist/lib/puppeteer/index.js.map +1 -0
- package/dist/lib/puppeteer/page.js +43 -0
- package/dist/lib/puppeteer/page.js.map +1 -0
- package/dist/lib/static/index.js +52 -0
- package/dist/lib/static/index.js.map +1 -0
- package/dist/lib/static/static-agent.js +44 -0
- package/dist/lib/static/static-agent.js.map +1 -0
- package/dist/lib/static/static-page.js +166 -0
- package/dist/lib/static/static-page.js.map +1 -0
- package/dist/lib/web-element.js +136 -0
- package/dist/lib/web-element.js.map +1 -0
- package/dist/lib/web-page.js +256 -0
- package/dist/lib/web-page.js.map +1 -0
- package/dist/types/bin.d.ts +1 -0
- package/dist/types/bridge-mode/agent-cli-side.d.ts +32 -0
- package/dist/types/bridge-mode/browser.d.ts +2 -0
- package/dist/types/bridge-mode/common.d.ts +60 -0
- package/dist/types/bridge-mode/index.d.ts +4 -0
- package/dist/types/bridge-mode/io-client.d.ts +10 -0
- package/dist/types/bridge-mode/io-server.d.ts +26 -0
- package/dist/types/bridge-mode/page-browser-side.d.ts +18 -0
- package/dist/types/chrome-extension/agent.d.ts +5 -0
- package/dist/types/chrome-extension/cdpInput.d.ts +52 -0
- package/dist/types/chrome-extension/dynamic-scripts.d.ts +3 -0
- package/dist/types/chrome-extension/index.d.ts +5 -0
- package/dist/types/chrome-extension/page.d.ts +95 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/playwright/ai-fixture.d.ts +117 -0
- package/dist/types/playwright/index.d.ts +12 -0
- package/dist/types/playwright/page.d.ts +6 -0
- package/dist/types/playwright/reporter/index.d.ts +18 -0
- package/dist/types/puppeteer/agent-launcher.d.ts +29 -0
- package/dist/types/puppeteer/base-page.d.ts +90 -0
- package/dist/types/puppeteer/index.d.ts +9 -0
- package/dist/types/puppeteer/page.d.ts +6 -0
- package/dist/types/static/index.d.ts +2 -0
- package/dist/types/static/static-agent.d.ts +5 -0
- package/dist/types/static/static-page.d.ts +52 -0
- package/dist/types/web-element.d.ts +51 -0
- package/dist/types/web-page.d.ts +59 -0
- package/package.json +164 -0
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>ChromeExtensionProxyPage
|
|
28
|
+
});
|
|
29
|
+
const external_web_element_js_namespaceObject = require("../web-element.js");
|
|
30
|
+
const extractor_namespaceObject = require("@rpascene/shared/extractor");
|
|
31
|
+
const img_namespaceObject = require("@rpascene/shared/img");
|
|
32
|
+
const utils_namespaceObject = require("@rpascene/shared/utils");
|
|
33
|
+
const external_web_page_js_namespaceObject = require("../web-page.js");
|
|
34
|
+
const external_cdpInput_js_namespaceObject = require("./cdpInput.js");
|
|
35
|
+
const external_dynamic_scripts_js_namespaceObject = require("./dynamic-scripts.js");
|
|
36
|
+
function _define_property(obj, key, value) {
|
|
37
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
38
|
+
value: value,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true
|
|
42
|
+
});
|
|
43
|
+
else obj[key] = value;
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
function sleep(ms) {
|
|
47
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
48
|
+
}
|
|
49
|
+
class ChromeExtensionProxyPage {
|
|
50
|
+
actionSpace() {
|
|
51
|
+
return (0, external_web_page_js_namespaceObject.commonWebActionsForWebPage)(this);
|
|
52
|
+
}
|
|
53
|
+
async setActiveTabId(tabId) {
|
|
54
|
+
if (this.activeTabId) throw new Error(`Active tab id is already set, which is ${this.activeTabId}, cannot set it to ${tabId}`);
|
|
55
|
+
await chrome.tabs.update(tabId, {
|
|
56
|
+
active: true
|
|
57
|
+
});
|
|
58
|
+
this.activeTabId = tabId;
|
|
59
|
+
}
|
|
60
|
+
async getActiveTabId() {
|
|
61
|
+
return this.activeTabId;
|
|
62
|
+
}
|
|
63
|
+
async getBrowserTabList() {
|
|
64
|
+
const tabs = await chrome.tabs.query({
|
|
65
|
+
currentWindow: true
|
|
66
|
+
});
|
|
67
|
+
return tabs.map((tab)=>({
|
|
68
|
+
id: `${tab.id}`,
|
|
69
|
+
title: tab.title,
|
|
70
|
+
url: tab.url,
|
|
71
|
+
currentActiveTab: tab.active
|
|
72
|
+
})).filter((tab)=>tab.id && tab.title && tab.url);
|
|
73
|
+
}
|
|
74
|
+
async getTabIdOrConnectToCurrentTab() {
|
|
75
|
+
if (this.activeTabId) return this.activeTabId;
|
|
76
|
+
const tabId = await chrome.tabs.query({
|
|
77
|
+
active: true,
|
|
78
|
+
currentWindow: true
|
|
79
|
+
}).then((tabs)=>{
|
|
80
|
+
var _tabs_;
|
|
81
|
+
return null == (_tabs_ = tabs[0]) ? void 0 : _tabs_.id;
|
|
82
|
+
});
|
|
83
|
+
this.activeTabId = tabId || 0;
|
|
84
|
+
return this.activeTabId;
|
|
85
|
+
}
|
|
86
|
+
async attachDebugger() {
|
|
87
|
+
(0, utils_namespaceObject.assert)(!this.destroyed, 'Page is destroyed');
|
|
88
|
+
if (this.attachingDebugger) return void await this.attachingDebugger;
|
|
89
|
+
this.attachingDebugger = (async ()=>{
|
|
90
|
+
const url = await this.url();
|
|
91
|
+
let error = null;
|
|
92
|
+
if (url.startsWith('chrome://')) throw new Error('Cannot attach debugger to chrome:// pages, please use Rpascene in a normal page with http://, https:// or file://');
|
|
93
|
+
try {
|
|
94
|
+
const currentTabId = await this.getTabIdOrConnectToCurrentTab();
|
|
95
|
+
if (this.tabIdOfDebuggerAttached === currentTabId) return;
|
|
96
|
+
if (this.tabIdOfDebuggerAttached && this.tabIdOfDebuggerAttached !== currentTabId) {
|
|
97
|
+
console.log('detach the previous tab', this.tabIdOfDebuggerAttached, '->', currentTabId);
|
|
98
|
+
try {
|
|
99
|
+
await this.detachDebugger(this.tabIdOfDebuggerAttached);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Failed to detach debugger', error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
console.log('attaching debugger', currentTabId);
|
|
105
|
+
try {
|
|
106
|
+
await chrome.debugger.attach({
|
|
107
|
+
tabId: currentTabId
|
|
108
|
+
}, '1.3');
|
|
109
|
+
} catch (e) {
|
|
110
|
+
if (this._continueWhenFailedToAttachDebugger) console.warn("Failed to attach debugger, but the script will continue as if the debugger is attached since the _continueWhenFailedToAttachDebugger is true", e);
|
|
111
|
+
else throw e;
|
|
112
|
+
}
|
|
113
|
+
await sleep(500);
|
|
114
|
+
this.tabIdOfDebuggerAttached = currentTabId;
|
|
115
|
+
await this.enableWaterFlowAnimation();
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.error('Failed to attach debugger', e);
|
|
118
|
+
error = e;
|
|
119
|
+
} finally{
|
|
120
|
+
this.attachingDebugger = null;
|
|
121
|
+
}
|
|
122
|
+
if (error) throw error;
|
|
123
|
+
})();
|
|
124
|
+
await this.attachingDebugger;
|
|
125
|
+
}
|
|
126
|
+
async showMousePointer(x, y) {
|
|
127
|
+
const pointerScript = `(() => {
|
|
128
|
+
if(typeof window.rpasceneWaterFlowAnimation !== 'undefined') {
|
|
129
|
+
window.rpasceneWaterFlowAnimation.enable();
|
|
130
|
+
window.rpasceneWaterFlowAnimation.showMousePointer(${x}, ${y});
|
|
131
|
+
} else {
|
|
132
|
+
console.log('rpasceneWaterFlowAnimation is not defined');
|
|
133
|
+
}
|
|
134
|
+
})()`;
|
|
135
|
+
await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
136
|
+
expression: `${pointerScript}`
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async hideMousePointer() {
|
|
140
|
+
await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
141
|
+
expression: `(() => {
|
|
142
|
+
if(typeof window.rpasceneWaterFlowAnimation !== 'undefined') {
|
|
143
|
+
window.rpasceneWaterFlowAnimation.hideMousePointer();
|
|
144
|
+
}
|
|
145
|
+
})()`
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async detachDebugger(tabId) {
|
|
149
|
+
const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;
|
|
150
|
+
console.log('detaching debugger', tabIdToDetach);
|
|
151
|
+
if (!tabIdToDetach) return void console.warn('No tab id to detach');
|
|
152
|
+
try {
|
|
153
|
+
await this.disableWaterFlowAnimation(tabIdToDetach);
|
|
154
|
+
await sleep(200);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.warn('Failed to disable water flow animation', error);
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
await chrome.debugger.detach({
|
|
160
|
+
tabId: tabIdToDetach
|
|
161
|
+
});
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.warn('Failed to detach debugger', error);
|
|
164
|
+
}
|
|
165
|
+
this.tabIdOfDebuggerAttached = null;
|
|
166
|
+
}
|
|
167
|
+
async enableWaterFlowAnimation() {
|
|
168
|
+
if (this.forceSameTabNavigation) await chrome.debugger.sendCommand({
|
|
169
|
+
tabId: this.tabIdOfDebuggerAttached
|
|
170
|
+
}, 'Runtime.evaluate', {
|
|
171
|
+
expression: external_web_element_js_namespaceObject.limitOpenNewTabScript
|
|
172
|
+
});
|
|
173
|
+
const script = await (0, external_dynamic_scripts_js_namespaceObject.injectWaterFlowAnimation)();
|
|
174
|
+
await chrome.debugger.sendCommand({
|
|
175
|
+
tabId: this.tabIdOfDebuggerAttached
|
|
176
|
+
}, 'Runtime.evaluate', {
|
|
177
|
+
expression: script
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async disableWaterFlowAnimation(tabId) {
|
|
181
|
+
const script = await (0, external_dynamic_scripts_js_namespaceObject.injectStopWaterFlowAnimation)();
|
|
182
|
+
await chrome.debugger.sendCommand({
|
|
183
|
+
tabId
|
|
184
|
+
}, 'Runtime.evaluate', {
|
|
185
|
+
expression: script
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async sendCommandToDebugger(command, params) {
|
|
189
|
+
await this.attachDebugger();
|
|
190
|
+
(0, utils_namespaceObject.assert)(this.tabIdOfDebuggerAttached, 'Debugger is not attached');
|
|
191
|
+
this.enableWaterFlowAnimation();
|
|
192
|
+
return await chrome.debugger.sendCommand({
|
|
193
|
+
tabId: this.tabIdOfDebuggerAttached
|
|
194
|
+
}, command, params);
|
|
195
|
+
}
|
|
196
|
+
async getPageContentByCDP() {
|
|
197
|
+
await chrome.scripting.executeScript({
|
|
198
|
+
files: [
|
|
199
|
+
"./scripts/htmlElement.js"
|
|
200
|
+
],
|
|
201
|
+
world: "MAIN",
|
|
202
|
+
target: {
|
|
203
|
+
allFrames: true,
|
|
204
|
+
tabId: this.tabIdOfDebuggerAttached
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const expression = async ()=>{
|
|
208
|
+
window.rpascene_element_inspector.setNodeHashCacheListOnWindow();
|
|
209
|
+
const tree = await window.rpascene_element_inspector.webExtractNodeTree();
|
|
210
|
+
return {
|
|
211
|
+
tree,
|
|
212
|
+
size: {
|
|
213
|
+
width: document.documentElement.clientWidth,
|
|
214
|
+
height: document.documentElement.clientHeight,
|
|
215
|
+
dpr: window.devicePixelRatio
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const returnValue = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
220
|
+
expression: `(${expression.toString()})()`,
|
|
221
|
+
returnByValue: true,
|
|
222
|
+
awaitPromise: true
|
|
223
|
+
});
|
|
224
|
+
if (!returnValue.result.value) {
|
|
225
|
+
var _returnValue_exceptionDetails_exception, _returnValue_exceptionDetails;
|
|
226
|
+
const errorDescription = (null == (_returnValue_exceptionDetails = returnValue.exceptionDetails) ? void 0 : null == (_returnValue_exceptionDetails_exception = _returnValue_exceptionDetails.exception) ? void 0 : _returnValue_exceptionDetails_exception.description) || '';
|
|
227
|
+
if (!errorDescription) console.error('returnValue from cdp', returnValue);
|
|
228
|
+
throw new Error(`Failed to get page content from page, error: ${errorDescription}`);
|
|
229
|
+
}
|
|
230
|
+
return returnValue.result.value;
|
|
231
|
+
}
|
|
232
|
+
async evaluateJavaScript(script) {
|
|
233
|
+
return this.sendCommandToDebugger('Runtime.evaluate', {
|
|
234
|
+
expression: script
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async beforeInvokeAction() {
|
|
238
|
+
try {
|
|
239
|
+
await this.waitUntilNetworkIdle();
|
|
240
|
+
} catch (error) {}
|
|
241
|
+
}
|
|
242
|
+
async waitUntilNetworkIdle() {
|
|
243
|
+
const timeout = 10000;
|
|
244
|
+
const startTime = Date.now();
|
|
245
|
+
let lastReadyState = '';
|
|
246
|
+
while(Date.now() - startTime < timeout){
|
|
247
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
248
|
+
expression: 'document.readyState'
|
|
249
|
+
});
|
|
250
|
+
lastReadyState = result.result.value;
|
|
251
|
+
if ('complete' === lastReadyState) return void await new Promise((resolve)=>setTimeout(resolve, 300));
|
|
252
|
+
await new Promise((resolve)=>setTimeout(resolve, 300));
|
|
253
|
+
}
|
|
254
|
+
throw new Error(`Failed to wait until network idle, last readyState: ${lastReadyState}`);
|
|
255
|
+
}
|
|
256
|
+
async getElementsInfo() {
|
|
257
|
+
const tree = await this.getElementsNodeTree();
|
|
258
|
+
return (0, extractor_namespaceObject.treeToList)(tree);
|
|
259
|
+
}
|
|
260
|
+
async getXpathsById(id) {
|
|
261
|
+
const script = await (0, external_dynamic_scripts_js_namespaceObject.getHtmlElementScript)();
|
|
262
|
+
await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
263
|
+
expression: script
|
|
264
|
+
});
|
|
265
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
266
|
+
expression: `window.rpascene_element_inspector.getXpathsById(${JSON.stringify(id)})`,
|
|
267
|
+
returnByValue: true
|
|
268
|
+
});
|
|
269
|
+
return result.result.value;
|
|
270
|
+
}
|
|
271
|
+
async getXpathsByPoint(point, isOrderSensitive) {
|
|
272
|
+
const script = await (0, external_dynamic_scripts_js_namespaceObject.getHtmlElementScript)();
|
|
273
|
+
await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
274
|
+
expression: script
|
|
275
|
+
});
|
|
276
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
277
|
+
expression: `window.rpascene_element_inspector.getXpathsByPoint({left: ${point.left}, top: ${point.top}}, ${isOrderSensitive})`,
|
|
278
|
+
returnByValue: true
|
|
279
|
+
});
|
|
280
|
+
return result.result.value;
|
|
281
|
+
}
|
|
282
|
+
async getElementInfoByXpath(xpath) {
|
|
283
|
+
const script = await (0, external_dynamic_scripts_js_namespaceObject.getHtmlElementScript)();
|
|
284
|
+
await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
285
|
+
expression: script
|
|
286
|
+
});
|
|
287
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
288
|
+
expression: `window.rpascene_element_inspector.getElementInfoByXpath(${JSON.stringify(xpath)})`,
|
|
289
|
+
returnByValue: true
|
|
290
|
+
});
|
|
291
|
+
return result.result.value;
|
|
292
|
+
}
|
|
293
|
+
async getElementsNodeTree() {
|
|
294
|
+
await this.hideMousePointer();
|
|
295
|
+
const content = await this.getPageContentByCDP();
|
|
296
|
+
if (null == content ? void 0 : content.size) this.viewportSize = content.size;
|
|
297
|
+
return (null == content ? void 0 : content.tree) || {
|
|
298
|
+
node: null,
|
|
299
|
+
children: []
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
async getContext() {
|
|
303
|
+
return await (0, external_web_element_js_namespaceObject.WebPageContextParser)(this, {});
|
|
304
|
+
}
|
|
305
|
+
async size() {
|
|
306
|
+
const content = await this.getPageContentByCDP();
|
|
307
|
+
return content.size;
|
|
308
|
+
}
|
|
309
|
+
async screenshotBase64() {
|
|
310
|
+
await this.hideMousePointer();
|
|
311
|
+
const format = 'jpeg';
|
|
312
|
+
const base64 = await this.sendCommandToDebugger('Page.captureScreenshot', {
|
|
313
|
+
format,
|
|
314
|
+
quality: 90
|
|
315
|
+
});
|
|
316
|
+
return (0, img_namespaceObject.createImgBase64ByFormat)(format, base64.data);
|
|
317
|
+
}
|
|
318
|
+
async url() {
|
|
319
|
+
const tabId = await this.getTabIdOrConnectToCurrentTab();
|
|
320
|
+
const url = await chrome.tabs.get(tabId).then((tab)=>tab.url);
|
|
321
|
+
return url || '';
|
|
322
|
+
}
|
|
323
|
+
async scrollUntilTop(startingPoint) {
|
|
324
|
+
if (startingPoint) await this.mouse.move(startingPoint.left, startingPoint.top);
|
|
325
|
+
return this.mouse.wheel(0, -9999999);
|
|
326
|
+
}
|
|
327
|
+
async scrollUntilBottom(startingPoint) {
|
|
328
|
+
if (startingPoint) await this.mouse.move(startingPoint.left, startingPoint.top);
|
|
329
|
+
return this.mouse.wheel(0, 9999999);
|
|
330
|
+
}
|
|
331
|
+
async scrollUntilLeft(startingPoint) {
|
|
332
|
+
if (startingPoint) await this.mouse.move(startingPoint.left, startingPoint.top);
|
|
333
|
+
return this.mouse.wheel(-9999999, 0);
|
|
334
|
+
}
|
|
335
|
+
async scrollUntilRight(startingPoint) {
|
|
336
|
+
if (startingPoint) await this.mouse.move(startingPoint.left, startingPoint.top);
|
|
337
|
+
return this.mouse.wheel(9999999, 0);
|
|
338
|
+
}
|
|
339
|
+
async scrollUp(distance, startingPoint) {
|
|
340
|
+
const { height } = await this.size();
|
|
341
|
+
const scrollDistance = distance || 0.7 * height;
|
|
342
|
+
return this.mouse.wheel(0, -scrollDistance, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
|
|
343
|
+
}
|
|
344
|
+
async scrollDown(distance, startingPoint) {
|
|
345
|
+
const { height } = await this.size();
|
|
346
|
+
const scrollDistance = distance || 0.7 * height;
|
|
347
|
+
return this.mouse.wheel(0, scrollDistance, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
|
|
348
|
+
}
|
|
349
|
+
async scrollLeft(distance, startingPoint) {
|
|
350
|
+
const { width } = await this.size();
|
|
351
|
+
const scrollDistance = distance || 0.7 * width;
|
|
352
|
+
return this.mouse.wheel(-scrollDistance, 0, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
|
|
353
|
+
}
|
|
354
|
+
async scrollRight(distance, startingPoint) {
|
|
355
|
+
const { width } = await this.size();
|
|
356
|
+
const scrollDistance = distance || 0.7 * width;
|
|
357
|
+
return this.mouse.wheel(scrollDistance, 0, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
|
|
358
|
+
}
|
|
359
|
+
async clearInput(element) {
|
|
360
|
+
if (!element) return void console.warn('No element to clear input');
|
|
361
|
+
await this.mouse.click(element.center[0], element.center[1]);
|
|
362
|
+
await this.sendCommandToDebugger('Input.dispatchKeyEvent', {
|
|
363
|
+
type: 'keyDown',
|
|
364
|
+
commands: [
|
|
365
|
+
'selectAll'
|
|
366
|
+
]
|
|
367
|
+
});
|
|
368
|
+
await this.sendCommandToDebugger('Input.dispatchKeyEvent', {
|
|
369
|
+
type: 'keyUp',
|
|
370
|
+
commands: [
|
|
371
|
+
'selectAll'
|
|
372
|
+
]
|
|
373
|
+
});
|
|
374
|
+
await sleep(100);
|
|
375
|
+
await this.keyboard.press({
|
|
376
|
+
key: 'Backspace'
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async destroy() {
|
|
380
|
+
this.activeTabId = null;
|
|
381
|
+
await this.detachDebugger();
|
|
382
|
+
this.destroyed = true;
|
|
383
|
+
}
|
|
384
|
+
async longPress(x, y, duration) {
|
|
385
|
+
duration = duration || 500;
|
|
386
|
+
const LONG_PRESS_THRESHOLD = 600;
|
|
387
|
+
const MIN_PRESS_THRESHOLD = 300;
|
|
388
|
+
if (duration > LONG_PRESS_THRESHOLD) duration = LONG_PRESS_THRESHOLD;
|
|
389
|
+
if (duration < MIN_PRESS_THRESHOLD) duration = MIN_PRESS_THRESHOLD;
|
|
390
|
+
await this.mouse.move(x, y);
|
|
391
|
+
if (null === this.isMobileEmulation) {
|
|
392
|
+
var _result_result;
|
|
393
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
394
|
+
expression: `(() => {
|
|
395
|
+
return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
|
|
396
|
+
})()`,
|
|
397
|
+
returnByValue: true
|
|
398
|
+
});
|
|
399
|
+
this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
|
|
400
|
+
}
|
|
401
|
+
if (this.isMobileEmulation) {
|
|
402
|
+
const touchPoints = [
|
|
403
|
+
{
|
|
404
|
+
x: Math.round(x),
|
|
405
|
+
y: Math.round(y)
|
|
406
|
+
}
|
|
407
|
+
];
|
|
408
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
409
|
+
type: 'touchStart',
|
|
410
|
+
touchPoints,
|
|
411
|
+
modifiers: 0
|
|
412
|
+
});
|
|
413
|
+
await new Promise((res)=>setTimeout(res, duration));
|
|
414
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
415
|
+
type: 'touchEnd',
|
|
416
|
+
touchPoints: [],
|
|
417
|
+
modifiers: 0
|
|
418
|
+
});
|
|
419
|
+
} else {
|
|
420
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
421
|
+
type: 'mousePressed',
|
|
422
|
+
x,
|
|
423
|
+
y,
|
|
424
|
+
button: 'left',
|
|
425
|
+
clickCount: 1
|
|
426
|
+
});
|
|
427
|
+
await new Promise((res)=>setTimeout(res, duration));
|
|
428
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
429
|
+
type: 'mouseReleased',
|
|
430
|
+
x,
|
|
431
|
+
y,
|
|
432
|
+
button: 'left',
|
|
433
|
+
clickCount: 1
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
this.latestMouseX = x;
|
|
437
|
+
this.latestMouseY = y;
|
|
438
|
+
}
|
|
439
|
+
async swipe(from, to, duration) {
|
|
440
|
+
const LONG_PRESS_THRESHOLD = 500;
|
|
441
|
+
const MIN_PRESS_THRESHOLD = 150;
|
|
442
|
+
duration = duration || 300;
|
|
443
|
+
if (duration < MIN_PRESS_THRESHOLD) duration = MIN_PRESS_THRESHOLD;
|
|
444
|
+
if (duration > LONG_PRESS_THRESHOLD) duration = LONG_PRESS_THRESHOLD;
|
|
445
|
+
if (null === this.isMobileEmulation) {
|
|
446
|
+
var _result_result;
|
|
447
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
448
|
+
expression: `(() => {
|
|
449
|
+
return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
|
|
450
|
+
})()`,
|
|
451
|
+
returnByValue: true
|
|
452
|
+
});
|
|
453
|
+
this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
|
|
454
|
+
}
|
|
455
|
+
const steps = 30;
|
|
456
|
+
const delay = duration / steps;
|
|
457
|
+
if (this.isMobileEmulation) {
|
|
458
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
459
|
+
type: 'touchStart',
|
|
460
|
+
touchPoints: [
|
|
461
|
+
{
|
|
462
|
+
x: Math.round(from.x),
|
|
463
|
+
y: Math.round(from.y)
|
|
464
|
+
}
|
|
465
|
+
],
|
|
466
|
+
modifiers: 0
|
|
467
|
+
});
|
|
468
|
+
for(let i = 1; i <= steps; i++){
|
|
469
|
+
const x = from.x + (to.x - from.x) * (i / steps);
|
|
470
|
+
const y = from.y + (to.y - from.y) * (i / steps);
|
|
471
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
472
|
+
type: 'touchMove',
|
|
473
|
+
touchPoints: [
|
|
474
|
+
{
|
|
475
|
+
x: Math.round(x),
|
|
476
|
+
y: Math.round(y)
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
modifiers: 0
|
|
480
|
+
});
|
|
481
|
+
await new Promise((res)=>setTimeout(res, delay));
|
|
482
|
+
}
|
|
483
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
484
|
+
type: 'touchEnd',
|
|
485
|
+
touchPoints: [],
|
|
486
|
+
modifiers: 0
|
|
487
|
+
});
|
|
488
|
+
} else {
|
|
489
|
+
await this.mouse.move(from.x, from.y);
|
|
490
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
491
|
+
type: 'mousePressed',
|
|
492
|
+
x: from.x,
|
|
493
|
+
y: from.y,
|
|
494
|
+
button: 'left',
|
|
495
|
+
clickCount: 1
|
|
496
|
+
});
|
|
497
|
+
for(let i = 1; i <= steps; i++){
|
|
498
|
+
const x = from.x + (to.x - from.x) * (i / steps);
|
|
499
|
+
const y = from.y + (to.y - from.y) * (i / steps);
|
|
500
|
+
await this.mouse.move(x, y);
|
|
501
|
+
await new Promise((res)=>setTimeout(res, delay));
|
|
502
|
+
}
|
|
503
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
504
|
+
type: 'mouseReleased',
|
|
505
|
+
x: to.x,
|
|
506
|
+
y: to.y,
|
|
507
|
+
button: 'left',
|
|
508
|
+
clickCount: 1
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
this.latestMouseX = to.x;
|
|
512
|
+
this.latestMouseY = to.y;
|
|
513
|
+
}
|
|
514
|
+
constructor(forceSameTabNavigation){
|
|
515
|
+
_define_property(this, "interfaceType", 'chrome-extension-proxy');
|
|
516
|
+
_define_property(this, "forceSameTabNavigation", void 0);
|
|
517
|
+
_define_property(this, "viewportSize", void 0);
|
|
518
|
+
_define_property(this, "activeTabId", null);
|
|
519
|
+
_define_property(this, "tabIdOfDebuggerAttached", null);
|
|
520
|
+
_define_property(this, "attachingDebugger", null);
|
|
521
|
+
_define_property(this, "destroyed", false);
|
|
522
|
+
_define_property(this, "isMobileEmulation", null);
|
|
523
|
+
_define_property(this, "_continueWhenFailedToAttachDebugger", false);
|
|
524
|
+
_define_property(this, "latestMouseX", 100);
|
|
525
|
+
_define_property(this, "latestMouseY", 100);
|
|
526
|
+
_define_property(this, "mouse", {
|
|
527
|
+
click: async (x, y, options)=>{
|
|
528
|
+
const { button = 'left', count = 1 } = options || {};
|
|
529
|
+
await this.mouse.move(x, y);
|
|
530
|
+
if (null === this.isMobileEmulation) {
|
|
531
|
+
var _result_result;
|
|
532
|
+
const result = await this.sendCommandToDebugger('Runtime.evaluate', {
|
|
533
|
+
expression: `(() => {
|
|
534
|
+
return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
|
|
535
|
+
})()`,
|
|
536
|
+
returnByValue: true
|
|
537
|
+
});
|
|
538
|
+
this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
|
|
539
|
+
}
|
|
540
|
+
if (this.isMobileEmulation && 'left' === button) {
|
|
541
|
+
const touchPoints = [
|
|
542
|
+
{
|
|
543
|
+
x: Math.round(x),
|
|
544
|
+
y: Math.round(y)
|
|
545
|
+
}
|
|
546
|
+
];
|
|
547
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
548
|
+
type: 'touchStart',
|
|
549
|
+
touchPoints,
|
|
550
|
+
modifiers: 0
|
|
551
|
+
});
|
|
552
|
+
await this.sendCommandToDebugger('Input.dispatchTouchEvent', {
|
|
553
|
+
type: 'touchEnd',
|
|
554
|
+
touchPoints: [],
|
|
555
|
+
modifiers: 0
|
|
556
|
+
});
|
|
557
|
+
} else for(let i = 0; i < count; i++){
|
|
558
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
559
|
+
type: 'mousePressed',
|
|
560
|
+
x,
|
|
561
|
+
y,
|
|
562
|
+
button,
|
|
563
|
+
clickCount: 1
|
|
564
|
+
});
|
|
565
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
566
|
+
type: 'mouseReleased',
|
|
567
|
+
x,
|
|
568
|
+
y,
|
|
569
|
+
button,
|
|
570
|
+
clickCount: 1
|
|
571
|
+
});
|
|
572
|
+
await sleep(50);
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
wheel: async (deltaX, deltaY, startX, startY)=>{
|
|
576
|
+
const finalX = startX || this.latestMouseX;
|
|
577
|
+
const finalY = startY || this.latestMouseY;
|
|
578
|
+
await this.showMousePointer(finalX, finalY);
|
|
579
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
580
|
+
type: 'mouseWheel',
|
|
581
|
+
x: finalX,
|
|
582
|
+
y: finalY,
|
|
583
|
+
deltaX,
|
|
584
|
+
deltaY
|
|
585
|
+
});
|
|
586
|
+
this.latestMouseX = finalX;
|
|
587
|
+
this.latestMouseY = finalY;
|
|
588
|
+
},
|
|
589
|
+
move: async (x, y)=>{
|
|
590
|
+
await this.showMousePointer(x, y);
|
|
591
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
592
|
+
type: 'mouseMoved',
|
|
593
|
+
x,
|
|
594
|
+
y
|
|
595
|
+
});
|
|
596
|
+
this.latestMouseX = x;
|
|
597
|
+
this.latestMouseY = y;
|
|
598
|
+
},
|
|
599
|
+
drag: async (from, to)=>{
|
|
600
|
+
await this.mouse.move(from.x, from.y);
|
|
601
|
+
await sleep(200);
|
|
602
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
603
|
+
type: 'mousePressed',
|
|
604
|
+
x: from.x,
|
|
605
|
+
y: from.y,
|
|
606
|
+
button: 'left',
|
|
607
|
+
clickCount: 1
|
|
608
|
+
});
|
|
609
|
+
await sleep(300);
|
|
610
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
611
|
+
type: 'mouseMoved',
|
|
612
|
+
x: to.x,
|
|
613
|
+
y: to.y
|
|
614
|
+
});
|
|
615
|
+
await sleep(500);
|
|
616
|
+
await this.sendCommandToDebugger('Input.dispatchMouseEvent', {
|
|
617
|
+
type: 'mouseReleased',
|
|
618
|
+
x: to.x,
|
|
619
|
+
y: to.y,
|
|
620
|
+
button: 'left',
|
|
621
|
+
clickCount: 1
|
|
622
|
+
});
|
|
623
|
+
await sleep(200);
|
|
624
|
+
await this.mouse.move(to.x, to.y);
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
_define_property(this, "keyboard", {
|
|
628
|
+
type: async (text)=>{
|
|
629
|
+
const cdpKeyboard = new external_cdpInput_js_namespaceObject.CdpKeyboard({
|
|
630
|
+
send: this.sendCommandToDebugger.bind(this)
|
|
631
|
+
});
|
|
632
|
+
await cdpKeyboard.type(text, {
|
|
633
|
+
delay: 0
|
|
634
|
+
});
|
|
635
|
+
},
|
|
636
|
+
press: async (action)=>{
|
|
637
|
+
const cdpKeyboard = new external_cdpInput_js_namespaceObject.CdpKeyboard({
|
|
638
|
+
send: this.sendCommandToDebugger.bind(this)
|
|
639
|
+
});
|
|
640
|
+
const keys = Array.isArray(action) ? action : [
|
|
641
|
+
action
|
|
642
|
+
];
|
|
643
|
+
for (const k of keys){
|
|
644
|
+
const commands = k.command ? [
|
|
645
|
+
k.command
|
|
646
|
+
] : [];
|
|
647
|
+
await cdpKeyboard.down(k.key, {
|
|
648
|
+
commands
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
for (const k of [
|
|
652
|
+
...keys
|
|
653
|
+
].reverse())await cdpKeyboard.up(k.key);
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
this.forceSameTabNavigation = forceSameTabNavigation;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
exports["default"] = __webpack_exports__["default"];
|
|
660
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
661
|
+
"default"
|
|
662
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
663
|
+
Object.defineProperty(exports, '__esModule', {
|
|
664
|
+
value: true
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
//# sourceMappingURL=page.js.map
|