@iflyrpa/playwright 1.0.7 → 1.0.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/dist/index.cjs CHANGED
@@ -5,7 +5,6 @@ const path = require('node:path');
5
5
  const axios = require('axios');
6
6
  const fs = require('fs-extra');
7
7
  const electron = require('electron');
8
- const playwright = require('playwright');
9
8
  const spawn = require('cross-spawn');
10
9
 
11
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -18,7 +17,7 @@ const spawn__default = /*#__PURE__*/_interopDefaultCompat(spawn);
18
17
 
19
18
  const name = "@iflyrpa/playwright";
20
19
  const type = "module";
21
- const version$1 = "1.0.7";
20
+ const version$1 = "1.0.8";
22
21
  const description = "";
23
22
  const main = "./dist/index.cjs";
24
23
  const module$1 = "./dist/index.mjs";
@@ -103,9 +102,9 @@ const xiaohongshuPublishAction = async (props) => {
103
102
  const selectAddress = async (selector, address) => {
104
103
  const instance = typeof selector === "string" ? page.locator(selector) : selector;
105
104
  await instance.click();
106
- await instance.fill(address);
105
+ await instance.locator("input").fill(address);
107
106
  const poperInstance = page.locator(
108
- ".el-popper[aria-hidden=false] ul li[role=option]"
107
+ '.d-popover:not([style*="display: none"]) .d-options .d-grid-item'
109
108
  );
110
109
  await poperInstance.first().waitFor();
111
110
  await poperInstance.first().click();
@@ -116,8 +115,12 @@ const xiaohongshuPublishAction = async (props) => {
116
115
  await instance.fill(date);
117
116
  await instance.blur();
118
117
  };
119
- await page.waitForSelector("#CreatorPlatform", { state: "visible" });
120
- await page.locator("#content-area .menu-container .publish-video a").click();
118
+ await page.waitForSelector("#CreatorPlatform", { state: "visible" }).catch(() => {
119
+ throw new Error("\u767B\u5F55\u5931\u8D25");
120
+ });
121
+ await page.locator("#content-area .menu-container .publish-video a").click().catch(() => {
122
+ throw new Error("\u672A\u627E\u5230\u53D1\u5E03\u7B14\u8BB0\u6309\u94AE");
123
+ });
121
124
  await page.locator(".creator-container .header .title").filter({ hasText: /^上传图文$/ }).click();
122
125
  const images = await Promise.all(
123
126
  params.banners.map((url) => {
@@ -140,7 +143,7 @@ const xiaohongshuPublishAction = async (props) => {
140
143
  await page.mouse.wheel(0, 500);
141
144
  if (params.address) {
142
145
  await selectAddress(
143
- ".media-extension .address-input input[placeholder=\u6DFB\u52A0\u5730\u70B9]",
146
+ page.locator(".media-extension .address-input").filter({ hasText: "\u6DFB\u52A0\u5730\u70B9" }),
144
147
  params.address
145
148
  );
146
149
  }
@@ -167,7 +170,7 @@ const xiaohongshuPublishAction = async (props) => {
167
170
  const hasCustomContent = shootingDate || shootingLocation;
168
171
  if (shootingLocation) {
169
172
  await selectAddress(
170
- selfShootingPopup.locator(".address-input input"),
173
+ selfShootingPopup.locator(".address-input"),
171
174
  shootingLocation
172
175
  );
173
176
  }
@@ -228,7 +231,8 @@ const generateFile = async (dir) => {
228
231
  }
229
232
  return filePath;
230
233
  };
231
- const createElectronApp = async (cachePath) => {
234
+ const createElectronApp = async (cachePath, playwrightPackage) => {
235
+ const playwright = await playwrightPackage;
232
236
  const mainPath = await generateFile(cachePath);
233
237
  const electronApp = await playwright._electron.launch({
234
238
  executablePath: electron.app.getPath("exe"),
@@ -245,14 +249,15 @@ var __publicField$1 = (obj, key, value) => {
245
249
  return value;
246
250
  };
247
251
  class PackageManager {
248
- // 依赖名称
249
- constructor(packageName, cacheDir) {
252
+ constructor(params) {
250
253
  __publicField$1(this, "cacheDir");
251
254
  // 依赖安装目录
252
- __publicField$1(this, "packageName");
253
- this.cacheDir = cacheDir;
254
- this.packageName = packageName;
255
- this.init();
255
+ __publicField$1(this, "forceUpdate");
256
+ // 是否强制更新
257
+ __publicField$1(this, "initPromise");
258
+ this.cacheDir = params.cacheDir;
259
+ this.forceUpdate = params.forceUpdate || true;
260
+ this.initPromise = this.init(params.packageName, params.packageVersion);
256
261
  }
257
262
  // 在子线程执行 npm 命令
258
263
  execCommand(cmd, modules, where = this.cacheDir) {
@@ -284,7 +289,7 @@ class PackageManager {
284
289
  });
285
290
  }
286
291
  // 构建 package.json 文件,有了该文件后,依赖可以安装在该目录下,避免污染全局环境
287
- async initCacheProject() {
292
+ initCacheProject() {
288
293
  const packagePath = path__default.join(this.cacheDir, "package.json");
289
294
  if (!fs__default.existsSync(packagePath)) {
290
295
  const pkg = {
@@ -292,10 +297,8 @@ class PackageManager {
292
297
  description: "rpa-plugins",
293
298
  license: "MIT"
294
299
  };
295
- await fs__default.ensureFile(packagePath);
296
- await Promise.all([
297
- fs__default.writeFile(packagePath, JSON.stringify(pkg), "utf8")
298
- ]);
300
+ fs__default.ensureFileSync(packagePath);
301
+ fs__default.writeFileSync(packagePath, JSON.stringify(pkg), "utf8");
299
302
  }
300
303
  }
301
304
  // 获取依赖信息
@@ -315,26 +318,31 @@ class PackageManager {
315
318
  return null;
316
319
  }
317
320
  }
321
+ async getPluginAfterInit(module) {
322
+ await this.initPromise;
323
+ return this.getPlugin(module);
324
+ }
318
325
  // 安装依赖
319
- install(module) {
320
- return this.execCommand("install", [module]);
326
+ install(module, version) {
327
+ const moduleName = version ? `${module}@${version}` : module;
328
+ return this.execCommand("install", [moduleName]);
321
329
  }
322
330
  // 更新依赖
323
331
  update(module) {
324
332
  return this.execCommand("update", [module]);
325
333
  }
326
- async init() {
327
- await this.initCacheProject();
328
- const plugin = this.getPlugin(path__default.join(this.packageName, "package.json"));
334
+ async init(name, version) {
335
+ this.initCacheProject();
336
+ const plugin = this.getPlugin(path__default.join(name, "package.json"));
329
337
  if (!plugin) {
330
- await this.install(this.packageName);
331
- } else {
332
- const pkInfo = await this.getPluginInfo(this.packageName);
338
+ await this.install(name, version);
339
+ } else if (this.forceUpdate) {
340
+ const pkInfo = await this.getPluginInfo(name);
333
341
  if (!pkInfo)
334
342
  throw new Error("\u4F9D\u8D56\u4FE1\u606F\u83B7\u53D6\u5931\u8D25");
335
343
  const hasNewVersion = semver__default.gt(pkInfo.version, plugin.version);
336
344
  if (hasNewVersion) {
337
- await this.install(`${this.packageName}@${pkInfo.version}`);
345
+ await this.install(name, pkInfo.version);
338
346
  }
339
347
  }
340
348
  console.log("Package manager init done!");
@@ -347,14 +355,32 @@ var __publicField = (obj, key, value) => {
347
355
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
348
356
  return value;
349
357
  };
358
+ const PLAYWRIGHT_VERSION = "1.46.1";
350
359
  class LocalAutomateTask {
351
360
  constructor(params) {
352
361
  __publicField(this, "cachePath");
353
362
  __publicField(this, "debug");
354
363
  __publicField(this, "appWhenReady");
364
+ __publicField(this, "playwrightPackage");
355
365
  this.cachePath = params.cachePath;
356
366
  this.debug = params.debug || false;
357
- this.appWhenReady = createElectronApp(params.cachePath);
367
+ this.playwrightPackage = this.installPlaywright();
368
+ this.appWhenReady = createElectronApp(
369
+ params.cachePath,
370
+ this.playwrightPackage
371
+ );
372
+ }
373
+ /**
374
+ * 安装 playwright
375
+ * @returns
376
+ */
377
+ installPlaywright() {
378
+ const playwrightPackageManager = new PackageManager({
379
+ packageName: "playwright",
380
+ packageVersion: PLAYWRIGHT_VERSION,
381
+ cacheDir: this.cachePath
382
+ });
383
+ return playwrightPackageManager.getPluginAfterInit("playwright");
358
384
  }
359
385
  /**
360
386
  * 关闭 playwright 启动的 electron 客户端
@@ -418,7 +444,10 @@ class LocalAutomateTask {
418
444
  }
419
445
  }
420
446
  const RpaTask = (params) => {
421
- const packageManager = new PackageManager(packageJson.name, params.cachePath);
447
+ const packageManager = new PackageManager({
448
+ packageName: packageJson.name,
449
+ cacheDir: params.cachePath
450
+ });
422
451
  const localPackge = packageManager.getPlugin(packageJson.name);
423
452
  if (localPackge?.LocalAutomateTask && localPackge?.version && semver__default.gt(localPackge.version, packageJson.version)) {
424
453
  return new localPackge.LocalAutomateTask(params);
package/dist/index.d.cts CHANGED
@@ -47,7 +47,13 @@ declare class LocalAutomateTask implements TaskParams {
47
47
  cachePath: string;
48
48
  debug: boolean;
49
49
  appWhenReady: Promise<ElectronApplication>;
50
+ playwrightPackage: Promise<unknown>;
50
51
  constructor(params: TaskParams);
52
+ /**
53
+ * 安装 playwright
54
+ * @returns
55
+ */
56
+ installPlaywright(): Promise<any>;
51
57
  /**
52
58
  * 关闭 playwright 启动的 electron 客户端
53
59
  * @returns
package/dist/index.d.mts CHANGED
@@ -47,7 +47,13 @@ declare class LocalAutomateTask implements TaskParams {
47
47
  cachePath: string;
48
48
  debug: boolean;
49
49
  appWhenReady: Promise<ElectronApplication>;
50
+ playwrightPackage: Promise<unknown>;
50
51
  constructor(params: TaskParams);
52
+ /**
53
+ * 安装 playwright
54
+ * @returns
55
+ */
56
+ installPlaywright(): Promise<any>;
51
57
  /**
52
58
  * 关闭 playwright 启动的 electron 客户端
53
59
  * @returns
package/dist/index.d.ts CHANGED
@@ -47,7 +47,13 @@ declare class LocalAutomateTask implements TaskParams {
47
47
  cachePath: string;
48
48
  debug: boolean;
49
49
  appWhenReady: Promise<ElectronApplication>;
50
+ playwrightPackage: Promise<unknown>;
50
51
  constructor(params: TaskParams);
52
+ /**
53
+ * 安装 playwright
54
+ * @returns
55
+ */
56
+ installPlaywright(): Promise<any>;
51
57
  /**
52
58
  * 关闭 playwright 启动的 electron 客户端
53
59
  * @returns
package/dist/index.mjs CHANGED
@@ -3,12 +3,11 @@ import path from 'node:path';
3
3
  import axios from 'axios';
4
4
  import fs from 'fs-extra';
5
5
  import { app } from 'electron';
6
- import { _electron } from 'playwright';
7
6
  import spawn from 'cross-spawn';
8
7
 
9
8
  const name = "@iflyrpa/playwright";
10
9
  const type = "module";
11
- const version$1 = "1.0.7";
10
+ const version$1 = "1.0.8";
12
11
  const description = "";
13
12
  const main = "./dist/index.cjs";
14
13
  const module = "./dist/index.mjs";
@@ -93,9 +92,9 @@ const xiaohongshuPublishAction = async (props) => {
93
92
  const selectAddress = async (selector, address) => {
94
93
  const instance = typeof selector === "string" ? page.locator(selector) : selector;
95
94
  await instance.click();
96
- await instance.fill(address);
95
+ await instance.locator("input").fill(address);
97
96
  const poperInstance = page.locator(
98
- ".el-popper[aria-hidden=false] ul li[role=option]"
97
+ '.d-popover:not([style*="display: none"]) .d-options .d-grid-item'
99
98
  );
100
99
  await poperInstance.first().waitFor();
101
100
  await poperInstance.first().click();
@@ -106,8 +105,12 @@ const xiaohongshuPublishAction = async (props) => {
106
105
  await instance.fill(date);
107
106
  await instance.blur();
108
107
  };
109
- await page.waitForSelector("#CreatorPlatform", { state: "visible" });
110
- await page.locator("#content-area .menu-container .publish-video a").click();
108
+ await page.waitForSelector("#CreatorPlatform", { state: "visible" }).catch(() => {
109
+ throw new Error("\u767B\u5F55\u5931\u8D25");
110
+ });
111
+ await page.locator("#content-area .menu-container .publish-video a").click().catch(() => {
112
+ throw new Error("\u672A\u627E\u5230\u53D1\u5E03\u7B14\u8BB0\u6309\u94AE");
113
+ });
111
114
  await page.locator(".creator-container .header .title").filter({ hasText: /^上传图文$/ }).click();
112
115
  const images = await Promise.all(
113
116
  params.banners.map((url) => {
@@ -130,7 +133,7 @@ const xiaohongshuPublishAction = async (props) => {
130
133
  await page.mouse.wheel(0, 500);
131
134
  if (params.address) {
132
135
  await selectAddress(
133
- ".media-extension .address-input input[placeholder=\u6DFB\u52A0\u5730\u70B9]",
136
+ page.locator(".media-extension .address-input").filter({ hasText: "\u6DFB\u52A0\u5730\u70B9" }),
134
137
  params.address
135
138
  );
136
139
  }
@@ -157,7 +160,7 @@ const xiaohongshuPublishAction = async (props) => {
157
160
  const hasCustomContent = shootingDate || shootingLocation;
158
161
  if (shootingLocation) {
159
162
  await selectAddress(
160
- selfShootingPopup.locator(".address-input input"),
163
+ selfShootingPopup.locator(".address-input"),
161
164
  shootingLocation
162
165
  );
163
166
  }
@@ -218,9 +221,10 @@ const generateFile = async (dir) => {
218
221
  }
219
222
  return filePath;
220
223
  };
221
- const createElectronApp = async (cachePath) => {
224
+ const createElectronApp = async (cachePath, playwrightPackage) => {
225
+ const playwright = await playwrightPackage;
222
226
  const mainPath = await generateFile(cachePath);
223
- const electronApp = await _electron.launch({
227
+ const electronApp = await playwright._electron.launch({
224
228
  executablePath: app.getPath("exe"),
225
229
  // 获取 Electron 可执行文件的路径
226
230
  args: [mainPath]
@@ -235,14 +239,15 @@ var __publicField$1 = (obj, key, value) => {
235
239
  return value;
236
240
  };
237
241
  class PackageManager {
238
- // 依赖名称
239
- constructor(packageName, cacheDir) {
242
+ constructor(params) {
240
243
  __publicField$1(this, "cacheDir");
241
244
  // 依赖安装目录
242
- __publicField$1(this, "packageName");
243
- this.cacheDir = cacheDir;
244
- this.packageName = packageName;
245
- this.init();
245
+ __publicField$1(this, "forceUpdate");
246
+ // 是否强制更新
247
+ __publicField$1(this, "initPromise");
248
+ this.cacheDir = params.cacheDir;
249
+ this.forceUpdate = params.forceUpdate || true;
250
+ this.initPromise = this.init(params.packageName, params.packageVersion);
246
251
  }
247
252
  // 在子线程执行 npm 命令
248
253
  execCommand(cmd, modules, where = this.cacheDir) {
@@ -274,7 +279,7 @@ class PackageManager {
274
279
  });
275
280
  }
276
281
  // 构建 package.json 文件,有了该文件后,依赖可以安装在该目录下,避免污染全局环境
277
- async initCacheProject() {
282
+ initCacheProject() {
278
283
  const packagePath = path.join(this.cacheDir, "package.json");
279
284
  if (!fs.existsSync(packagePath)) {
280
285
  const pkg = {
@@ -282,10 +287,8 @@ class PackageManager {
282
287
  description: "rpa-plugins",
283
288
  license: "MIT"
284
289
  };
285
- await fs.ensureFile(packagePath);
286
- await Promise.all([
287
- fs.writeFile(packagePath, JSON.stringify(pkg), "utf8")
288
- ]);
290
+ fs.ensureFileSync(packagePath);
291
+ fs.writeFileSync(packagePath, JSON.stringify(pkg), "utf8");
289
292
  }
290
293
  }
291
294
  // 获取依赖信息
@@ -305,26 +308,31 @@ class PackageManager {
305
308
  return null;
306
309
  }
307
310
  }
311
+ async getPluginAfterInit(module) {
312
+ await this.initPromise;
313
+ return this.getPlugin(module);
314
+ }
308
315
  // 安装依赖
309
- install(module) {
310
- return this.execCommand("install", [module]);
316
+ install(module, version) {
317
+ const moduleName = version ? `${module}@${version}` : module;
318
+ return this.execCommand("install", [moduleName]);
311
319
  }
312
320
  // 更新依赖
313
321
  update(module) {
314
322
  return this.execCommand("update", [module]);
315
323
  }
316
- async init() {
317
- await this.initCacheProject();
318
- const plugin = this.getPlugin(path.join(this.packageName, "package.json"));
324
+ async init(name, version) {
325
+ this.initCacheProject();
326
+ const plugin = this.getPlugin(path.join(name, "package.json"));
319
327
  if (!plugin) {
320
- await this.install(this.packageName);
321
- } else {
322
- const pkInfo = await this.getPluginInfo(this.packageName);
328
+ await this.install(name, version);
329
+ } else if (this.forceUpdate) {
330
+ const pkInfo = await this.getPluginInfo(name);
323
331
  if (!pkInfo)
324
332
  throw new Error("\u4F9D\u8D56\u4FE1\u606F\u83B7\u53D6\u5931\u8D25");
325
333
  const hasNewVersion = semver.gt(pkInfo.version, plugin.version);
326
334
  if (hasNewVersion) {
327
- await this.install(`${this.packageName}@${pkInfo.version}`);
335
+ await this.install(name, pkInfo.version);
328
336
  }
329
337
  }
330
338
  console.log("Package manager init done!");
@@ -337,14 +345,32 @@ var __publicField = (obj, key, value) => {
337
345
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
338
346
  return value;
339
347
  };
348
+ const PLAYWRIGHT_VERSION = "1.46.1";
340
349
  class LocalAutomateTask {
341
350
  constructor(params) {
342
351
  __publicField(this, "cachePath");
343
352
  __publicField(this, "debug");
344
353
  __publicField(this, "appWhenReady");
354
+ __publicField(this, "playwrightPackage");
345
355
  this.cachePath = params.cachePath;
346
356
  this.debug = params.debug || false;
347
- this.appWhenReady = createElectronApp(params.cachePath);
357
+ this.playwrightPackage = this.installPlaywright();
358
+ this.appWhenReady = createElectronApp(
359
+ params.cachePath,
360
+ this.playwrightPackage
361
+ );
362
+ }
363
+ /**
364
+ * 安装 playwright
365
+ * @returns
366
+ */
367
+ installPlaywright() {
368
+ const playwrightPackageManager = new PackageManager({
369
+ packageName: "playwright",
370
+ packageVersion: PLAYWRIGHT_VERSION,
371
+ cacheDir: this.cachePath
372
+ });
373
+ return playwrightPackageManager.getPluginAfterInit("playwright");
348
374
  }
349
375
  /**
350
376
  * 关闭 playwright 启动的 electron 客户端
@@ -408,7 +434,10 @@ class LocalAutomateTask {
408
434
  }
409
435
  }
410
436
  const RpaTask = (params) => {
411
- const packageManager = new PackageManager(packageJson.name, params.cachePath);
437
+ const packageManager = new PackageManager({
438
+ packageName: packageJson.name,
439
+ cacheDir: params.cachePath
440
+ });
412
441
  const localPackge = packageManager.getPlugin(packageJson.name);
413
442
  if (localPackge?.LocalAutomateTask && localPackge?.version && semver.gt(localPackge.version, packageJson.version)) {
414
443
  return new localPackge.LocalAutomateTask(params);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iflyrpa/playwright",
3
3
  "type": "module",
4
- "version": "1.0.7",
4
+ "version": "1.0.8",
5
5
  "description": "",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",