@iflyrpa/playwright 1.1.2 → 1.2.1
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 +12 -10
- package/dist/index.cjs +420 -457
- package/dist/index.d.ts +93 -86
- package/dist/index.js +407 -0
- package/package.json +19 -19
- package/dist/index.d.cts +0 -86
- package/dist/index.d.mts +0 -86
- package/dist/index.mjs +0 -486
package/dist/index.cjs
CHANGED
|
@@ -1,253 +1,238 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
playwright: "^1.46.1",
|
|
49
|
-
typescript: "^5.5.2",
|
|
50
|
-
unbuild: "^2.0.0"
|
|
51
|
-
};
|
|
52
|
-
const dependencies = {
|
|
53
|
-
"@iflyrpa/actions": "workspace:*",
|
|
54
|
-
"@iflyrpa/share": "workspace:*",
|
|
55
|
-
"@electron/get": "^2.0.0",
|
|
56
|
-
"@sentry/node": "^5.5.0",
|
|
57
|
-
"extract-zip": "^2.0.1",
|
|
58
|
-
loglevel: "^1.9.2",
|
|
59
|
-
pacote: "^20.0.0"
|
|
60
|
-
};
|
|
61
|
-
const packageJson = {
|
|
62
|
-
name: name,
|
|
63
|
-
type: type,
|
|
64
|
-
version: version$1,
|
|
65
|
-
main: main,
|
|
66
|
-
module: module$1,
|
|
67
|
-
types: types,
|
|
68
|
-
scripts: scripts,
|
|
69
|
-
author: author,
|
|
70
|
-
license: license,
|
|
71
|
-
files: files,
|
|
72
|
-
peerDependencies: peerDependencies,
|
|
73
|
-
devDependencies: devDependencies,
|
|
74
|
-
dependencies: dependencies
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
var __defProp$4 = Object.defineProperty;
|
|
78
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
79
|
-
var __publicField$4 = (obj, key, value) => {
|
|
80
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
81
|
-
return value;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = function(module) {
|
|
5
|
+
var getter = module && module.__esModule ? function() {
|
|
6
|
+
return module['default'];
|
|
7
|
+
} : function() {
|
|
8
|
+
return module;
|
|
9
|
+
};
|
|
10
|
+
__webpack_require__.d(getter, {
|
|
11
|
+
a: getter
|
|
12
|
+
});
|
|
13
|
+
return getter;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
18
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: definition[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = function(obj, prop) {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.r = function(exports1) {
|
|
31
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
32
|
+
value: 'Module'
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __webpack_exports__ = {};
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
version: ()=>src_version,
|
|
43
|
+
RpaTask: ()=>RpaTask
|
|
44
|
+
});
|
|
45
|
+
const actions_namespaceObject = require("@iflyrpa/actions");
|
|
46
|
+
var package_namespaceObject = {
|
|
47
|
+
i8: "1.2.1"
|
|
82
48
|
};
|
|
49
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
50
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
51
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
52
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
53
|
+
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
54
|
+
var external_node_child_process_default = /*#__PURE__*/ __webpack_require__.n(external_node_child_process_namespaceObject);
|
|
55
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
56
|
+
var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
|
|
57
|
+
const get_namespaceObject = require("@electron/get");
|
|
58
|
+
const external_extract_zip_namespaceObject = require("extract-zip");
|
|
59
|
+
var external_extract_zip_default = /*#__PURE__*/ __webpack_require__.n(external_extract_zip_namespaceObject);
|
|
60
|
+
function _define_property(obj, key, value) {
|
|
61
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
62
|
+
value: value,
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true
|
|
66
|
+
});
|
|
67
|
+
else obj[key] = value;
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
83
70
|
const ELECTRON_MIRROR = "http://npmmirror.com/mirrors/electron/";
|
|
84
71
|
const ELECTRON_VERSION = "22.3.27";
|
|
85
72
|
class ElectronInstall {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.electronPath = path__default.join(this.rootDir, this.platformPath);
|
|
95
|
-
}
|
|
96
|
-
isInstalled() {
|
|
97
|
-
try {
|
|
98
|
-
if (fs__default.readFileSync(path__default.join(this.rootDir, "version"), "utf-8").replace(/^v/, "") !== this.version) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
} catch (ignored) {
|
|
102
|
-
return false;
|
|
73
|
+
isInstalled() {
|
|
74
|
+
try {
|
|
75
|
+
if (external_node_fs_default().readFileSync(external_node_path_default().join(this.rootDir, "version"), "utf-8").replace(/^v/, "") !== this.version) return false;
|
|
76
|
+
} catch (ignored) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || external_node_path_default().join(this.rootDir, this.platformPath);
|
|
80
|
+
return external_node_fs_default().existsSync(electronPath);
|
|
103
81
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
default:
|
|
120
|
-
throw new Error(
|
|
121
|
-
`Electron builds are not available on platform: ${platform}`
|
|
122
|
-
);
|
|
82
|
+
getPlatformPath() {
|
|
83
|
+
const platform = process.env.npm_config_platform || external_node_os_default().platform();
|
|
84
|
+
switch(platform){
|
|
85
|
+
case "mas":
|
|
86
|
+
case "darwin":
|
|
87
|
+
return "Electron.app/Contents/MacOS/Electron";
|
|
88
|
+
case "freebsd":
|
|
89
|
+
case "openbsd":
|
|
90
|
+
case "linux":
|
|
91
|
+
return "electron";
|
|
92
|
+
case "win32":
|
|
93
|
+
return "electron.exe";
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(`Electron builds are not available on platform: ${platform}`);
|
|
96
|
+
}
|
|
123
97
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
98
|
+
async install() {
|
|
99
|
+
const installed = this.isInstalled();
|
|
100
|
+
this.task.logger.info(`electron@${this.version} 是否已安装:${installed}`);
|
|
101
|
+
if (installed) return this.electronPath;
|
|
102
|
+
const platform = process.env.npm_config_platform || process.platform;
|
|
103
|
+
let arch = process.env.npm_config_arch || process.arch;
|
|
104
|
+
if ("darwin" === platform && "darwin" === process.platform && "x64" === arch && void 0 === process.env.npm_config_arch) try {
|
|
105
|
+
const output = external_node_child_process_default().execSync("sysctl -in sysctl.proc_translated");
|
|
106
|
+
if ("1" === output.toString().trim()) arch = "arm64";
|
|
107
|
+
} catch {}
|
|
108
|
+
try {
|
|
109
|
+
this.task.logger.info(`electron@${this.version} 开始下载资源`);
|
|
110
|
+
const zipPath = await (0, get_namespaceObject.downloadArtifact)({
|
|
111
|
+
version: this.version,
|
|
112
|
+
artifactName: "electron",
|
|
113
|
+
force: "true" === process.env.force_no_cache,
|
|
114
|
+
cacheRoot: process.env.electron_config_cache,
|
|
115
|
+
checksums: void 0,
|
|
116
|
+
mirrorOptions: {
|
|
117
|
+
mirror: ELECTRON_MIRROR
|
|
118
|
+
},
|
|
119
|
+
platform,
|
|
120
|
+
arch
|
|
121
|
+
});
|
|
122
|
+
this.task.logger.info(`electron@${this.version} 开始解压资源`);
|
|
123
|
+
process.noAsar = true;
|
|
124
|
+
await external_extract_zip_default()(zipPath, {
|
|
125
|
+
dir: this.rootDir
|
|
126
|
+
});
|
|
127
|
+
this.task.logger.info(`electron@${this.version} 下载成功`);
|
|
128
|
+
return this.electronPath;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
this.task.logger.error(`electron@${this.version} 下载失败`, error);
|
|
131
|
+
throw error;
|
|
139
132
|
}
|
|
140
|
-
} catch {
|
|
141
|
-
}
|
|
142
133
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
arch
|
|
155
|
-
});
|
|
156
|
-
this.task.logger.info(`electron@${this.version} \u5F00\u59CB\u89E3\u538B\u8D44\u6E90`);
|
|
157
|
-
process.noAsar = true;
|
|
158
|
-
await extract__default(zipPath, { dir: this.rootDir });
|
|
159
|
-
this.task.logger.info(`electron@${this.version} \u4E0B\u8F7D\u6210\u529F`);
|
|
160
|
-
return this.electronPath;
|
|
161
|
-
} catch (error) {
|
|
162
|
-
this.task.logger.error(`electron@${this.version} \u4E0B\u8F7D\u5931\u8D25`, error);
|
|
163
|
-
throw error;
|
|
134
|
+
constructor(task){
|
|
135
|
+
_define_property(this, "task", void 0);
|
|
136
|
+
_define_property(this, "rootDir", void 0);
|
|
137
|
+
_define_property(this, "electronPath", void 0);
|
|
138
|
+
_define_property(this, "platformPath", void 0);
|
|
139
|
+
_define_property(this, "version", void 0);
|
|
140
|
+
this.task = task;
|
|
141
|
+
this.version = ELECTRON_VERSION;
|
|
142
|
+
this.platformPath = this.getPlatformPath();
|
|
143
|
+
this.rootDir = external_node_path_default().join(task.packagesDir, `electron@${this.version}`);
|
|
144
|
+
this.electronPath = external_node_path_default().join(this.rootDir, this.platformPath);
|
|
164
145
|
}
|
|
165
|
-
}
|
|
166
146
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (!dsn)
|
|
178
|
-
return;
|
|
179
|
-
this.sentry = new node.NodeClient({
|
|
180
|
-
dsn,
|
|
181
|
-
defaultIntegrations: false
|
|
147
|
+
const share_namespaceObject = require("@iflyrpa/share");
|
|
148
|
+
const external_loglevel_namespaceObject = require("loglevel");
|
|
149
|
+
var external_loglevel_default = /*#__PURE__*/ __webpack_require__.n(external_loglevel_namespaceObject);
|
|
150
|
+
const node_namespaceObject = require("@sentry/node");
|
|
151
|
+
function sentry_define_property(obj, key, value) {
|
|
152
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
153
|
+
value: value,
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: true,
|
|
156
|
+
writable: true
|
|
182
157
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
158
|
+
else obj[key] = value;
|
|
159
|
+
return obj;
|
|
160
|
+
}
|
|
161
|
+
class SentryInstance {
|
|
162
|
+
captureException(error) {
|
|
163
|
+
var _this_sentry;
|
|
164
|
+
null === (_this_sentry = this.sentry) || void 0 === _this_sentry || _this_sentry.captureException(error);
|
|
165
|
+
}
|
|
166
|
+
constructor(dsn){
|
|
167
|
+
sentry_define_property(this, "sentry", void 0);
|
|
168
|
+
if (!dsn) return;
|
|
169
|
+
this.sentry = new node_namespaceObject.NodeClient({
|
|
170
|
+
dsn,
|
|
171
|
+
defaultIntegrations: false
|
|
172
|
+
});
|
|
173
|
+
}
|
|
187
174
|
}
|
|
188
175
|
const sentry = new SentryInstance(process.env.RPA_SENTRY_DSN);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
176
|
+
function logger_define_property(obj, key, value) {
|
|
177
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
178
|
+
value: value,
|
|
179
|
+
enumerable: true,
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: true
|
|
182
|
+
});
|
|
183
|
+
else obj[key] = value;
|
|
184
|
+
return obj;
|
|
185
|
+
}
|
|
186
|
+
class Logger {
|
|
187
|
+
static getInstance(cachePath) {
|
|
188
|
+
if (!Logger.instance) Logger.instance = new Logger(cachePath);
|
|
189
|
+
return Logger.instance;
|
|
201
190
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.stream = fs__default.createWriteStream(logFile, { flags: "a" });
|
|
205
|
-
log__default.setLevel("debug");
|
|
206
|
-
log__default.methodFactory = (methodName) => {
|
|
207
|
-
return (message) => {
|
|
208
|
-
this.stream.write(
|
|
209
|
-
`[${( new Date()).toLocaleString()}] ${methodName.toUpperCase()}: ${message}
|
|
210
|
-
`
|
|
211
|
-
);
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
log__default.setLevel(log__default.getLevel());
|
|
215
|
-
_Logger.instance = this;
|
|
216
|
-
}
|
|
217
|
-
static getInstance(cachePath) {
|
|
218
|
-
if (!_Logger.instance) {
|
|
219
|
-
_Logger.instance = new _Logger(cachePath);
|
|
191
|
+
debug(...msg) {
|
|
192
|
+
external_loglevel_default().debug(...msg);
|
|
220
193
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
224
|
-
debug(...msg) {
|
|
225
|
-
log__default.debug(...msg);
|
|
226
|
-
}
|
|
227
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
228
|
-
info(...msg) {
|
|
229
|
-
log__default.info(...msg);
|
|
230
|
-
}
|
|
231
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
232
|
-
warn(...msg) {
|
|
233
|
-
log__default.warn(...msg);
|
|
234
|
-
}
|
|
235
|
-
// error 级别的日志上报 sentry
|
|
236
|
-
error(prefix, err) {
|
|
237
|
-
const error = err || prefix;
|
|
238
|
-
if (err instanceof Error) {
|
|
239
|
-
err.message = `${prefix}\uFF1A${err.message}`;
|
|
194
|
+
info(...msg) {
|
|
195
|
+
external_loglevel_default().info(...msg);
|
|
240
196
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
197
|
+
warn(...msg) {
|
|
198
|
+
external_loglevel_default().warn(...msg);
|
|
199
|
+
}
|
|
200
|
+
error(prefix, err) {
|
|
201
|
+
let error = err || prefix;
|
|
202
|
+
if (err instanceof Error) err.message = `${prefix}:${err.message}`;
|
|
203
|
+
if ("object" == typeof err) error = `${prefix}:${JSON.stringify(err)}`;
|
|
204
|
+
external_loglevel_default().error(error);
|
|
205
|
+
sentry.captureException(error);
|
|
206
|
+
}
|
|
207
|
+
close() {
|
|
208
|
+
this.stream.end();
|
|
209
|
+
}
|
|
210
|
+
constructor(cachePath){
|
|
211
|
+
logger_define_property(this, "stream", void 0);
|
|
212
|
+
if (Logger.instance) return Logger.instance;
|
|
213
|
+
const logFile = external_node_path_default().join(cachePath, "rpa.log");
|
|
214
|
+
(0, share_namespaceObject.ensureFileSync)(logFile);
|
|
215
|
+
this.stream = external_node_fs_default().createWriteStream(logFile, {
|
|
216
|
+
flags: "a"
|
|
217
|
+
});
|
|
218
|
+
external_loglevel_default().setLevel("debug");
|
|
219
|
+
const logToFile = (level, message)=>{
|
|
220
|
+
const timestamp = new Date().toLocaleString();
|
|
221
|
+
this.stream.write(`[${timestamp}] ${level.toUpperCase()} ${message}\n`);
|
|
222
|
+
};
|
|
223
|
+
external_loglevel_default().methodFactory = (methodName, _level, _logger)=>(...messages)=>{
|
|
224
|
+
const formattedMessage = messages.map((message)=>{
|
|
225
|
+
if (message instanceof Error) return `${message.name}: ${message.message}\n${message.stack}`;
|
|
226
|
+
if ("object" == typeof message) return JSON.stringify(message);
|
|
227
|
+
return message;
|
|
228
|
+
}).join(" ");
|
|
229
|
+
logToFile(methodName, formattedMessage);
|
|
230
|
+
};
|
|
231
|
+
external_loglevel_default().setLevel(external_loglevel_default().getLevel());
|
|
232
|
+
Logger.instance = this;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
logger_define_property(Logger, "instance", null);
|
|
251
236
|
const template = `
|
|
252
237
|
const { app } = require("electron");
|
|
253
238
|
|
|
@@ -255,245 +240,223 @@ app.whenReady().then(() => {});
|
|
|
255
240
|
|
|
256
241
|
app.on("window-all-closed", (e) => e.preventDefault());
|
|
257
242
|
`;
|
|
258
|
-
const generateFile = async (dir)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
243
|
+
const generateFile = async (dir)=>{
|
|
244
|
+
const filePath = external_node_path_default().join(dir, "main.js");
|
|
245
|
+
const isPathExists = await (0, share_namespaceObject.pathExists)(filePath);
|
|
246
|
+
if (!isPathExists) {
|
|
247
|
+
await (0, share_namespaceObject.ensureFile)(filePath);
|
|
248
|
+
await (0, share_namespaceObject.writeFile)(filePath, template);
|
|
249
|
+
}
|
|
250
|
+
return filePath;
|
|
266
251
|
};
|
|
267
|
-
const launchElectronApp = async (cachePath, playwright, electronPath)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
252
|
+
const launchElectronApp = async (cachePath, playwright, electronPath)=>{
|
|
253
|
+
const logger = Logger.getInstance(cachePath);
|
|
254
|
+
try {
|
|
255
|
+
const mainPath = await generateFile(cachePath);
|
|
256
|
+
const electronApp = await playwright._electron.launch({
|
|
257
|
+
executablePath: electronPath,
|
|
258
|
+
args: [
|
|
259
|
+
mainPath
|
|
260
|
+
],
|
|
261
|
+
cwd: cachePath
|
|
262
|
+
});
|
|
263
|
+
logger.info(`electron 启动成功:${electronPath} ${mainPath}`);
|
|
264
|
+
return electronApp;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
logger.error("electron 启动失败:", error);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
283
269
|
};
|
|
284
|
-
|
|
270
|
+
const pacote_namespaceObject = require("@iflyrpa/pacote");
|
|
271
|
+
var pacote_default = /*#__PURE__*/ __webpack_require__.n(pacote_namespaceObject);
|
|
272
|
+
function packageManager_define_property(obj, key, value) {
|
|
273
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
274
|
+
value: value,
|
|
275
|
+
enumerable: true,
|
|
276
|
+
configurable: true,
|
|
277
|
+
writable: true
|
|
278
|
+
});
|
|
279
|
+
else obj[key] = value;
|
|
280
|
+
return obj;
|
|
281
|
+
}
|
|
285
282
|
const NPM_REGISTRY = "https://registry.npmmirror.com/";
|
|
286
283
|
class PackageManager {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
throw error;
|
|
284
|
+
async getManifest(module) {
|
|
285
|
+
try {
|
|
286
|
+
return pacote_default().manifest(module, {
|
|
287
|
+
registry: NPM_REGISTRY
|
|
288
|
+
});
|
|
289
|
+
} catch (error) {
|
|
290
|
+
this.task.logger.error("获取依赖信息失败", error);
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
297
293
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.task.logger.info(`${packageName} \u5B89\u88C5\u6210\u529F`);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
this.task.logger.error(`${packageName} \u5B89\u88C5\u5931\u8D25`, error);
|
|
294
|
+
async extract(name, version = "latest") {
|
|
295
|
+
const packageName = `${name}@${version}`;
|
|
296
|
+
try {
|
|
297
|
+
this.task.logger.info(`${packageName} 开始安装`);
|
|
298
|
+
await pacote_default().extract(packageName, external_node_path_default().join(this.task.packagesDir, packageName), {
|
|
299
|
+
registry: NPM_REGISTRY
|
|
300
|
+
});
|
|
301
|
+
this.task.logger.info(`${packageName} 安装成功`);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
this.task.logger.error(`${packageName} 安装失败`, error);
|
|
304
|
+
}
|
|
312
305
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return null;
|
|
306
|
+
require(module) {
|
|
307
|
+
try {
|
|
308
|
+
return require(external_node_path_default().join(this.task.packagesDir, module));
|
|
309
|
+
} catch (error) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
320
312
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
this.task.logger.info(`${packageName} \u662F\u5426\u5DF2\u5B89\u88C5\uFF1A${!!plugin}`);
|
|
327
|
-
if (!plugin) {
|
|
328
|
-
await this.extract(name, version);
|
|
313
|
+
async install(name, version) {
|
|
314
|
+
const packageName = `${name}@${version}`;
|
|
315
|
+
const plugin = this.require(packageName);
|
|
316
|
+
this.task.logger.info(`${packageName} 是否已安装:${!!plugin}`);
|
|
317
|
+
if (!plugin) await this.extract(name, version);
|
|
329
318
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
319
|
+
async update(name) {
|
|
320
|
+
const manifest = await this.getManifest(`${name}@latest`);
|
|
321
|
+
const version = manifest.version;
|
|
322
|
+
const plugin = this.require(`${name}@${version}`);
|
|
323
|
+
if (plugin) this.task.logger.info(`${name}@${version} 已是最新版本`);
|
|
324
|
+
else {
|
|
325
|
+
await this.extract(name, version);
|
|
326
|
+
this.task.logger.info(`${name}@${version} 安装成功`);
|
|
327
|
+
}
|
|
328
|
+
return version;
|
|
329
|
+
}
|
|
330
|
+
constructor(task){
|
|
331
|
+
packageManager_define_property(this, "task", void 0);
|
|
332
|
+
this.task = task;
|
|
338
333
|
}
|
|
339
|
-
return version;
|
|
340
|
-
}
|
|
341
334
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
};
|
|
335
|
+
function task_define_property(obj, key, value) {
|
|
336
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
337
|
+
value: value,
|
|
338
|
+
enumerable: true,
|
|
339
|
+
configurable: true,
|
|
340
|
+
writable: true
|
|
341
|
+
});
|
|
342
|
+
else obj[key] = value;
|
|
343
|
+
return obj;
|
|
344
|
+
}
|
|
349
345
|
const PLAYWRIGHT_VERSION = "1.46.1";
|
|
350
346
|
const PLAYWRIGHT_NAME = "playwright-core";
|
|
351
347
|
class Task {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
348
|
+
async installPlaywright() {
|
|
349
|
+
const packageName = `${PLAYWRIGHT_NAME}@${PLAYWRIGHT_VERSION}`;
|
|
350
|
+
await this.packageManager.install(PLAYWRIGHT_NAME, PLAYWRIGHT_VERSION);
|
|
351
|
+
return this.packageManager.require(packageName);
|
|
352
|
+
}
|
|
353
|
+
installElectron() {
|
|
354
|
+
return new ElectronInstall(this).install();
|
|
355
|
+
}
|
|
356
|
+
async launchApp() {
|
|
357
|
+
if (!this._electronApp) {
|
|
358
|
+
const [playwright, electronPath] = await Promise.all([
|
|
359
|
+
this.playwrightPackage,
|
|
360
|
+
this.electronPackage
|
|
361
|
+
]);
|
|
362
|
+
this._electronApp = await launchElectronApp(this.cachePath, playwright, electronPath);
|
|
363
|
+
}
|
|
364
|
+
return this._electronApp;
|
|
365
|
+
}
|
|
366
|
+
getTmpPath() {
|
|
367
|
+
return external_node_path_default().join(this.cachePath, "tmp");
|
|
368
|
+
}
|
|
369
|
+
clearTmpPath() {
|
|
370
|
+
const tmpPath = this.getTmpPath();
|
|
371
|
+
return external_node_fs_default().rm(tmpPath, {
|
|
372
|
+
recursive: true,
|
|
373
|
+
force: true
|
|
374
|
+
}, (err)=>{
|
|
375
|
+
if (err) this.logger.error("删除临时文件失败,", err);
|
|
376
|
+
else this.logger.info("删除临时文件成功");
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async close() {
|
|
380
|
+
var _this__electronApp;
|
|
381
|
+
this.logger.info("关闭应用");
|
|
382
|
+
this.clearTmpPath();
|
|
383
|
+
this.logger.close();
|
|
384
|
+
await (null === (_this__electronApp = this._electronApp) || void 0 === _this__electronApp ? void 0 : _this__electronApp.close());
|
|
385
|
+
this.isClosed = true;
|
|
386
|
+
this._electronApp = null;
|
|
387
|
+
}
|
|
388
|
+
async createPage(pageParams) {
|
|
389
|
+
const electronApp = await this.launchApp();
|
|
390
|
+
const [page] = await Promise.all([
|
|
391
|
+
electronApp.waitForEvent("window"),
|
|
392
|
+
electronApp.evaluate(async (electron, { pageParams })=>{
|
|
393
|
+
await electron.app.whenReady();
|
|
394
|
+
const window = new electron.BrowserWindow({
|
|
395
|
+
show: pageParams.show,
|
|
396
|
+
width: 1500,
|
|
397
|
+
height: 800,
|
|
398
|
+
webPreferences: {
|
|
399
|
+
nodeIntegration: true,
|
|
400
|
+
contextIsolation: false
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
if (pageParams.cookies) await Promise.all(pageParams.cookies.map((cookie)=>electron.session.defaultSession.cookies.set(cookie)));
|
|
404
|
+
await window.loadURL(pageParams.url);
|
|
405
|
+
}, {
|
|
406
|
+
pageParams
|
|
407
|
+
})
|
|
408
|
+
]);
|
|
409
|
+
return page;
|
|
405
410
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
411
|
+
constructor({ cachePath, debug }){
|
|
412
|
+
task_define_property(this, "logger", void 0);
|
|
413
|
+
task_define_property(this, "cachePath", void 0);
|
|
414
|
+
task_define_property(this, "debug", void 0);
|
|
415
|
+
task_define_property(this, "packagesDir", void 0);
|
|
416
|
+
task_define_property(this, "packageManager", void 0);
|
|
417
|
+
task_define_property(this, "playwrightPackage", void 0);
|
|
418
|
+
task_define_property(this, "electronPackage", void 0);
|
|
419
|
+
task_define_property(this, "_electronApp", null);
|
|
420
|
+
task_define_property(this, "isClosed", false);
|
|
421
|
+
this.cachePath = cachePath;
|
|
422
|
+
this.packagesDir = external_node_path_default().join(cachePath, "packages");
|
|
423
|
+
this.debug = debug || false;
|
|
424
|
+
this.logger = Logger.getInstance(cachePath);
|
|
425
|
+
this.packageManager = new PackageManager(this);
|
|
426
|
+
this.playwrightPackage = this.installPlaywright();
|
|
427
|
+
this.electronPackage = this.installElectron();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function src_define_property(obj, key, value) {
|
|
431
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
432
|
+
value: value,
|
|
433
|
+
enumerable: true,
|
|
434
|
+
configurable: true,
|
|
435
|
+
writable: true
|
|
426
436
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
* 关闭 playwright 启动的 electron 客户端
|
|
430
|
-
* @returns
|
|
431
|
-
*/
|
|
432
|
-
async close() {
|
|
433
|
-
this.logger.info("\u5173\u95ED\u5E94\u7528");
|
|
434
|
-
this.clearTmpPath();
|
|
435
|
-
this.logger.close();
|
|
436
|
-
await this._electronApp?.close();
|
|
437
|
-
this.isClosed = true;
|
|
438
|
-
this._electronApp = null;
|
|
439
|
-
}
|
|
440
|
-
async createPage(pageParams) {
|
|
441
|
-
const electronApp = await this.launchApp();
|
|
442
|
-
const [page] = await Promise.all([
|
|
443
|
-
electronApp.waitForEvent("window"),
|
|
444
|
-
electronApp.evaluate(
|
|
445
|
-
async (electron, { pageParams: pageParams2 }) => {
|
|
446
|
-
await electron.app.whenReady();
|
|
447
|
-
const window = new electron.BrowserWindow({
|
|
448
|
-
show: pageParams2.show,
|
|
449
|
-
width: 1500,
|
|
450
|
-
height: 800,
|
|
451
|
-
webPreferences: {
|
|
452
|
-
nodeIntegration: true,
|
|
453
|
-
contextIsolation: false
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
if (pageParams2.cookies) {
|
|
457
|
-
await Promise.all(
|
|
458
|
-
pageParams2.cookies.map(
|
|
459
|
-
(cookie) => electron.session.defaultSession.cookies.set(cookie)
|
|
460
|
-
)
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
await window.loadURL(pageParams2.url);
|
|
464
|
-
},
|
|
465
|
-
{ pageParams }
|
|
466
|
-
)
|
|
467
|
-
]);
|
|
468
|
-
return page;
|
|
469
|
-
}
|
|
437
|
+
else obj[key] = value;
|
|
438
|
+
return obj;
|
|
470
439
|
}
|
|
471
|
-
|
|
472
|
-
var __defProp = Object.defineProperty;
|
|
473
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
474
|
-
var __publicField = (obj, key, value) => {
|
|
475
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
476
|
-
return value;
|
|
477
|
-
};
|
|
478
440
|
class RpaTask extends Task {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
441
|
+
async update() {
|
|
442
|
+
try {
|
|
443
|
+
const name = "@iflyrpa/actions";
|
|
444
|
+
const version = await this.packageManager.update(name);
|
|
445
|
+
const actionPackage = this.packageManager.require(`${name}@${version}`);
|
|
446
|
+
(null == actionPackage ? void 0 : actionPackage.actions) && (this.actions = actionPackage.actions);
|
|
447
|
+
} catch (error) {
|
|
448
|
+
this.logger.error("更新依赖失败", error);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
constructor(params){
|
|
452
|
+
super(params), src_define_property(this, "actions", void 0);
|
|
453
|
+
this.actions = new actions_namespaceObject.Action(this);
|
|
454
|
+
params.forceUpdate && this.update();
|
|
493
455
|
}
|
|
494
|
-
}
|
|
495
456
|
}
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
457
|
+
const src_version = package_namespaceObject.i8;
|
|
458
|
+
var __webpack_export_target__ = exports;
|
|
459
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
460
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
461
|
+
value: true
|
|
462
|
+
});
|