extension-develop 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -32,9 +32,10 @@ var __webpack_modules__ = {
32
32
  f: ()=>DynamicExtensionManager
33
33
  });
34
34
  var fs_promises__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("fs/promises");
35
- var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("path");
36
- var crypto__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("crypto");
37
- var _webpack_lib_messages__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./webpack/webpack-lib/messages.ts");
35
+ var fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("fs");
36
+ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("path");
37
+ var crypto__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("crypto");
38
+ var _webpack_lib_messages__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./webpack/webpack-lib/messages.ts");
38
39
  function _define_property(obj, key, value) {
39
40
  if (key in obj) Object.defineProperty(obj, key, {
40
41
  value: value,
@@ -47,7 +48,7 @@ var __webpack_modules__ = {
47
48
  }
48
49
  class DynamicExtensionManager {
49
50
  generateExtensionKey() {
50
- const keyData = crypto__WEBPACK_IMPORTED_MODULE_2__.randomBytes(128);
51
+ const keyData = crypto__WEBPACK_IMPORTED_MODULE_3__.randomBytes(128);
51
52
  return keyData.toString('base64');
52
53
  }
53
54
  getBaseExtensionPath(browser) {
@@ -59,17 +60,17 @@ var __webpack_modules__ = {
59
60
  'gecko-based': 'gecko-based-manager-extension'
60
61
  };
61
62
  const extensionName = browserMap[browser] || 'chrome-manager-extension';
62
- return path__WEBPACK_IMPORTED_MODULE_1__.join(this.baseExtensionPath, extensionName);
63
+ return path__WEBPACK_IMPORTED_MODULE_2__.join(this.baseExtensionPath, extensionName);
63
64
  }
64
65
  async readBaseManifest(browser) {
65
66
  const basePath = this.getBaseExtensionPath(browser);
66
- const manifestPath = path__WEBPACK_IMPORTED_MODULE_1__.join(basePath, 'manifest.json');
67
+ const manifestPath = path__WEBPACK_IMPORTED_MODULE_2__.join(basePath, 'manifest.json');
67
68
  const manifestContent = await fs_promises__WEBPACK_IMPORTED_MODULE_0__.readFile(manifestPath, 'utf-8');
68
69
  return JSON.parse(manifestContent);
69
70
  }
70
71
  async readBaseServiceWorker(browser) {
71
72
  const basePath = this.getBaseExtensionPath(browser);
72
- const serviceWorkerPath = path__WEBPACK_IMPORTED_MODULE_1__.join(basePath, 'reload-service.js');
73
+ const serviceWorkerPath = path__WEBPACK_IMPORTED_MODULE_2__.join(basePath, 'reload-service.js');
73
74
  return await fs_promises__WEBPACK_IMPORTED_MODULE_0__.readFile(serviceWorkerPath, 'utf-8');
74
75
  }
75
76
  async generateExtension(instance) {
@@ -87,14 +88,14 @@ var __webpack_modules__ = {
87
88
  };
88
89
  const serviceWorkerContent = baseServiceWorker.replace(/const\s+port\s*=\s*['"](__RELOAD_PORT__|\d+)['"]/, `const port = '${instance.webSocketPort}'`).replace(/const\s+instanceId\s*=\s*['"](__INSTANCE_ID__|\w+)['"]/, `const instanceId = '${instance.instanceId}'`);
89
90
  const enhancedServiceWorker = `// Instance: ${instanceId}\n// Generated: ${new Date().toISOString()}\n// Cache-buster: ${Date.now()}\n\n${serviceWorkerContent}\n\n// Instance-specific logging\n${'development' === process.env.EXTENSION_ENV ? `console.log('[Extension.js DevTools] Instance ${instanceId} initialized on port ${instance.webSocketPort}');` : ''}\n`;
90
- const extensionPath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
91
+ const extensionPath = path__WEBPACK_IMPORTED_MODULE_2__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
91
92
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.mkdir(extensionPath, {
92
93
  recursive: true
93
94
  });
94
- const manifestPath = path__WEBPACK_IMPORTED_MODULE_1__.join(extensionPath, 'manifest.json');
95
+ const manifestPath = path__WEBPACK_IMPORTED_MODULE_2__.join(extensionPath, 'manifest.json');
95
96
  const manifestContent = JSON.stringify(manifest, null, 2).replace(/__INSTANCE_ID__/g, instance.instanceId);
96
97
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.writeFile(manifestPath, manifestContent);
97
- const serviceWorkerPath = path__WEBPACK_IMPORTED_MODULE_1__.join(extensionPath, 'reload-service.js');
98
+ const serviceWorkerPath = path__WEBPACK_IMPORTED_MODULE_2__.join(extensionPath, 'reload-service.js');
98
99
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.writeFile(serviceWorkerPath, enhancedServiceWorker);
99
100
  await this.copyExtensionFiles(instance.browser, extensionPath);
100
101
  return {
@@ -111,8 +112,8 @@ var __webpack_modules__ = {
111
112
  withFileTypes: true
112
113
  });
113
114
  for (const entry of entries)if (entry.isDirectory() && 'images' === entry.name) {
114
- const sourceImagesPath = path__WEBPACK_IMPORTED_MODULE_1__.join(basePath, 'images');
115
- const targetImagesPath = path__WEBPACK_IMPORTED_MODULE_1__.join(targetPath, 'images');
115
+ const sourceImagesPath = path__WEBPACK_IMPORTED_MODULE_2__.join(basePath, 'images');
116
+ const targetImagesPath = path__WEBPACK_IMPORTED_MODULE_2__.join(targetPath, 'images');
116
117
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.mkdir(targetImagesPath, {
117
118
  recursive: true
118
119
  });
@@ -120,13 +121,13 @@ var __webpack_modules__ = {
120
121
  withFileTypes: true
121
122
  });
122
123
  for (const imageEntry of imageEntries)if (imageEntry.isFile()) {
123
- const sourceImagePath = path__WEBPACK_IMPORTED_MODULE_1__.join(sourceImagesPath, imageEntry.name);
124
- const targetImagePath = path__WEBPACK_IMPORTED_MODULE_1__.join(targetImagesPath, imageEntry.name);
124
+ const sourceImagePath = path__WEBPACK_IMPORTED_MODULE_2__.join(sourceImagesPath, imageEntry.name);
125
+ const targetImagePath = path__WEBPACK_IMPORTED_MODULE_2__.join(targetImagesPath, imageEntry.name);
125
126
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.copyFile(sourceImagePath, targetImagePath);
126
127
  }
127
128
  } else if (entry.isDirectory() && 'pages' === entry.name) {
128
- const sourcePagesPath = path__WEBPACK_IMPORTED_MODULE_1__.join(basePath, 'pages');
129
- const targetPagesPath = path__WEBPACK_IMPORTED_MODULE_1__.join(targetPath, 'pages');
129
+ const sourcePagesPath = path__WEBPACK_IMPORTED_MODULE_2__.join(basePath, 'pages');
130
+ const targetPagesPath = path__WEBPACK_IMPORTED_MODULE_2__.join(targetPath, 'pages');
130
131
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.mkdir(targetPagesPath, {
131
132
  recursive: true
132
133
  });
@@ -134,17 +135,17 @@ var __webpack_modules__ = {
134
135
  withFileTypes: true
135
136
  });
136
137
  for (const pageEntry of pageEntries)if (pageEntry.isFile()) {
137
- const sourcePagePath = path__WEBPACK_IMPORTED_MODULE_1__.join(sourcePagesPath, pageEntry.name);
138
- const targetPagePath = path__WEBPACK_IMPORTED_MODULE_1__.join(targetPagesPath, pageEntry.name);
138
+ const sourcePagePath = path__WEBPACK_IMPORTED_MODULE_2__.join(sourcePagesPath, pageEntry.name);
139
+ const targetPagePath = path__WEBPACK_IMPORTED_MODULE_2__.join(targetPagesPath, pageEntry.name);
139
140
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.copyFile(sourcePagePath, targetPagePath);
140
141
  }
141
142
  } else if (entry.isFile() && 'manifest.json' !== entry.name && 'reload-service.js' !== entry.name) {
142
- const sourceFilePath = path__WEBPACK_IMPORTED_MODULE_1__.join(basePath, entry.name);
143
- const targetFilePath = path__WEBPACK_IMPORTED_MODULE_1__.join(targetPath, entry.name);
143
+ const sourceFilePath = path__WEBPACK_IMPORTED_MODULE_2__.join(basePath, entry.name);
144
+ const targetFilePath = path__WEBPACK_IMPORTED_MODULE_2__.join(targetPath, entry.name);
144
145
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.copyFile(sourceFilePath, targetFilePath);
145
146
  }
146
147
  } catch (error) {
147
- if ('development' === process.env.EXTENSION_ENV) console.warn(_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_3__.O3(error));
148
+ if ('development' === process.env.EXTENSION_ENV) console.warn(_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_4__.O3(error));
148
149
  }
149
150
  }
150
151
  async cleanupExtension(instanceId) {
@@ -152,10 +153,10 @@ var __webpack_modules__ = {
152
153
  const instanceManager = new InstanceManager(this.projectPath);
153
154
  const instance = await instanceManager.getInstance(instanceId);
154
155
  if (!instance) {
155
- if ('development' === process.env.EXTENSION_ENV) console.warn(_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_3__.ej(instanceId));
156
+ if ('development' === process.env.EXTENSION_ENV) console.warn(_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_4__.ej(instanceId));
156
157
  return;
157
158
  }
158
- const extensionPath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
159
+ const extensionPath = path__WEBPACK_IMPORTED_MODULE_2__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
159
160
  try {
160
161
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.rm(extensionPath, {
161
162
  recursive: true,
@@ -172,18 +173,30 @@ var __webpack_modules__ = {
172
173
  force: true
173
174
  });
174
175
  } catch (error) {
175
- if ('development' === process.env.EXTENSION_ENV) console.warn(_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_3__.rH(error));
176
+ if ('development' === process.env.EXTENSION_ENV) console.warn(_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_4__.rH(error));
176
177
  }
177
178
  }
178
179
  getExtensionPath(instanceId) {
179
- return path__WEBPACK_IMPORTED_MODULE_1__.join(this.userExtensionsPath, `manager-port-${instanceId}`);
180
+ try {
181
+ const InstanceManager = __webpack_require__("./webpack/plugin-browsers/browsers-lib/instance-manager.ts").InstanceManager;
182
+ new InstanceManager(this.projectPath);
183
+ const registryPath = path__WEBPACK_IMPORTED_MODULE_2__.join(__webpack_require__("os").homedir(), 'Library', 'Application Support', 'extension-js', 'instances.json');
184
+ if (fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(registryPath)) try {
185
+ var _data_instances;
186
+ const raw = fs__WEBPACK_IMPORTED_MODULE_1__.readFileSync(registryPath, 'utf-8');
187
+ const data = JSON.parse(raw);
188
+ const info = null == (_data_instances = data.instances) ? void 0 : _data_instances[instanceId];
189
+ if (info && info.browser && 'number' == typeof info.port) return path__WEBPACK_IMPORTED_MODULE_2__.join(this.userExtensionsPath, `${info.browser}-manager-${info.port}`);
190
+ } catch {}
191
+ } catch {}
192
+ return path__WEBPACK_IMPORTED_MODULE_2__.join(this.userExtensionsPath, `manager-port-${instanceId}`);
180
193
  }
181
194
  async extensionExists(instanceId) {
182
195
  const { InstanceManager } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "./webpack/plugin-browsers/browsers-lib/instance-manager.ts"));
183
196
  const instanceManager = new InstanceManager(this.projectPath);
184
197
  const instance = await instanceManager.getInstance(instanceId);
185
198
  if (!instance) return false;
186
- const extensionPath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
199
+ const extensionPath = path__WEBPACK_IMPORTED_MODULE_2__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
187
200
  try {
188
201
  await fs_promises__WEBPACK_IMPORTED_MODULE_0__.access(extensionPath);
189
202
  return true;
@@ -194,8 +207,8 @@ var __webpack_modules__ = {
194
207
  async regenerateExtensionIfNeeded(instance) {
195
208
  const exists = await this.extensionExists(instance.instanceId);
196
209
  if (!exists) return await this.generateExtension(instance);
197
- const extensionPath = this.getExtensionPath(instance.instanceId);
198
- const serviceWorkerPath = path__WEBPACK_IMPORTED_MODULE_1__.join(extensionPath, 'reload-service.js');
210
+ const extensionPath = path__WEBPACK_IMPORTED_MODULE_2__.join(this.userExtensionsPath, `${instance.browser}-manager-${instance.port}`);
211
+ const serviceWorkerPath = path__WEBPACK_IMPORTED_MODULE_2__.join(extensionPath, 'reload-service.js');
199
212
  try {
200
213
  const content = await fs_promises__WEBPACK_IMPORTED_MODULE_0__.readFile(serviceWorkerPath, 'utf-8');
201
214
  const portMatch = content.match(/const\s+port\s*=\s*['"](\d+)['"]/);
@@ -211,7 +224,7 @@ var __webpack_modules__ = {
211
224
  return {
212
225
  extensionId: instance.managerExtensionId,
213
226
  manifest,
214
- serviceWorkerPath: path__WEBPACK_IMPORTED_MODULE_1__.join(extensionPath, 'reload-service.js'),
227
+ serviceWorkerPath: path__WEBPACK_IMPORTED_MODULE_2__.join(extensionPath, 'reload-service.js'),
215
228
  extensionPath
216
229
  };
217
230
  }
@@ -219,9 +232,27 @@ var __webpack_modules__ = {
219
232
  _define_property(this, "baseExtensionPath", void 0);
220
233
  _define_property(this, "projectPath", void 0);
221
234
  _define_property(this, "userExtensionsPath", void 0);
222
- this.baseExtensionPath = path__WEBPACK_IMPORTED_MODULE_1__.join(__dirname, '../webpack/plugin-reload/extensions');
235
+ const candidateBasePaths = [];
236
+ try {
237
+ const entryPath = require.resolve('extension-develop');
238
+ const distDir = path__WEBPACK_IMPORTED_MODULE_2__.dirname(entryPath);
239
+ candidateBasePaths.push(path__WEBPACK_IMPORTED_MODULE_2__.join(distDir, 'extensions'));
240
+ } catch {}
241
+ candidateBasePaths.push(path__WEBPACK_IMPORTED_MODULE_2__.join(__dirname, 'extensions'));
242
+ candidateBasePaths.push(path__WEBPACK_IMPORTED_MODULE_2__.join(__dirname, 'dist', 'extensions'));
243
+ candidateBasePaths.push(path__WEBPACK_IMPORTED_MODULE_2__.join(__dirname, 'programs', 'develop', 'dist', 'extensions'));
244
+ candidateBasePaths.push(path__WEBPACK_IMPORTED_MODULE_2__.join(process.cwd(), 'node_modules', 'extension-develop', 'dist', 'extensions'));
245
+ candidateBasePaths.push(path__WEBPACK_IMPORTED_MODULE_2__.join(__dirname, '..', '..', 'plugin-reload', 'extensions'));
246
+ let resolvedBasePath = candidateBasePaths[0];
247
+ for (const candidate of candidateBasePaths)try {
248
+ if (fs__WEBPACK_IMPORTED_MODULE_1__.existsSync(candidate)) {
249
+ resolvedBasePath = candidate;
250
+ break;
251
+ }
252
+ } catch {}
253
+ this.baseExtensionPath = resolvedBasePath;
223
254
  this.projectPath = projectPath || process.cwd();
224
- this.userExtensionsPath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.projectPath, 'dist', 'extension-js', 'extensions');
255
+ this.userExtensionsPath = path__WEBPACK_IMPORTED_MODULE_2__.join(this.projectPath, 'dist', 'extension-js', 'extensions');
225
256
  }
226
257
  }
227
258
  },
@@ -464,6 +495,18 @@ var __webpack_modules__ = {
464
495
  if ('development' === process.env.EXTENSION_ENV) console.log(_webpack_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_5__.JJ());
465
496
  }
466
497
  async createInstance(browser, projectPath, requestedPort) {
498
+ const lockPath = path__WEBPACK_IMPORTED_MODULE_1__.join(this.getDataDirectory(), 'instances.lock');
499
+ let lockHandle = null;
500
+ for(let attempt = 0; attempt < 10; attempt++)try {
501
+ lockHandle = await (await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "fs/promises", 23))).open(lockPath, 'wx');
502
+ break;
503
+ } catch (err) {
504
+ if (err && 'EEXIST' === err.code) {
505
+ await new Promise((r)=>setTimeout(r, 25 * (attempt + 1)));
506
+ continue;
507
+ }
508
+ throw err;
509
+ }
467
510
  if ('development' === process.env.EXTENSION_ENV) console.log(_webpack_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_5__.jE({
468
511
  browser,
469
512
  projectPath,
@@ -490,6 +533,10 @@ var __webpack_modules__ = {
490
533
  await this.saveRegistry(registry);
491
534
  await this.monitorProcessHealth(instanceId);
492
535
  if ('development' === process.env.EXTENSION_ENV) console.log(_webpack_webpack_lib_messages__WEBPACK_IMPORTED_MODULE_5__.pU(registry));
536
+ try {
537
+ if (lockHandle && 'function' == typeof lockHandle.close) await lockHandle.close();
538
+ await (await Promise.resolve().then(__webpack_require__.t.bind(__webpack_require__, "fs/promises", 23))).unlink(lockPath);
539
+ } catch {}
493
540
  return instance;
494
541
  }
495
542
  async updateInstance(instanceId, updates) {
@@ -594,6 +641,7 @@ var __webpack_modules__ = {
594
641
  ET: ()=>sourceInspectorFileChanged,
595
642
  El: ()=>firefoxFailedToStart,
596
643
  F0: ()=>sourceInspectorUsingExistingTarget,
644
+ G$: ()=>devFirefoxProfilePath,
597
645
  G9: ()=>sourceInspectorStartingWatchMode,
598
646
  GB: ()=>cdpClientExtensionReloadFailed,
599
647
  GR: ()=>sourceInspectorAttachedToTarget,
@@ -643,6 +691,7 @@ var __webpack_modules__ = {
643
691
  Ym: ()=>sourceInspectorUrlRequired,
644
692
  Yw: ()=>sourceInspectorChromeNotReadyYet,
645
693
  ZM: ()=>firefoxBinaryArgsExtracted,
694
+ ZZ: ()=>devFirefoxDebugPort,
646
695
  Zk: ()=>sourceInspectorOpeningUrl,
647
696
  _A: ()=>enhancedProcessManagementTerminating,
648
697
  _C: ()=>cdpClientCheckingShadowDOM,
@@ -691,6 +740,7 @@ var __webpack_modules__ = {
691
740
  uc: ()=>enhancedProcessManagementInstanceCleanupComplete,
692
741
  v5: ()=>sourceInspectorCreatingTarget,
693
742
  w4: ()=>sourceInspectorReconnectionFailed,
743
+ x: ()=>devChromiumDebugPort,
694
744
  xQ: ()=>runningInDevelopment,
695
745
  xR: ()=>sourceInspectorEnablingPageDomain,
696
746
  y4: ()=>sourceInspectorSetupFailed,
@@ -1084,13 +1134,21 @@ var __webpack_modules__ = {
1084
1134
  function emptyLine() {
1085
1135
  return '';
1086
1136
  }
1137
+ function devChromiumDebugPort(finalPort, requestedPort) {
1138
+ return `${pintor__WEBPACK_IMPORTED_MODULE_0___default().brightMagenta("\u25BA\u25BA\u25BA")} ${pintor__WEBPACK_IMPORTED_MODULE_0___default().brightMagenta('Dev')} Chromium debug port: ${pintor__WEBPACK_IMPORTED_MODULE_0___default().gray(finalPort.toString())} (requested ${pintor__WEBPACK_IMPORTED_MODULE_0___default().gray(requestedPort.toString())})`;
1139
+ }
1140
+ function devFirefoxDebugPort(finalPort, requestedPort) {
1141
+ return `${pintor__WEBPACK_IMPORTED_MODULE_0___default().brightMagenta("\u25BA\u25BA\u25BA")} ${pintor__WEBPACK_IMPORTED_MODULE_0___default().brightMagenta('Dev')} Firefox debug port: ${pintor__WEBPACK_IMPORTED_MODULE_0___default().gray(finalPort.toString())} (requested ${pintor__WEBPACK_IMPORTED_MODULE_0___default().gray(requestedPort.toString())})`;
1142
+ }
1143
+ function devFirefoxProfilePath(profilePath) {
1144
+ return `${pintor__WEBPACK_IMPORTED_MODULE_0___default().brightMagenta("\u25BA\u25BA\u25BA")} ${pintor__WEBPACK_IMPORTED_MODULE_0___default().brightMagenta('Dev')} Firefox profile: ${pintor__WEBPACK_IMPORTED_MODULE_0___default().underline(profilePath)}`;
1145
+ }
1087
1146
  },
1088
1147
  "./webpack/plugin-browsers/browsers-lib/shared-utils.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1089
1148
  __webpack_require__.d(__webpack_exports__, {
1090
- c5: ()=>calculateDebugPort,
1091
1149
  gB: ()=>filterBrowserFlags,
1092
- tu: ()=>chooseEffectiveInstanceId,
1093
1150
  rX: ()=>isChromiumProfileLocked,
1151
+ tu: ()=>chooseEffectiveInstanceId,
1094
1152
  _v: ()=>mergePreferences,
1095
1153
  x$: ()=>validateProfilePath,
1096
1154
  km: ()=>findAvailablePortNear,
@@ -1192,7 +1250,7 @@ var __webpack_modules__ = {
1192
1250
  }
1193
1251
  function chooseEffectiveInstanceId(reuseRequested, _concurrent, lockPresent, instanceId) {
1194
1252
  const reuse = void 0 === reuseRequested ? true : !!reuseRequested;
1195
- const canShare = reuse && !lockPresent;
1253
+ const canShare = reuse && !_concurrent && !lockPresent;
1196
1254
  return canShare ? void 0 : instanceId;
1197
1255
  }
1198
1256
  function calculateDebugPort(portFromConfig, devServerPort, defaultPort = DEFAULT_DEBUG_PORT) {
@@ -1368,11 +1426,27 @@ var __webpack_modules__ = {
1368
1426
  const shortId = instanceId ? String(instanceId).slice(0, 8) : void 0;
1369
1427
  const instanceAwareProfilePath = shortId ? external_path_.join(defaultProfilePath, shortId) : defaultProfilePath;
1370
1428
  (0, shared_utils.x$)(browser, instanceAwareProfilePath);
1429
+ const preferencesPath = external_path_.join(instanceAwareProfilePath, 'Default', 'Preferences');
1371
1430
  try {
1372
- if (external_fs_.existsSync(instanceAwareProfilePath)) return instanceAwareProfilePath;
1431
+ if (external_fs_.existsSync(instanceAwareProfilePath)) {
1432
+ if (!external_fs_.existsSync(preferencesPath)) {
1433
+ if (!(0, shared_utils.rX)(instanceAwareProfilePath)) {
1434
+ const basePrefs = 'chrome' === browser ? chromeMasterPreferences : edgeMasterPreferences;
1435
+ const mergedPrefs = {
1436
+ ...basePrefs,
1437
+ ...configPreferences
1438
+ };
1439
+ try {
1440
+ external_fs_.mkdirSync(external_path_.dirname(preferencesPath), {
1441
+ recursive: true
1442
+ });
1443
+ } catch {}
1444
+ external_fs_.writeFileSync(preferencesPath, JSON.stringify(mergedPrefs), 'utf8');
1445
+ }
1446
+ }
1447
+ return instanceAwareProfilePath;
1448
+ }
1373
1449
  } catch {}
1374
- const preferencesPath = external_path_.join(instanceAwareProfilePath, 'Default', 'Preferences');
1375
- if (external_fs_.existsSync(preferencesPath)) return instanceAwareProfilePath;
1376
1450
  const preferences = 'chrome' === browser ? chromeMasterPreferences : edgeMasterPreferences;
1377
1451
  const userProfile = {
1378
1452
  ...preferences,
@@ -1460,7 +1534,7 @@ var __webpack_modules__ = {
1460
1534
  ...aiOptimizedFlags,
1461
1535
  ...sourceEnabled ? [
1462
1536
  `--remote-debugging-port=${cdpPort}`,
1463
- '--remote-debugging-address=localhost'
1537
+ '--remote-debugging-address=127.0.0.1'
1464
1538
  ] : [],
1465
1539
  ...filteredFlags,
1466
1540
  ...configOptions.browserFlags || []
@@ -1488,7 +1562,12 @@ var __webpack_modules__ = {
1488
1562
  browserBinaryLocation = external_chrome_location2_default()();
1489
1563
  break;
1490
1564
  case 'edge':
1491
- browserBinaryLocation = external_edge_location_default()();
1565
+ try {
1566
+ browserBinaryLocation = external_edge_location_default()();
1567
+ } catch (e) {
1568
+ console.error(messages.iv(browser, 'edge binary not found'));
1569
+ process.exit(1);
1570
+ }
1492
1571
  break;
1493
1572
  case 'chromium-based':
1494
1573
  browserBinaryLocation = external_path_.normalize(this.chromiumBinary);
@@ -1533,8 +1612,10 @@ var __webpack_modules__ = {
1533
1612
  }
1534
1613
  let chromiumConfig;
1535
1614
  try {
1615
+ const profileForConfig = false === this.profile && (await instanceManager.getRunningInstances()).some((i)=>'running' === i.status && i.browser === this.browser) ? void 0 : this.profile;
1536
1616
  chromiumConfig = browserConfig(compilation, {
1537
1617
  ...this,
1618
+ profile: profileForConfig,
1538
1619
  instanceId: effectiveInstanceId,
1539
1620
  extension: extensionsToLoad
1540
1621
  });
@@ -1552,6 +1633,14 @@ var __webpack_modules__ = {
1552
1633
  const desiredPort = (0, shared_utils.Zb)(this.port, this.instanceId);
1553
1634
  const freePort = await (0, shared_utils.km)(desiredPort);
1554
1635
  if (freePort !== desiredPort) chromiumConfig = chromiumConfig.map((flag)=>flag.startsWith('--remote-debugging-port=') ? `--remote-debugging-port=${freePort}` : flag);
1636
+ try {
1637
+ if (this.instanceId) {
1638
+ await instanceManager.updateInstance(this.instanceId, {
1639
+ debugPort: freePort
1640
+ });
1641
+ if ('development' === process.env.EXTENSION_ENV) console.log(messages.x(freePort, desiredPort));
1642
+ }
1643
+ } catch {}
1555
1644
  }
1556
1645
  if (this.dryRun) {
1557
1646
  console.log(messages.Lh());
@@ -2257,9 +2346,11 @@ var __webpack_modules__ = {
2257
2346
  }
2258
2347
  let firefoxConfig;
2259
2348
  try {
2349
+ const hasConcurrent = (await instanceManager.getRunningInstances()).some((i)=>'running' === i.status && i.browser === this.browser);
2350
+ const profileForConfig = false === this.profile && hasConcurrent ? void 0 : this.profile;
2260
2351
  firefoxConfig = await browserConfig(compilation, {
2261
2352
  ...options,
2262
- profile: this.profile,
2353
+ profile: profileForConfig,
2263
2354
  preferences: this.preferences,
2264
2355
  keepProfileChanges: this.keepProfileChanges,
2265
2356
  copyFromProfile: this.copyFromProfile,
@@ -2345,6 +2436,18 @@ var __webpack_modules__ = {
2345
2436
  console.error(messages.Q(this.browser, error));
2346
2437
  process.exit(1);
2347
2438
  }
2439
+ try {
2440
+ if (this.instanceId && profileMatch) {
2441
+ await instanceManager.updateInstance(this.instanceId, {
2442
+ debugPort,
2443
+ effectiveProfilePath: profileMatch[1]
2444
+ });
2445
+ if ('development' === process.env.EXTENSION_ENV) {
2446
+ console.log(messages.ZZ(debugPort, desiredDebugPort));
2447
+ console.log(messages.G$(profileMatch[1]));
2448
+ }
2449
+ }
2450
+ } catch {}
2348
2451
  } else {
2349
2452
  const args = [
2350
2453
  ...debugPort > 0 ? [
@@ -3325,7 +3428,7 @@ var __webpack_modules__ = {
3325
3428
  module.exports = require("util");
3326
3429
  },
3327
3430
  "./package.json": function(module) {
3328
- module.exports = JSON.parse('{"i8":"2.0.3","HO":{"@rspack/core":"^1.4.8","@rspack/dev-server":"^1.1.3","@swc/helpers":"^0.5.15","@types/webextension-polyfill":"0.12.3","@vue/compiler-sfc":"^3.5.13","adm-zip":"^0.5.16","axios":"^1.9.0","case-sensitive-paths-webpack-plugin":"^2.4.0","chokidar":"^4.0.1","chrome-location2":"2.0.0","content-security-policy-parser":"^0.6.0","cross-spawn":"^7.0.6","dotenv":"^16.4.7","dotenv-webpack":"^8.1.0","edge-location":"^1.1.1","firefox-location2":"1.0.0","firefox-profile":"^4.7.0","go-git-it":"^5.0.0","ignore":"^6.0.2","loader-utils":"^3.3.1","locate-path":"^7.2.0","micromatch":"^4.0.8","package-manager-detector":"^0.2.7","parse5":"^7.2.1","parse5-utilities":"^1.0.0","pintor":"0.3.0","postcss":"^8.4.49","preact":"^10.22.0","progress":"^2.0.3","schema-utils":"^4.2.0","slugify":"^1.6.6","tiny-glob":"^0.2.9","webextension-polyfill":"^0.12.0","webpack-merge":"^6.0.1","webpack-target-webextension":"^2.1.3","ws":"^8.18.0"},"Lq":{"@prefresh/core":"^1.5.2","@prefresh/utils":"^1.2.0","@prefresh/webpack":"^4.0.1","@rspack/plugin-preact-refresh":"^1.1.2","@rspack/plugin-react-refresh":"^1.0.1","babel-loader":"^9.2.1","less-loader":"^12.2.0","postcss-loader":"^8.1.1","postcss-preset-env":"^10.1.1","react-refresh":"^0.14.2","sass-loader":"^16.0.4","svelte-loader":"^3.2.4","vue-loader":"^17.4.2","vue-style-loader":"^4.1.3"}}');
3431
+ module.exports = JSON.parse('{"i8":"2.1.0","HO":{"@rspack/core":"^1.4.8","@rspack/dev-server":"^1.1.3","@swc/helpers":"^0.5.15","@types/webextension-polyfill":"0.12.3","@vue/compiler-sfc":"^3.5.13","adm-zip":"^0.5.16","axios":"^1.9.0","case-sensitive-paths-webpack-plugin":"^2.4.0","chokidar":"^4.0.1","chrome-location2":"2.0.0","content-security-policy-parser":"^0.6.0","cross-spawn":"^7.0.6","dotenv":"^16.4.7","dotenv-webpack":"^8.1.0","edge-location":"^1.1.1","firefox-location2":"1.0.0","firefox-profile":"^4.7.0","go-git-it":"^5.0.0","ignore":"^6.0.2","loader-utils":"^3.3.1","locate-path":"^7.2.0","micromatch":"^4.0.8","package-manager-detector":"^0.2.7","parse5":"^7.2.1","parse5-utilities":"^1.0.0","pintor":"0.3.0","postcss":"^8.4.49","preact":"^10.22.0","progress":"^2.0.3","schema-utils":"^4.2.0","slugify":"^1.6.6","tiny-glob":"^0.2.9","webextension-polyfill":"^0.12.0","webpack-merge":"^6.0.1","webpack-target-webextension":"^2.1.3","ws":"^8.18.0"},"Lq":{"@prefresh/core":"^1.5.2","@prefresh/utils":"^1.2.0","@prefresh/webpack":"^4.0.1","@rspack/plugin-preact-refresh":"^1.1.2","@rspack/plugin-react-refresh":"^1.0.1","babel-loader":"^9.2.1","less-loader":"^12.2.0","postcss-loader":"^8.1.1","postcss-preset-env":"^10.1.1","react-refresh":"^0.14.2","sass-loader":"^16.0.4","svelte-loader":"^3.2.4","vue-loader":"^17.4.2","vue-style-loader":"^4.1.3"}}');
3329
3432
  }
3330
3433
  };
3331
3434
  var __webpack_module_cache__ = {};
@@ -3347,6 +3450,33 @@ function __webpack_require__(moduleId) {
3347
3450
  return getter;
3348
3451
  };
3349
3452
  })();
3453
+ (()=>{
3454
+ var getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__;
3455
+ var leafPrototypes;
3456
+ __webpack_require__.t = function(value, mode) {
3457
+ if (1 & mode) value = this(value);
3458
+ if (8 & mode) return value;
3459
+ if ('object' == typeof value && value) {
3460
+ if (4 & mode && value.__esModule) return value;
3461
+ if (16 & mode && 'function' == typeof value.then) return value;
3462
+ }
3463
+ var ns = Object.create(null);
3464
+ __webpack_require__.r(ns);
3465
+ var def = {};
3466
+ leafPrototypes = leafPrototypes || [
3467
+ null,
3468
+ getProto({}),
3469
+ getProto([]),
3470
+ getProto(getProto)
3471
+ ];
3472
+ for(var current = 2 & mode && value; 'object' == typeof current && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{
3473
+ def[key] = ()=>value[key];
3474
+ });
3475
+ def['default'] = ()=>value;
3476
+ __webpack_require__.d(ns, def);
3477
+ return ns;
3478
+ };
3479
+ })();
3350
3480
  (()=>{
3351
3481
  __webpack_require__.d = (exports1, definition)=>{
3352
3482
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
@@ -7934,6 +8064,7 @@ var __webpack_exports__ = {};
7934
8064
  browser: this.browser,
7935
8065
  mode: compiler.options.mode || 'development'
7936
8066
  });
8067
+ compiler.options.webSocketServer = this.webSocketServer;
7937
8068
  this.isServerInitialized = true;
7938
8069
  if ('development' === process.env.EXTENSION_ENV) console.log(webSocketServerInitialized());
7939
8070
  } catch (error) {
@@ -8396,10 +8527,7 @@ var __webpack_exports__ = {};
8396
8527
  }
8397
8528
  }
8398
8529
  const setup_reload_strategy = SetupReloadStrategy;
8399
- var browsers_lib_messages = __webpack_require__("./webpack/plugin-browsers/browsers-lib/messages.ts");
8400
- var messaging_client = __webpack_require__("./webpack/plugin-browsers/run-firefox/remote-firefox/messaging-client.ts");
8401
- var shared_utils = __webpack_require__("./webpack/plugin-browsers/browsers-lib/shared-utils.ts");
8402
- function setup_firefox_inspection_define_property(obj, key, value) {
8530
+ function plugin_reload_define_property(obj, key, value) {
8403
8531
  if (key in obj) Object.defineProperty(obj, key, {
8404
8532
  value: value,
8405
8533
  enumerable: true,
@@ -8409,269 +8537,113 @@ var __webpack_exports__ = {};
8409
8537
  else obj[key] = value;
8410
8538
  return obj;
8411
8539
  }
8412
- const MAX_CONNECT_RETRIES = 60;
8413
- const CONNECT_RETRY_INTERVAL_MS = 500;
8414
- const PAGE_READY_TIMEOUT_MS = 8000;
8415
- const TARGET_SCAN_INTERVAL_MS = 250;
8416
- const CHANGE_DEBOUNCE_MS = 300;
8417
- function wait(ms) {
8418
- return new Promise((resolve)=>setTimeout(resolve, ms));
8419
- }
8420
- class SetupFirefoxInspectionStep {
8421
- getRdpPort() {
8422
- return (0, shared_utils.Zb)(this.devOptions.port, this.devOptions.instanceId);
8540
+ class ReloadPlugin {
8541
+ apply(compiler) {
8542
+ if (this.instanceId) compiler.options.currentInstance = {
8543
+ instanceId: this.instanceId
8544
+ };
8545
+ if ('development' !== compiler.options.mode) return;
8546
+ new CreateWebSocketServer({
8547
+ manifestPath: this.manifestPath,
8548
+ browser: this.browser,
8549
+ port: this.port,
8550
+ stats: this.stats,
8551
+ instanceId: this.instanceId
8552
+ }).apply(compiler);
8553
+ new setup_reload_strategy({
8554
+ manifestPath: this.manifestPath,
8555
+ browser: this.browser,
8556
+ autoReload: this.autoReload,
8557
+ stats: this.stats,
8558
+ port: this.port,
8559
+ instanceId: this.instanceId
8560
+ }).apply(compiler);
8423
8561
  }
8424
- async initialize() {
8425
- if (this.initialized) return;
8426
- const client = new messaging_client.v();
8427
- const port = this.getRdpPort();
8562
+ constructor(options){
8563
+ plugin_reload_define_property(this, "manifestPath", void 0);
8564
+ plugin_reload_define_property(this, "browser", void 0);
8565
+ plugin_reload_define_property(this, "port", void 0);
8566
+ plugin_reload_define_property(this, "stats", void 0);
8567
+ plugin_reload_define_property(this, "autoReload", void 0);
8568
+ plugin_reload_define_property(this, "instanceId", void 0);
8569
+ this.manifestPath = options.manifestPath;
8570
+ this.browser = options.browser || 'chrome';
8571
+ this.port = parseInt(options.port, 10);
8572
+ this.stats = options.stats;
8573
+ this.autoReload = options.autoReload;
8574
+ this.instanceId = options.instanceId;
8575
+ }
8576
+ }
8577
+ plugin_reload_define_property(ReloadPlugin, "name", 'plugin-reload');
8578
+ function feature_polyfill_define_property(obj, key, value) {
8579
+ if (key in obj) Object.defineProperty(obj, key, {
8580
+ value: value,
8581
+ enumerable: true,
8582
+ configurable: true,
8583
+ writable: true
8584
+ });
8585
+ else obj[key] = value;
8586
+ return obj;
8587
+ }
8588
+ class PolyfillPlugin {
8589
+ apply(compiler) {
8428
8590
  try {
8429
- console.log(browsers_lib_messages.l());
8430
- } catch {}
8431
- let retries = 0;
8432
- while(retries < MAX_CONNECT_RETRIES)try {
8433
- await client.connect(port);
8434
- this.client = client;
8435
- this.initialized = true;
8436
- try {
8437
- console.log(browsers_lib_messages.Xy());
8438
- console.log(browsers_lib_messages.Qe());
8439
- } catch {}
8440
- return;
8441
- } catch (err) {
8442
- retries++;
8443
- if (retries % 10 === 0) try {
8444
- console.log(browsers_lib_messages.X_(retries, MAX_CONNECT_RETRIES));
8445
- } catch {}
8446
- await wait(CONNECT_RETRY_INTERVAL_MS);
8591
+ const context = compiler.options.context;
8592
+ const polyfillPath = require.resolve('webextension-polyfill/dist/browser-polyfill.js', {
8593
+ paths: [
8594
+ context
8595
+ ]
8596
+ });
8597
+ new (core_default()).ProvidePlugin({
8598
+ browser: polyfillPath
8599
+ }).apply(compiler);
8600
+ } catch (error) {
8601
+ console.warn(webpack_lib_messages.or());
8447
8602
  }
8448
- throw new Error(browsers_lib_messages.V9(port));
8449
8603
  }
8450
- resolveUrlToInspect() {
8451
- if (this.devOptions.source && 'string' == typeof this.devOptions.source && 'true' !== this.devOptions.source) return this.devOptions.source;
8452
- if (this.devOptions.startingUrl) return this.devOptions.startingUrl;
8453
- throw new Error(browsers_lib_messages.Ym());
8604
+ constructor(options){
8605
+ feature_polyfill_define_property(this, "manifestPath", void 0);
8606
+ feature_polyfill_define_property(this, "browser", void 0);
8607
+ this.manifestPath = options.manifestPath;
8608
+ this.browser = options.browser;
8454
8609
  }
8455
- async selectActors(urlToInspect) {
8456
- if (!this.client) throw new Error(browsers_lib_messages.pl());
8457
- const deadline = Date.now() + 10000;
8458
- let triedAddTab = false;
8459
- while(Date.now() < deadline){
8460
- const allTargets = await this.client.getTargets() || [];
8461
- for (const target of allTargets)if (target && 'string' == typeof target.url && target.url === urlToInspect && target.actor) return {
8462
- tabActor: target.actor,
8463
- consoleActor: target.consoleActor || target.actor
8464
- };
8465
- if (!triedAddTab && urlToInspect) {
8466
- triedAddTab = true;
8467
- try {
8468
- await this.client.addTab(urlToInspect);
8469
- await wait(300);
8470
- continue;
8471
- } catch {}
8472
- }
8473
- for (const target of allTargets)if (target && (target.actor || target.outerWindowID)) return {
8474
- tabActor: target.actor,
8475
- consoleActor: target.consoleActor || target.actor
8476
- };
8477
- await wait(TARGET_SCAN_INTERVAL_MS);
8478
- }
8479
- throw new Error(browsers_lib_messages.qP());
8610
+ }
8611
+ function feature_browser_specific_fields_define_property(obj, key, value) {
8612
+ if (key in obj) Object.defineProperty(obj, key, {
8613
+ value: value,
8614
+ enumerable: true,
8615
+ configurable: true,
8616
+ writable: true
8617
+ });
8618
+ else obj[key] = value;
8619
+ return obj;
8620
+ }
8621
+ class BrowserSpecificFieldsPlugin {
8622
+ patchManifest(manifest) {
8623
+ const patchedManifest = filterKeysForThisBrowser(manifest, this.browser);
8624
+ return JSON.stringify(patchedManifest, null, 2);
8480
8625
  }
8481
- async ensureNavigatedAndLoaded(urlToInspect, tabActor) {
8482
- if (!this.client) throw new Error(browsers_lib_messages.pl());
8483
- if (!tabActor) throw new Error(browsers_lib_messages.Do());
8484
- let consoleActor = tabActor;
8485
- let frameActor = tabActor;
8486
- try {
8487
- const detail = await this.client.getTargetFromDescriptor(tabActor);
8488
- if (detail.consoleActor) consoleActor = detail.consoleActor;
8489
- if (detail.targetActor) frameActor = detail.targetActor;
8490
- } catch {}
8491
- try {
8492
- await this.client.attach(frameActor);
8493
- } catch {}
8494
- try {
8495
- await this.client.navigateViaScript(consoleActor, urlToInspect);
8496
- await this.client.waitForPageReady(consoleActor, urlToInspect, PAGE_READY_TIMEOUT_MS);
8497
- return;
8498
- } catch {}
8499
- try {
8500
- const detail = await this.client.getTargetFromDescriptor(tabActor);
8501
- const targetActor = detail.targetActor || tabActor;
8502
- try {
8503
- await this.client.attach(targetActor);
8504
- } catch {}
8505
- await this.client.navigate(targetActor, urlToInspect);
8506
- await this.client.waitForLoadEvent(targetActor);
8507
- } catch {}
8626
+ apply(compiler) {
8627
+ compiler.hooks.compilation.tap('compatibility:browser-specific-fields', (compilation)=>{
8628
+ compilation.hooks.processAssets.tap({
8629
+ name: 'compatibility:browser-specific-fields',
8630
+ stage: core_namespaceObject.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
8631
+ }, ()=>{
8632
+ const manifest = getManifestContent(compilation, this.manifestPath);
8633
+ const patchedSource = this.patchManifest(manifest);
8634
+ const rawSource = new core_namespaceObject.sources.RawSource(patchedSource);
8635
+ compilation.updateAsset('manifest.json', rawSource);
8636
+ });
8637
+ });
8508
8638
  }
8509
- async ensureUrlAndReady(consoleActor, urlToInspect) {
8510
- if (!this.client) return;
8511
- try {
8512
- const href = await this.client.evaluate(consoleActor, 'String(location.href)');
8513
- if ('string' != typeof href || !href.startsWith(urlToInspect)) await this.client.navigateViaScript(consoleActor, urlToInspect);
8514
- } catch {}
8515
- await this.client.waitForPageReady(consoleActor, urlToInspect, PAGE_READY_TIMEOUT_MS);
8516
- }
8517
- async resolveConsoleActor(tabActor, urlToInspect) {
8518
- if (!this.client) throw new Error(browsers_lib_messages.pl());
8519
- const start = Date.now();
8520
- while(Date.now() - start < PAGE_READY_TIMEOUT_MS){
8521
- try {
8522
- const targets = await this.client.getTargets();
8523
- const byActor = targets.find((t)=>t && t.actor === tabActor);
8524
- const byUrl = targets.find((t)=>t && t.url === urlToInspect);
8525
- const match = byActor || byUrl;
8526
- const ca = (null == match ? void 0 : match.consoleActor) || (null == match ? void 0 : match.webConsoleActor);
8527
- if ('string' == typeof ca && ca.length > 0) return ca;
8528
- try {
8529
- const detail = await this.client.getTargetFromDescriptor(tabActor);
8530
- const guessed = detail.consoleActor;
8531
- if ('string' == typeof guessed && guessed.length > 0) return guessed;
8532
- } catch {}
8533
- } catch {}
8534
- await wait(200);
8535
- }
8536
- return tabActor;
8537
- }
8538
- async printHTML(consoleActor) {
8539
- if (!this.client) throw new Error('RDP client not initialized');
8540
- let lastError = null;
8541
- for(let attempt = 0; attempt < 3; attempt++){
8542
- let actorToUse = consoleActor;
8543
- try {
8544
- if (this.currentTabActor && this.lastUrlToInspect) {
8545
- const fresh = await this.resolveConsoleActor(this.currentTabActor, this.lastUrlToInspect);
8546
- if (fresh) actorToUse = fresh;
8547
- }
8548
- } catch {}
8549
- try {
8550
- const descriptor = this.currentTabActor || actorToUse;
8551
- if (this.lastUrlToInspect) await this.ensureUrlAndReady(actorToUse, this.lastUrlToInspect);
8552
- try {
8553
- const currentUrl = await this.client.evaluate(actorToUse, 'String(location.href)');
8554
- const currentTitle = await this.client.evaluate(actorToUse, 'String(document.title)');
8555
- console.log(browsers_lib_messages.dI());
8556
- console.log(browsers_lib_messages.Hd(`URL: ${currentUrl} | TITLE: ${currentTitle}`));
8557
- } catch {}
8558
- const html = await this.client.getPageHTML(descriptor, actorToUse) || '';
8559
- console.log(html);
8560
- console.log(browsers_lib_messages.qX());
8561
- return;
8562
- } catch (err) {
8563
- lastError = err;
8564
- }
8565
- await wait(200);
8566
- }
8567
- throw lastError || new Error(browsers_lib_messages.Cn());
8568
- }
8569
- async waitForContentScriptInjection(consoleActor) {
8570
- if (!this.client) return;
8571
- const deadline = Date.now() + PAGE_READY_TIMEOUT_MS;
8572
- while(Date.now() < deadline){
8573
- try {
8574
- const injected = await this.client.evaluate(consoleActor, `(() => {
8575
- const root = document.getElementById('extension-root');
8576
- if (!root || !root.shadowRoot) return false;
8577
- const html = root.shadowRoot.innerHTML || '';
8578
- return html.length > 0;
8579
- })()`);
8580
- if (injected) return;
8581
- } catch {}
8582
- await wait(200);
8583
- }
8584
- }
8585
- setupWebSocketHandler(websocketServer) {
8586
- if (!websocketServer || !websocketServer.clients) return;
8587
- websocketServer.clients.forEach((ws)=>{
8588
- this.attachConnection(ws);
8589
- });
8590
- websocketServer.on('connection', (ws)=>{
8591
- this.attachConnection(ws);
8592
- });
8593
- }
8594
- attachConnection(ws) {
8595
- ws.on('message', async (data)=>{
8596
- try {
8597
- const message = JSON.parse(data);
8598
- if ('changedFile' === message.type && this.isWatching) await this.handleFileChange();
8599
- } catch {}
8600
- });
8601
- }
8602
- async handleFileChange() {
8603
- if (!this.client || !this.currentConsoleActor) return;
8604
- if (this.debounceTimer) clearTimeout(this.debounceTimer);
8605
- this.debounceTimer = setTimeout(async ()=>{
8606
- try {
8607
- if (this.currentTabActor && this.lastUrlToInspect) {
8608
- const freshConsole = await this.resolveConsoleActor(this.currentTabActor, this.lastUrlToInspect);
8609
- if (freshConsole) this.currentConsoleActor = freshConsole;
8610
- }
8611
- if (this.lastUrlToInspect) await this.ensureUrlAndReady(this.currentConsoleActor, this.lastUrlToInspect);
8612
- await this.waitForContentScriptInjection(this.currentConsoleActor);
8613
- let lastError = null;
8614
- for(let attempt = 0; attempt < 3; attempt++){
8615
- try {
8616
- const descriptor = this.currentTabActor || this.currentConsoleActor;
8617
- const html = await this.client.getPageHTML(descriptor, this.currentConsoleActor);
8618
- console.log(browsers_lib_messages.dI());
8619
- console.log(browsers_lib_messages.Hd("UPDATED - after content script injection"));
8620
- console.log(html);
8621
- console.log(browsers_lib_messages.qX());
8622
- return;
8623
- } catch (err) {
8624
- lastError = err;
8625
- }
8626
- await wait(200);
8627
- }
8628
- throw lastError || new Error('Failed to update HTML after retries');
8629
- } catch (err) {
8630
- console.error(browsers_lib_messages.QB(err.message));
8631
- }
8632
- }, CHANGE_DEBOUNCE_MS);
8633
- }
8634
- apply(compiler) {
8635
- if (!this.devOptions.source && !this.devOptions.watchSource) return;
8636
- compiler.hooks.done.tapAsync('plugin-reload:setup-firefox-inspection', async (_stats, done)=>{
8637
- try {
8638
- if (!this.initialized) await this.initialize();
8639
- const urlToInspect = this.resolveUrlToInspect();
8640
- this.lastUrlToInspect = urlToInspect;
8641
- console.log(browsers_lib_messages.hm(urlToInspect));
8642
- const { tabActor, consoleActor } = await this.selectActors(urlToInspect);
8643
- this.currentTabActor = tabActor;
8644
- await this.ensureNavigatedAndLoaded(urlToInspect, tabActor);
8645
- const resolvedConsoleActor = await this.resolveConsoleActor(tabActor, urlToInspect);
8646
- this.currentConsoleActor = resolvedConsoleActor || consoleActor;
8647
- if (this.currentConsoleActor) {
8648
- await this.waitForContentScriptInjection(this.currentConsoleActor);
8649
- await this.printHTML(this.currentConsoleActor);
8650
- }
8651
- const webSocketServer = compiler.options.webSocketServer;
8652
- if (this.devOptions.watchSource && webSocketServer && !this.isWatching) {
8653
- this.isWatching = true;
8654
- this.setupWebSocketHandler(webSocketServer);
8655
- }
8656
- } catch (error) {
8657
- console.error(browsers_lib_messages.y4(error.message));
8658
- }
8659
- done();
8660
- });
8661
- }
8662
- constructor(devOptions){
8663
- setup_firefox_inspection_define_property(this, "devOptions", void 0);
8664
- setup_firefox_inspection_define_property(this, "client", null);
8665
- setup_firefox_inspection_define_property(this, "currentConsoleActor", null);
8666
- setup_firefox_inspection_define_property(this, "currentTabActor", null);
8667
- setup_firefox_inspection_define_property(this, "isWatching", false);
8668
- setup_firefox_inspection_define_property(this, "debounceTimer", null);
8669
- setup_firefox_inspection_define_property(this, "initialized", false);
8670
- setup_firefox_inspection_define_property(this, "lastUrlToInspect", null);
8671
- this.devOptions = devOptions;
8639
+ constructor(options){
8640
+ feature_browser_specific_fields_define_property(this, "browser", void 0);
8641
+ feature_browser_specific_fields_define_property(this, "manifestPath", void 0);
8642
+ this.manifestPath = options.manifestPath;
8643
+ this.browser = options.browser || 'chrome';
8672
8644
  }
8673
8645
  }
8674
- function plugin_reload_define_property(obj, key, value) {
8646
+ function plugin_compatibility_define_property(obj, key, value) {
8675
8647
  if (key in obj) Object.defineProperty(obj, key, {
8676
8648
  value: value,
8677
8649
  enumerable: true,
@@ -8681,169 +8653,48 @@ var __webpack_exports__ = {};
8681
8653
  else obj[key] = value;
8682
8654
  return obj;
8683
8655
  }
8684
- class ReloadPlugin {
8685
- apply(compiler) {
8686
- if (this.instanceId) compiler.options.currentInstance = {
8687
- instanceId: this.instanceId
8688
- };
8689
- if ('development' !== compiler.options.mode) return;
8690
- new CreateWebSocketServer({
8691
- manifestPath: this.manifestPath,
8692
- browser: this.browser,
8693
- port: this.port,
8694
- stats: this.stats,
8695
- instanceId: this.instanceId
8696
- }).apply(compiler);
8697
- new setup_reload_strategy({
8656
+ class CompatibilityPlugin {
8657
+ async apply(compiler) {
8658
+ if (this.polyfill) {
8659
+ if ('firefox' !== this.browser) new PolyfillPlugin({
8660
+ manifestPath: this.manifestPath,
8661
+ browser: this.browser || 'chrome'
8662
+ }).apply(compiler);
8663
+ }
8664
+ new BrowserSpecificFieldsPlugin({
8698
8665
  manifestPath: this.manifestPath,
8699
- browser: this.browser,
8700
- autoReload: this.autoReload,
8701
- stats: this.stats,
8702
- port: this.port,
8703
- instanceId: this.instanceId
8704
- }).apply(compiler);
8705
- if ('firefox' === this.browser || 'gecko-based' === this.browser) new SetupFirefoxInspectionStep({
8706
- browser: this.browser,
8707
- mode: compiler.options.mode || 'development',
8708
- port: this.port,
8709
- instanceId: this.instanceId
8666
+ browser: this.browser || 'chrome'
8710
8667
  }).apply(compiler);
8711
8668
  }
8712
8669
  constructor(options){
8713
- plugin_reload_define_property(this, "manifestPath", void 0);
8714
- plugin_reload_define_property(this, "browser", void 0);
8715
- plugin_reload_define_property(this, "port", void 0);
8716
- plugin_reload_define_property(this, "stats", void 0);
8717
- plugin_reload_define_property(this, "autoReload", void 0);
8718
- plugin_reload_define_property(this, "instanceId", void 0);
8670
+ plugin_compatibility_define_property(this, "manifestPath", void 0);
8671
+ plugin_compatibility_define_property(this, "browser", void 0);
8672
+ plugin_compatibility_define_property(this, "polyfill", void 0);
8719
8673
  this.manifestPath = options.manifestPath;
8720
8674
  this.browser = options.browser || 'chrome';
8721
- this.port = parseInt(options.port, 10);
8722
- this.stats = options.stats;
8723
- this.autoReload = options.autoReload;
8724
- this.instanceId = options.instanceId;
8675
+ this.polyfill = options.polyfill || false;
8725
8676
  }
8726
8677
  }
8727
- plugin_reload_define_property(ReloadPlugin, "name", 'plugin-reload');
8728
- function feature_polyfill_define_property(obj, key, value) {
8729
- if (key in obj) Object.defineProperty(obj, key, {
8730
- value: value,
8731
- enumerable: true,
8732
- configurable: true,
8733
- writable: true
8734
- });
8735
- else obj[key] = value;
8736
- return obj;
8737
- }
8738
- class PolyfillPlugin {
8739
- apply(compiler) {
8740
- try {
8741
- const context = compiler.options.context;
8742
- const polyfillPath = require.resolve('webextension-polyfill/dist/browser-polyfill.js', {
8743
- paths: [
8744
- context
8745
- ]
8746
- });
8747
- new (core_default()).ProvidePlugin({
8748
- browser: polyfillPath
8749
- }).apply(compiler);
8750
- } catch (error) {
8751
- console.warn(webpack_lib_messages.or());
8678
+ plugin_compatibility_define_property(CompatibilityPlugin, "name", 'plugin-compatibility');
8679
+ var external_net_ = __webpack_require__("net");
8680
+ var browsers_lib_messages = __webpack_require__("./webpack/plugin-browsers/browsers-lib/messages.ts");
8681
+ function mergeShadowIntoDocument(mainHTML, shadowContent) {
8682
+ try {
8683
+ if (!mainHTML) return '';
8684
+ const hasRoot = /<div id=(["'])extension-root\1/i.test(mainHTML);
8685
+ if (hasRoot) {
8686
+ const emptyRoot = /<div id=(["'])extension-root\1[^>]*><\/div>/i;
8687
+ const replacedEmpty = mainHTML.replace(emptyRoot, `<div id="extension-root">${shadowContent}</div>`);
8688
+ if (replacedEmpty !== mainHTML) return replacedEmpty;
8689
+ return mainHTML.replace(/<div id=(["'])extension-root\1[^>]*>[\s\S]*?<\/div>/i, `<div id="extension-root">${shadowContent}</div>`);
8752
8690
  }
8753
- }
8754
- constructor(options){
8755
- feature_polyfill_define_property(this, "manifestPath", void 0);
8756
- feature_polyfill_define_property(this, "browser", void 0);
8757
- this.manifestPath = options.manifestPath;
8758
- this.browser = options.browser;
8691
+ if (/<\/body>/i.test(mainHTML)) return mainHTML.replace(/<\/body>/i, `<div id="extension-root">${shadowContent}</div></body>`);
8692
+ return `${mainHTML}\n<div id="extension-root">${shadowContent}</div>`;
8693
+ } catch {
8694
+ return mainHTML;
8759
8695
  }
8760
8696
  }
8761
- function feature_browser_specific_fields_define_property(obj, key, value) {
8762
- if (key in obj) Object.defineProperty(obj, key, {
8763
- value: value,
8764
- enumerable: true,
8765
- configurable: true,
8766
- writable: true
8767
- });
8768
- else obj[key] = value;
8769
- return obj;
8770
- }
8771
- class BrowserSpecificFieldsPlugin {
8772
- patchManifest(manifest) {
8773
- const patchedManifest = filterKeysForThisBrowser(manifest, this.browser);
8774
- return JSON.stringify(patchedManifest, null, 2);
8775
- }
8776
- apply(compiler) {
8777
- compiler.hooks.compilation.tap('compatibility:browser-specific-fields', (compilation)=>{
8778
- compilation.hooks.processAssets.tap({
8779
- name: 'compatibility:browser-specific-fields',
8780
- stage: core_namespaceObject.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
8781
- }, ()=>{
8782
- const manifest = getManifestContent(compilation, this.manifestPath);
8783
- const patchedSource = this.patchManifest(manifest);
8784
- const rawSource = new core_namespaceObject.sources.RawSource(patchedSource);
8785
- compilation.updateAsset('manifest.json', rawSource);
8786
- });
8787
- });
8788
- }
8789
- constructor(options){
8790
- feature_browser_specific_fields_define_property(this, "browser", void 0);
8791
- feature_browser_specific_fields_define_property(this, "manifestPath", void 0);
8792
- this.manifestPath = options.manifestPath;
8793
- this.browser = options.browser || 'chrome';
8794
- }
8795
- }
8796
- function plugin_compatibility_define_property(obj, key, value) {
8797
- if (key in obj) Object.defineProperty(obj, key, {
8798
- value: value,
8799
- enumerable: true,
8800
- configurable: true,
8801
- writable: true
8802
- });
8803
- else obj[key] = value;
8804
- return obj;
8805
- }
8806
- class CompatibilityPlugin {
8807
- async apply(compiler) {
8808
- if (this.polyfill) {
8809
- if ('firefox' !== this.browser) new PolyfillPlugin({
8810
- manifestPath: this.manifestPath,
8811
- browser: this.browser || 'chrome'
8812
- }).apply(compiler);
8813
- }
8814
- new BrowserSpecificFieldsPlugin({
8815
- manifestPath: this.manifestPath,
8816
- browser: this.browser || 'chrome'
8817
- }).apply(compiler);
8818
- }
8819
- constructor(options){
8820
- plugin_compatibility_define_property(this, "manifestPath", void 0);
8821
- plugin_compatibility_define_property(this, "browser", void 0);
8822
- plugin_compatibility_define_property(this, "polyfill", void 0);
8823
- this.manifestPath = options.manifestPath;
8824
- this.browser = options.browser || 'chrome';
8825
- this.polyfill = options.polyfill || false;
8826
- }
8827
- }
8828
- plugin_compatibility_define_property(CompatibilityPlugin, "name", 'plugin-compatibility');
8829
- var external_net_ = __webpack_require__("net");
8830
- function mergeShadowIntoDocument(mainHTML, shadowContent) {
8831
- try {
8832
- if (!mainHTML) return '';
8833
- const hasRoot = /<div id=(["'])extension-root\1/i.test(mainHTML);
8834
- if (hasRoot) {
8835
- const emptyRoot = /<div id=(["'])extension-root\1[^>]*><\/div>/i;
8836
- const replacedEmpty = mainHTML.replace(emptyRoot, `<div id="extension-root">${shadowContent}</div>`);
8837
- if (replacedEmpty !== mainHTML) return replacedEmpty;
8838
- return mainHTML.replace(/<div id=(["'])extension-root\1[^>]*>[\s\S]*?<\/div>/i, `<div id="extension-root">${shadowContent}</div>`);
8839
- }
8840
- if (/<\/body>/i.test(mainHTML)) return mainHTML.replace(/<\/body>/i, `<div id="extension-root">${shadowContent}</div></body>`);
8841
- return `${mainHTML}\n<div id="extension-root">${shadowContent}</div>`;
8842
- } catch {
8843
- return mainHTML;
8844
- }
8845
- }
8846
- function cdp_client_define_property(obj, key, value) {
8697
+ function cdp_client_define_property(obj, key, value) {
8847
8698
  if (key in obj) Object.defineProperty(obj, key, {
8848
8699
  value: value,
8849
8700
  enumerable: true,
@@ -9154,6 +9005,7 @@ var __webpack_exports__ = {};
9154
9005
  socket.connect(port, 'localhost');
9155
9006
  });
9156
9007
  }
9008
+ var shared_utils = __webpack_require__("./webpack/plugin-browsers/browsers-lib/shared-utils.ts");
9157
9009
  function setup_chrome_inspection_define_property(obj, key, value) {
9158
9010
  if (key in obj) Object.defineProperty(obj, key, {
9159
9011
  value: value,
@@ -9165,11 +9017,18 @@ var __webpack_exports__ = {};
9165
9017
  return obj;
9166
9018
  }
9167
9019
  class SetupChromeInspectionStep {
9168
- getCdpPort() {
9169
- return (0, shared_utils.c5)(this.devOptions.port, void 0);
9020
+ async getCdpPort() {
9021
+ const instanceId = this.devOptions.instanceId;
9022
+ if (instanceId) try {
9023
+ const instanceManager = new instance_manager.InstanceManager(process.cwd());
9024
+ const instance = await instanceManager.getInstance(instanceId);
9025
+ if ((null == instance ? void 0 : instance.debugPort) && Number.isFinite(instance.debugPort)) return instance.debugPort;
9026
+ } catch {}
9027
+ return (0, shared_utils.Zb)(this.devOptions.port, instanceId);
9170
9028
  }
9171
- async initialize(port = this.getCdpPort()) {
9029
+ async initialize(port) {
9172
9030
  try {
9031
+ if (!port) port = await this.getCdpPort();
9173
9032
  if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.Ro());
9174
9033
  let retries = 0;
9175
9034
  const maxRetries = 60;
@@ -9194,160 +9053,439 @@ var __webpack_exports__ = {};
9194
9053
  throw error;
9195
9054
  }
9196
9055
  }
9197
- async inspectSource(url) {
9198
- if (!this.cdpClient) throw new Error(browsers_lib_messages.mO());
9056
+ async inspectSource(url) {
9057
+ if (!this.cdpClient) throw new Error(browsers_lib_messages.mO());
9058
+ try {
9059
+ if ('development' === process.env.EXTENSION_ENV) {
9060
+ console.log(browsers_lib_messages.Zk(url));
9061
+ console.log(browsers_lib_messages.Tz());
9062
+ }
9063
+ const targets = await this.cdpClient.getTargets();
9064
+ const existingTarget = targets.find((target)=>target.url === url && 'page' === target.type);
9065
+ if (existingTarget) {
9066
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.F0(existingTarget.targetId));
9067
+ this.currentTargetId = existingTarget.targetId;
9068
+ } else {
9069
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.v5());
9070
+ this.currentTargetId = await this.cdpClient.createTarget(url);
9071
+ if ('development' === process.env.EXTENSION_ENV) {
9072
+ console.log(browsers_lib_messages.N_(this.currentTargetId));
9073
+ console.log(browsers_lib_messages.Ac());
9074
+ }
9075
+ await this.cdpClient.navigateToUrl(this.currentTargetId, url);
9076
+ }
9077
+ if (!this.currentTargetId) throw new Error('Failed to get or create target');
9078
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.tX());
9079
+ this.currentSessionId = await this.cdpClient.attachToTarget(this.currentTargetId);
9080
+ if ('development' === process.env.EXTENSION_ENV) {
9081
+ console.log(browsers_lib_messages.GR(this.currentSessionId));
9082
+ console.log(browsers_lib_messages.xR());
9083
+ }
9084
+ await this.cdpClient.sendCommand('Page.enable', {}, this.currentSessionId);
9085
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages._y());
9086
+ await this.cdpClient.waitForLoadEvent(this.currentSessionId);
9087
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.Ak());
9088
+ await this.cdpClient.waitForContentScriptInjection(this.currentSessionId);
9089
+ const html = await this.cdpClient.getPageHTML(this.currentSessionId);
9090
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.tg());
9091
+ return html;
9092
+ } catch (error) {
9093
+ if ('development' === process.env.EXTENSION_ENV) console.error(browsers_lib_messages.L7(error.message));
9094
+ throw error;
9095
+ }
9096
+ }
9097
+ async startWatching(websocketServer) {
9098
+ if ('development' !== process.env.EXTENSION_ENV) return;
9099
+ if (this.isWatching) return void console.log(browsers_lib_messages.Li());
9100
+ this.isWatching = true;
9101
+ console.log(browsers_lib_messages.G9());
9102
+ this.setupWebSocketHandler(websocketServer);
9103
+ console.log(browsers_lib_messages.A4());
9104
+ }
9105
+ setupWebSocketHandler(websocketServer) {
9106
+ if ('development' !== process.env.EXTENSION_ENV) return;
9107
+ if (!websocketServer || !websocketServer.clients) return void console.warn(browsers_lib_messages.c9());
9108
+ websocketServer.clients.forEach((ws)=>{
9109
+ this.setupConnectionHandler(ws);
9110
+ });
9111
+ websocketServer.on('connection', (ws)=>{
9112
+ this.setupConnectionHandler(ws);
9113
+ });
9114
+ }
9115
+ setupConnectionHandler(ws) {
9116
+ if ('development' !== process.env.EXTENSION_ENV) return;
9117
+ ws.on('message', async (data)=>{
9118
+ try {
9119
+ const message = JSON.parse(data);
9120
+ if ('changedFile' === message.type && this.isWatching) await this.handleFileChange();
9121
+ } catch (error) {}
9122
+ });
9123
+ }
9124
+ stopWatching() {
9125
+ if ('development' !== process.env.EXTENSION_ENV) return;
9126
+ this.isWatching = false;
9127
+ console.log(browsers_lib_messages.aW());
9128
+ }
9129
+ async handleFileChange() {
9130
+ if ('development' !== process.env.EXTENSION_ENV) return;
9131
+ if (!this.cdpClient || !this.currentSessionId) return void console.warn(browsers_lib_messages.ln());
9132
+ if (this.debounceTimer) clearTimeout(this.debounceTimer);
9133
+ this.debounceTimer = setTimeout(async ()=>{
9134
+ try {
9135
+ console.log(browsers_lib_messages.ET());
9136
+ console.log(browsers_lib_messages.Tq());
9137
+ await this.cdpClient.waitForContentScriptInjection(this.currentSessionId);
9138
+ console.log(browsers_lib_messages.ov());
9139
+ const html = await this.cdpClient.getPageHTML(this.currentSessionId);
9140
+ this.printUpdatedHTML(html);
9141
+ } catch (error) {
9142
+ console.error(browsers_lib_messages.QB(error.message));
9143
+ if (error.message.includes('session') || error.message.includes('target')) {
9144
+ console.log(browsers_lib_messages.Lf());
9145
+ await this.reconnectToTarget();
9146
+ }
9147
+ }
9148
+ }, 300);
9149
+ }
9150
+ async reconnectToTarget() {
9151
+ if ('development' !== process.env.EXTENSION_ENV) return;
9152
+ try {
9153
+ if (!this.cdpClient || !this.currentTargetId) return void console.warn(browsers_lib_messages.DQ());
9154
+ console.log(browsers_lib_messages.S6());
9155
+ this.currentSessionId = await this.cdpClient.attachToTarget(this.currentTargetId);
9156
+ console.log(browsers_lib_messages.BK(this.currentSessionId));
9157
+ } catch (error) {
9158
+ console.error(browsers_lib_messages.w4(error.message));
9159
+ }
9160
+ }
9161
+ printHTML(html) {
9162
+ console.log(browsers_lib_messages.dI());
9163
+ console.log(html);
9164
+ console.log(browsers_lib_messages.qX());
9165
+ }
9166
+ printUpdatedHTML(html) {
9167
+ if ('development' !== process.env.EXTENSION_ENV) return;
9168
+ console.log(browsers_lib_messages.dI());
9169
+ console.log(browsers_lib_messages.Hd("UPDATED - after content script injection"));
9170
+ console.log(browsers_lib_messages.dI());
9171
+ console.log(html);
9172
+ console.log(browsers_lib_messages.qX());
9173
+ }
9174
+ async cleanup() {
9175
+ try {
9176
+ if ('development' === process.env.EXTENSION_ENV) this.stopWatching();
9177
+ if (this.cdpClient && this.currentTargetId) await this.cdpClient.closeTarget(this.currentTargetId);
9178
+ if (this.cdpClient) this.cdpClient.disconnect();
9179
+ if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.S5());
9180
+ } catch (error) {
9181
+ if ('development' === process.env.EXTENSION_ENV) console.error(browsers_lib_messages.oP(error.message));
9182
+ }
9183
+ }
9184
+ apply(compiler) {
9185
+ if (!this.devOptions.source && !this.devOptions.watchSource) return;
9186
+ compiler.hooks.done.tapAsync('plugin-reload:setup-chrome-inspection', async (stats, done)=>{
9187
+ try {
9188
+ if (!this.isInitialized) await this.initialize();
9189
+ let urlToInspect;
9190
+ if (this.devOptions.source && 'string' == typeof this.devOptions.source && 'true' !== this.devOptions.source) urlToInspect = this.devOptions.source;
9191
+ else if (this.devOptions.startingUrl) urlToInspect = this.devOptions.startingUrl;
9192
+ else throw new Error(browsers_lib_messages.Ym());
9193
+ const html = await this.inspectSource(urlToInspect);
9194
+ this.printHTML(html);
9195
+ const webSocketServer = compiler.options.webSocketServer;
9196
+ if (this.devOptions.watchSource && webSocketServer && 'development' === process.env.EXTENSION_ENV) this.startWatching(webSocketServer);
9197
+ done();
9198
+ } catch (error) {
9199
+ if ('development' === process.env.EXTENSION_ENV) console.error(browsers_lib_messages.y4(error.message));
9200
+ done();
9201
+ }
9202
+ });
9203
+ }
9204
+ constructor(devOptions){
9205
+ setup_chrome_inspection_define_property(this, "devOptions", void 0);
9206
+ setup_chrome_inspection_define_property(this, "cdpClient", null);
9207
+ setup_chrome_inspection_define_property(this, "currentTargetId", null);
9208
+ setup_chrome_inspection_define_property(this, "currentSessionId", null);
9209
+ setup_chrome_inspection_define_property(this, "isInitialized", false);
9210
+ this.devOptions = devOptions;
9211
+ }
9212
+ }
9213
+ var messaging_client = __webpack_require__("./webpack/plugin-browsers/run-firefox/remote-firefox/messaging-client.ts");
9214
+ function setup_firefox_inspection_define_property(obj, key, value) {
9215
+ if (key in obj) Object.defineProperty(obj, key, {
9216
+ value: value,
9217
+ enumerable: true,
9218
+ configurable: true,
9219
+ writable: true
9220
+ });
9221
+ else obj[key] = value;
9222
+ return obj;
9223
+ }
9224
+ const MAX_CONNECT_RETRIES = 60;
9225
+ const CONNECT_RETRY_INTERVAL_MS = 500;
9226
+ const PAGE_READY_TIMEOUT_MS = 8000;
9227
+ const TARGET_SCAN_INTERVAL_MS = 250;
9228
+ const CHANGE_DEBOUNCE_MS = 300;
9229
+ function wait(ms) {
9230
+ return new Promise((resolve)=>setTimeout(resolve, ms));
9231
+ }
9232
+ class SetupFirefoxInspectionStep {
9233
+ async getRdpPort() {
9234
+ const instanceId = this.devOptions.instanceId;
9235
+ if (instanceId) try {
9236
+ const instanceManager = new instance_manager.InstanceManager(process.cwd());
9237
+ const instance = await instanceManager.getInstance(instanceId);
9238
+ if ((null == instance ? void 0 : instance.debugPort) && Number.isFinite(instance.debugPort)) return instance.debugPort;
9239
+ } catch {}
9240
+ return (0, shared_utils.Zb)(this.devOptions.port, instanceId);
9241
+ }
9242
+ async initialize() {
9243
+ if (this.initialized) return;
9244
+ const client = new messaging_client.v();
9245
+ const port = await this.getRdpPort();
9246
+ try {
9247
+ console.log(browsers_lib_messages.l());
9248
+ } catch {}
9249
+ let retries = 0;
9250
+ while(retries < MAX_CONNECT_RETRIES)try {
9251
+ await client.connect(port);
9252
+ this.client = client;
9253
+ this.initialized = true;
9254
+ try {
9255
+ console.log(browsers_lib_messages.Xy());
9256
+ console.log(browsers_lib_messages.Qe());
9257
+ } catch {}
9258
+ return;
9259
+ } catch (err) {
9260
+ retries++;
9261
+ if (retries % 10 === 0) try {
9262
+ console.log(browsers_lib_messages.X_(retries, MAX_CONNECT_RETRIES));
9263
+ } catch {}
9264
+ await wait(CONNECT_RETRY_INTERVAL_MS);
9265
+ }
9266
+ throw new Error(browsers_lib_messages.V9(port));
9267
+ }
9268
+ resolveUrlToInspect() {
9269
+ if (this.devOptions.source && 'string' == typeof this.devOptions.source && 'true' !== this.devOptions.source) return this.devOptions.source;
9270
+ if (this.devOptions.startingUrl) return this.devOptions.startingUrl;
9271
+ throw new Error(browsers_lib_messages.Ym());
9272
+ }
9273
+ async selectActors(urlToInspect) {
9274
+ if (!this.client) throw new Error(browsers_lib_messages.pl());
9275
+ const deadline = Date.now() + 10000;
9276
+ let triedAddTab = false;
9277
+ while(Date.now() < deadline){
9278
+ const allTargets = await this.client.getTargets() || [];
9279
+ for (const target of allTargets)if (target && 'string' == typeof target.url && target.url === urlToInspect && target.actor) return {
9280
+ tabActor: target.actor,
9281
+ consoleActor: target.consoleActor || target.actor
9282
+ };
9283
+ if (!triedAddTab && urlToInspect) {
9284
+ triedAddTab = true;
9285
+ try {
9286
+ await this.client.addTab(urlToInspect);
9287
+ await wait(300);
9288
+ continue;
9289
+ } catch {}
9290
+ }
9291
+ for (const target of allTargets)if (target && (target.actor || target.outerWindowID)) return {
9292
+ tabActor: target.actor,
9293
+ consoleActor: target.consoleActor || target.actor
9294
+ };
9295
+ await wait(TARGET_SCAN_INTERVAL_MS);
9296
+ }
9297
+ throw new Error(browsers_lib_messages.qP());
9298
+ }
9299
+ async ensureNavigatedAndLoaded(urlToInspect, tabActor) {
9300
+ if (!this.client) throw new Error(browsers_lib_messages.pl());
9301
+ if (!tabActor) throw new Error(browsers_lib_messages.Do());
9302
+ let consoleActor = tabActor;
9303
+ let frameActor = tabActor;
9304
+ try {
9305
+ const detail = await this.client.getTargetFromDescriptor(tabActor);
9306
+ if (detail.consoleActor) consoleActor = detail.consoleActor;
9307
+ if (detail.targetActor) frameActor = detail.targetActor;
9308
+ } catch {}
9309
+ try {
9310
+ await this.client.attach(frameActor);
9311
+ } catch {}
9312
+ try {
9313
+ await this.client.navigateViaScript(consoleActor, urlToInspect);
9314
+ await this.client.waitForPageReady(consoleActor, urlToInspect, PAGE_READY_TIMEOUT_MS);
9315
+ return;
9316
+ } catch {}
9317
+ try {
9318
+ const detail = await this.client.getTargetFromDescriptor(tabActor);
9319
+ const targetActor = detail.targetActor || tabActor;
9320
+ try {
9321
+ await this.client.attach(targetActor);
9322
+ } catch {}
9323
+ await this.client.navigate(targetActor, urlToInspect);
9324
+ await this.client.waitForLoadEvent(targetActor);
9325
+ } catch {}
9326
+ }
9327
+ async ensureUrlAndReady(consoleActor, urlToInspect) {
9328
+ if (!this.client) return;
9199
9329
  try {
9200
- if ('development' === process.env.EXTENSION_ENV) {
9201
- console.log(browsers_lib_messages.Zk(url));
9202
- console.log(browsers_lib_messages.Tz());
9203
- }
9204
- const targets = await this.cdpClient.getTargets();
9205
- const existingTarget = targets.find((target)=>target.url === url && 'page' === target.type);
9206
- if (existingTarget) {
9207
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.F0(existingTarget.targetId));
9208
- this.currentTargetId = existingTarget.targetId;
9209
- } else {
9210
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.v5());
9211
- this.currentTargetId = await this.cdpClient.createTarget(url);
9212
- if ('development' === process.env.EXTENSION_ENV) {
9213
- console.log(browsers_lib_messages.N_(this.currentTargetId));
9214
- console.log(browsers_lib_messages.Ac());
9330
+ const href = await this.client.evaluate(consoleActor, 'String(location.href)');
9331
+ if ('string' != typeof href || !href.startsWith(urlToInspect)) await this.client.navigateViaScript(consoleActor, urlToInspect);
9332
+ } catch {}
9333
+ await this.client.waitForPageReady(consoleActor, urlToInspect, PAGE_READY_TIMEOUT_MS);
9334
+ }
9335
+ async resolveConsoleActor(tabActor, urlToInspect) {
9336
+ if (!this.client) throw new Error(browsers_lib_messages.pl());
9337
+ const start = Date.now();
9338
+ while(Date.now() - start < PAGE_READY_TIMEOUT_MS){
9339
+ try {
9340
+ const targets = await this.client.getTargets();
9341
+ const byActor = targets.find((t)=>t && t.actor === tabActor);
9342
+ const byUrl = targets.find((t)=>t && t.url === urlToInspect);
9343
+ const match = byActor || byUrl;
9344
+ const ca = (null == match ? void 0 : match.consoleActor) || (null == match ? void 0 : match.webConsoleActor);
9345
+ if ('string' == typeof ca && ca.length > 0) return ca;
9346
+ try {
9347
+ const detail = await this.client.getTargetFromDescriptor(tabActor);
9348
+ const guessed = detail.consoleActor;
9349
+ if ('string' == typeof guessed && guessed.length > 0) return guessed;
9350
+ } catch {}
9351
+ } catch {}
9352
+ await wait(200);
9353
+ }
9354
+ return tabActor;
9355
+ }
9356
+ async printHTML(consoleActor) {
9357
+ if (!this.client) throw new Error('RDP client not initialized');
9358
+ let lastError = null;
9359
+ for(let attempt = 0; attempt < 3; attempt++){
9360
+ let actorToUse = consoleActor;
9361
+ try {
9362
+ if (this.currentTabActor && this.lastUrlToInspect) {
9363
+ const fresh = await this.resolveConsoleActor(this.currentTabActor, this.lastUrlToInspect);
9364
+ if (fresh) actorToUse = fresh;
9215
9365
  }
9216
- await this.cdpClient.navigateToUrl(this.currentTargetId, url);
9217
- }
9218
- if (!this.currentTargetId) throw new Error('Failed to get or create target');
9219
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.tX());
9220
- this.currentSessionId = await this.cdpClient.attachToTarget(this.currentTargetId);
9221
- if ('development' === process.env.EXTENSION_ENV) {
9222
- console.log(browsers_lib_messages.GR(this.currentSessionId));
9223
- console.log(browsers_lib_messages.xR());
9366
+ } catch {}
9367
+ try {
9368
+ const descriptor = this.currentTabActor || actorToUse;
9369
+ if (this.lastUrlToInspect) await this.ensureUrlAndReady(actorToUse, this.lastUrlToInspect);
9370
+ try {
9371
+ const currentUrl = await this.client.evaluate(actorToUse, 'String(location.href)');
9372
+ const currentTitle = await this.client.evaluate(actorToUse, 'String(document.title)');
9373
+ console.log(browsers_lib_messages.dI());
9374
+ console.log(browsers_lib_messages.Hd(`URL: ${currentUrl} | TITLE: ${currentTitle}`));
9375
+ } catch {}
9376
+ const html = await this.client.getPageHTML(descriptor, actorToUse) || '';
9377
+ console.log(html);
9378
+ console.log(browsers_lib_messages.qX());
9379
+ return;
9380
+ } catch (err) {
9381
+ lastError = err;
9224
9382
  }
9225
- await this.cdpClient.sendCommand('Page.enable', {}, this.currentSessionId);
9226
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages._y());
9227
- await this.cdpClient.waitForLoadEvent(this.currentSessionId);
9228
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.Ak());
9229
- await this.cdpClient.waitForContentScriptInjection(this.currentSessionId);
9230
- const html = await this.cdpClient.getPageHTML(this.currentSessionId);
9231
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.tg());
9232
- return html;
9233
- } catch (error) {
9234
- if ('development' === process.env.EXTENSION_ENV) console.error(browsers_lib_messages.L7(error.message));
9235
- throw error;
9383
+ await wait(200);
9236
9384
  }
9385
+ throw lastError || new Error(browsers_lib_messages.Cn());
9237
9386
  }
9238
- async startWatching(websocketServer) {
9239
- if ('development' !== process.env.EXTENSION_ENV) return;
9240
- if (this.isWatching) return void console.log(browsers_lib_messages.Li());
9241
- this.isWatching = true;
9242
- console.log(browsers_lib_messages.G9());
9243
- this.setupWebSocketHandler(websocketServer);
9244
- console.log(browsers_lib_messages.A4());
9387
+ async waitForContentScriptInjection(consoleActor) {
9388
+ if (!this.client) return;
9389
+ const deadline = Date.now() + PAGE_READY_TIMEOUT_MS;
9390
+ while(Date.now() < deadline){
9391
+ try {
9392
+ const injected = await this.client.evaluate(consoleActor, `(() => {
9393
+ const root = document.getElementById('extension-root');
9394
+ if (!root || !root.shadowRoot) return false;
9395
+ const html = root.shadowRoot.innerHTML || '';
9396
+ return html.length > 0;
9397
+ })()`);
9398
+ if (injected) return;
9399
+ } catch {}
9400
+ await wait(200);
9401
+ }
9245
9402
  }
9246
9403
  setupWebSocketHandler(websocketServer) {
9247
- if ('development' !== process.env.EXTENSION_ENV) return;
9248
- if (!websocketServer || !websocketServer.clients) return void console.warn(browsers_lib_messages.c9());
9404
+ if (!websocketServer || !websocketServer.clients) return;
9249
9405
  websocketServer.clients.forEach((ws)=>{
9250
- this.setupConnectionHandler(ws);
9406
+ this.attachConnection(ws);
9251
9407
  });
9252
9408
  websocketServer.on('connection', (ws)=>{
9253
- this.setupConnectionHandler(ws);
9409
+ this.attachConnection(ws);
9254
9410
  });
9255
9411
  }
9256
- setupConnectionHandler(ws) {
9257
- if ('development' !== process.env.EXTENSION_ENV) return;
9412
+ attachConnection(ws) {
9258
9413
  ws.on('message', async (data)=>{
9259
9414
  try {
9260
9415
  const message = JSON.parse(data);
9261
9416
  if ('changedFile' === message.type && this.isWatching) await this.handleFileChange();
9262
- } catch (error) {}
9417
+ } catch {}
9263
9418
  });
9264
9419
  }
9265
- stopWatching() {
9266
- if ('development' !== process.env.EXTENSION_ENV) return;
9267
- this.isWatching = false;
9268
- console.log(browsers_lib_messages.aW());
9269
- }
9270
9420
  async handleFileChange() {
9271
- if ('development' !== process.env.EXTENSION_ENV) return;
9272
- if (!this.cdpClient || !this.currentSessionId) return void console.warn(browsers_lib_messages.ln());
9421
+ if (!this.client || !this.currentConsoleActor) return;
9273
9422
  if (this.debounceTimer) clearTimeout(this.debounceTimer);
9274
9423
  this.debounceTimer = setTimeout(async ()=>{
9275
9424
  try {
9276
- console.log(browsers_lib_messages.ET());
9277
- console.log(browsers_lib_messages.Tq());
9278
- await this.cdpClient.waitForContentScriptInjection(this.currentSessionId);
9279
- console.log(browsers_lib_messages.ov());
9280
- const html = await this.cdpClient.getPageHTML(this.currentSessionId);
9281
- this.printUpdatedHTML(html);
9282
- } catch (error) {
9283
- console.error(browsers_lib_messages.QB(error.message));
9284
- if (error.message.includes('session') || error.message.includes('target')) {
9285
- console.log(browsers_lib_messages.Lf());
9286
- await this.reconnectToTarget();
9425
+ if (this.currentTabActor && this.lastUrlToInspect) {
9426
+ const freshConsole = await this.resolveConsoleActor(this.currentTabActor, this.lastUrlToInspect);
9427
+ if (freshConsole) this.currentConsoleActor = freshConsole;
9428
+ }
9429
+ if (this.lastUrlToInspect) await this.ensureUrlAndReady(this.currentConsoleActor, this.lastUrlToInspect);
9430
+ await this.waitForContentScriptInjection(this.currentConsoleActor);
9431
+ let lastError = null;
9432
+ for(let attempt = 0; attempt < 3; attempt++){
9433
+ try {
9434
+ const descriptor = this.currentTabActor || this.currentConsoleActor;
9435
+ const html = await this.client.getPageHTML(descriptor, this.currentConsoleActor);
9436
+ console.log(browsers_lib_messages.dI());
9437
+ console.log(browsers_lib_messages.Hd("UPDATED - after content script injection"));
9438
+ console.log(html);
9439
+ console.log(browsers_lib_messages.qX());
9440
+ return;
9441
+ } catch (err) {
9442
+ lastError = err;
9443
+ }
9444
+ await wait(200);
9287
9445
  }
9446
+ throw lastError || new Error('Failed to update HTML after retries');
9447
+ } catch (err) {
9448
+ console.error(browsers_lib_messages.QB(err.message));
9288
9449
  }
9289
- }, 300);
9290
- }
9291
- async reconnectToTarget() {
9292
- if ('development' !== process.env.EXTENSION_ENV) return;
9293
- try {
9294
- if (!this.cdpClient || !this.currentTargetId) return void console.warn(browsers_lib_messages.DQ());
9295
- console.log(browsers_lib_messages.S6());
9296
- this.currentSessionId = await this.cdpClient.attachToTarget(this.currentTargetId);
9297
- console.log(browsers_lib_messages.BK(this.currentSessionId));
9298
- } catch (error) {
9299
- console.error(browsers_lib_messages.w4(error.message));
9300
- }
9301
- }
9302
- printHTML(html) {
9303
- console.log(browsers_lib_messages.dI());
9304
- console.log(html);
9305
- console.log(browsers_lib_messages.qX());
9306
- }
9307
- printUpdatedHTML(html) {
9308
- if ('development' !== process.env.EXTENSION_ENV) return;
9309
- console.log(browsers_lib_messages.dI());
9310
- console.log(browsers_lib_messages.Hd("UPDATED - after content script injection"));
9311
- console.log(browsers_lib_messages.dI());
9312
- console.log(html);
9313
- console.log(browsers_lib_messages.qX());
9314
- }
9315
- async cleanup() {
9316
- try {
9317
- if ('development' === process.env.EXTENSION_ENV) this.stopWatching();
9318
- if (this.cdpClient && this.currentTargetId) await this.cdpClient.closeTarget(this.currentTargetId);
9319
- if (this.cdpClient) this.cdpClient.disconnect();
9320
- if ('development' === process.env.EXTENSION_ENV) console.log(browsers_lib_messages.S5());
9321
- } catch (error) {
9322
- if ('development' === process.env.EXTENSION_ENV) console.error(browsers_lib_messages.oP(error.message));
9323
- }
9450
+ }, CHANGE_DEBOUNCE_MS);
9324
9451
  }
9325
9452
  apply(compiler) {
9326
9453
  if (!this.devOptions.source && !this.devOptions.watchSource) return;
9327
- compiler.hooks.done.tapAsync('plugin-reload:setup-chrome-inspection', async (stats, done)=>{
9454
+ compiler.hooks.done.tapAsync('plugin-reload:setup-firefox-inspection', async (_stats, done)=>{
9328
9455
  try {
9329
- if (!this.isInitialized) await this.initialize();
9330
- let urlToInspect;
9331
- if (this.devOptions.source && 'string' == typeof this.devOptions.source && 'true' !== this.devOptions.source) urlToInspect = this.devOptions.source;
9332
- else if (this.devOptions.startingUrl) urlToInspect = this.devOptions.startingUrl;
9333
- else throw new Error(browsers_lib_messages.Ym());
9334
- const html = await this.inspectSource(urlToInspect);
9335
- this.printHTML(html);
9456
+ if (!this.initialized) await this.initialize();
9457
+ const urlToInspect = this.resolveUrlToInspect();
9458
+ this.lastUrlToInspect = urlToInspect;
9459
+ console.log(browsers_lib_messages.hm(urlToInspect));
9460
+ const { tabActor, consoleActor } = await this.selectActors(urlToInspect);
9461
+ this.currentTabActor = tabActor;
9462
+ await this.ensureNavigatedAndLoaded(urlToInspect, tabActor);
9463
+ const resolvedConsoleActor = await this.resolveConsoleActor(tabActor, urlToInspect);
9464
+ this.currentConsoleActor = resolvedConsoleActor || consoleActor;
9465
+ if (this.currentConsoleActor) {
9466
+ await this.waitForContentScriptInjection(this.currentConsoleActor);
9467
+ await this.printHTML(this.currentConsoleActor);
9468
+ }
9336
9469
  const webSocketServer = compiler.options.webSocketServer;
9337
- if (this.devOptions.watchSource && webSocketServer && 'development' === process.env.EXTENSION_ENV) this.startWatching(webSocketServer);
9338
- done();
9470
+ if (this.devOptions.watchSource && webSocketServer && !this.isWatching) {
9471
+ this.isWatching = true;
9472
+ this.setupWebSocketHandler(webSocketServer);
9473
+ }
9339
9474
  } catch (error) {
9340
- if ('development' === process.env.EXTENSION_ENV) console.error(browsers_lib_messages.y4(error.message));
9341
- done();
9475
+ console.error(browsers_lib_messages.y4(error.message));
9342
9476
  }
9477
+ done();
9343
9478
  });
9344
9479
  }
9345
9480
  constructor(devOptions){
9346
- setup_chrome_inspection_define_property(this, "devOptions", void 0);
9347
- setup_chrome_inspection_define_property(this, "cdpClient", null);
9348
- setup_chrome_inspection_define_property(this, "currentTargetId", null);
9349
- setup_chrome_inspection_define_property(this, "currentSessionId", null);
9350
- setup_chrome_inspection_define_property(this, "isInitialized", false);
9481
+ setup_firefox_inspection_define_property(this, "devOptions", void 0);
9482
+ setup_firefox_inspection_define_property(this, "client", null);
9483
+ setup_firefox_inspection_define_property(this, "currentConsoleActor", null);
9484
+ setup_firefox_inspection_define_property(this, "currentTabActor", null);
9485
+ setup_firefox_inspection_define_property(this, "isWatching", false);
9486
+ setup_firefox_inspection_define_property(this, "debounceTimer", null);
9487
+ setup_firefox_inspection_define_property(this, "initialized", false);
9488
+ setup_firefox_inspection_define_property(this, "lastUrlToInspect", null);
9351
9489
  this.devOptions = devOptions;
9352
9490
  }
9353
9491
  }