extension 3.17.0 → 3.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/322.cjs +89 -11
  2. package/dist/browsers.cjs +263 -206
  3. package/dist/cli.cjs +1312 -413
  4. package/dist/extension/browsers/browsers-lib/messages.d.ts +17 -0
  5. package/dist/extension/browsers/browsers-lib/output-binaries-resolver.d.ts +1 -1
  6. package/dist/extension/browsers/browsers-lib/shared-utils.d.ts +1 -0
  7. package/dist/extension/browsers/browsers-lib/wsl-support.d.ts +3 -0
  8. package/dist/extension/browsers/browsers-types.d.ts +1 -1
  9. package/dist/extension/browsers/run-chromium/chromium-launch/process-handlers.d.ts +8 -1
  10. package/dist/extension/browsers/run-chromium/chromium-launch/wsl-support.d.ts +2 -9
  11. package/dist/extension/browsers/run-chromium/chromium-source-inspection/cdp-client.d.ts +6 -0
  12. package/dist/extension/browsers/run-chromium/chromium-source-inspection/cdp-extension-controller/logging.d.ts +0 -5
  13. package/dist/extension/browsers/run-chromium/chromium-source-inspection/index.d.ts +1 -0
  14. package/dist/extension/browsers/run-firefox/firefox-launch/binary-detector.d.ts +0 -4
  15. package/dist/extension/browsers/run-firefox/firefox-launch/process-handlers.d.ts +5 -1
  16. package/dist/extension/browsers/run-firefox/firefox-launch/wsl-support.d.ts +2 -4
  17. package/dist/extension/browsers/run-firefox/firefox-source-inspection/remote-firefox/evaluate.d.ts +1 -0
  18. package/dist/extension/browsers/run-safari/safari-launch/dry-run.d.ts +1 -0
  19. package/dist/extension/browsers/run-safari/safari-launch/index.d.ts +5 -0
  20. package/dist/extension/browsers/run-safari/safari-launch/safari-config.d.ts +16 -0
  21. package/dist/extension/browsers/run-safari/safari-launch/toolchain.d.ts +10 -0
  22. package/dist/extension/browsers/run-safari/safari-types.d.ts +18 -0
  23. package/dist/extension/commands/act.d.ts +6 -0
  24. package/dist/extension/commands/dev-wait.d.ts +2 -0
  25. package/dist/extension/commands/logs.d.ts +2 -0
  26. package/dist/extension/commands/publish.d.ts +15 -0
  27. package/dist/extension/helpers/extension-develop-runtime.d.ts +5 -0
  28. package/dist/extension/helpers/messages.d.ts +18 -1
  29. package/dist/extension/helpers/telemetry.d.ts +1 -0
  30. package/dist/extension/helpers/vendors.d.ts +2 -1
  31. package/package.json +5 -5
package/dist/322.cjs CHANGED
@@ -7,11 +7,11 @@ exports.modules = {
7
7
  __webpack_require__.d(__webpack_exports__, {
8
8
  setupCdpAfterLaunch: ()=>setupCdpAfterLaunch
9
9
  });
10
+ var external_fs_ = __webpack_require__("fs");
11
+ var external_path_ = __webpack_require__("path");
10
12
  var messages = __webpack_require__("./browsers/browsers-lib/messages.ts");
11
13
  var shared_utils = __webpack_require__("./browsers/browsers-lib/shared-utils.ts");
12
14
  var banner = __webpack_require__("./browsers/browsers-lib/banner.ts");
13
- var external_path_ = __webpack_require__("path");
14
- var external_fs_ = __webpack_require__("fs");
15
15
  var content_script_targets = __webpack_require__("./browsers/browsers-lib/content-script-targets.ts");
16
16
  var content_script_contracts = __webpack_require__("./browsers/browsers-lib/content-script-contracts.ts");
17
17
  var external_ws_ = __webpack_require__("ws");
@@ -60,7 +60,6 @@ exports.modules = {
60
60
  }
61
61
  }
62
62
  const CONTENT_ROOT_SELECTOR = '#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])';
63
- const NON_DEVTOOLS_CONTENT_ROOT_SELECTOR = '#extension-root,[data-extension-root]:not([data-extension-root="extension-js-devtools"])';
64
63
  const EXTENSION_ROOT_META_EXPRESSION = `(() => {
65
64
  const readGeneration = (node) => {
66
65
  try {
@@ -149,7 +148,7 @@ exports.modules = {
149
148
  const generations = roots
150
149
  .concat(markers)
151
150
  .map((entry) => entry.generation)
152
- .concat(typeof page.generation === 'number' ? [page.generation] : [])
151
+ .concat(page && typeof page.generation === 'number' ? [page.generation] : [])
153
152
  .concat(
154
153
  registries
155
154
  .map((entry) => entry.generation)
@@ -321,7 +320,7 @@ exports.modules = {
321
320
  if ('off' === includeShadow) return mainHTML;
322
321
  const hasVisibleContentRoot = await evaluateWithContentContext(cdp, sessionId, `(() => {
323
322
  try {
324
- return !!document.querySelector(${JSON.stringify(NON_DEVTOOLS_CONTENT_ROOT_SELECTOR)})
323
+ return !!document.querySelector(${JSON.stringify(CONTENT_ROOT_SELECTOR)})
325
324
  } catch {
326
325
  return false
327
326
  }
@@ -330,7 +329,7 @@ exports.modules = {
330
329
  try {
331
330
  const mergedHtmlRaw = await evaluateWithContentContext(cdp, sessionId, `(() => { try {
332
331
  var cloned = document.documentElement.cloneNode(true);
333
- var selector = ${JSON.stringify(NON_DEVTOOLS_CONTENT_ROOT_SELECTOR)};
332
+ var selector = ${JSON.stringify(CONTENT_ROOT_SELECTOR)};
334
333
  var s = new XMLSerializer();
335
334
  try {
336
335
  var liveHosts = Array.from(document.querySelectorAll(selector));
@@ -488,6 +487,7 @@ exports.modules = {
488
487
  ws.on('close', ()=>{
489
488
  if (isDev) console.log(messages.hE8());
490
489
  onRejectPending('CDP connection closed');
490
+ reject(new Error('CDP WebSocket closed before the connection opened'));
491
491
  });
492
492
  });
493
493
  }
@@ -771,6 +771,55 @@ exports.modules = {
771
771
  async getPageHTML(sessionId, includeShadow = 'open-only') {
772
772
  return getPageHTML(this, sessionId, includeShadow);
773
773
  }
774
+ async getClosedShadowRoots(sessionId, maxBytes = 65536) {
775
+ await this.sendCommand('DOM.enable', {}, sessionId);
776
+ const doc = await this.sendCommand('DOM.getDocument', {
777
+ depth: -1,
778
+ pierce: true
779
+ }, sessionId);
780
+ const found = [];
781
+ const walk = (node, hostName)=>{
782
+ if (!node || 'object' != typeof node) return;
783
+ const name = node.localName || node.nodeName || hostName;
784
+ if (Array.isArray(node.shadowRoots)) for (const sr of node.shadowRoots){
785
+ if (sr && 'closed' === sr.shadowRootType && 'number' == typeof sr.nodeId) found.push({
786
+ nodeId: sr.nodeId,
787
+ host: String(name)
788
+ });
789
+ walk(sr, name);
790
+ }
791
+ if (Array.isArray(node.children)) for (const c of node.children)walk(c, name);
792
+ if (node.contentDocument) walk(node.contentDocument, name);
793
+ };
794
+ walk(doc.root, 'html');
795
+ const out = [];
796
+ for (const f of found)try {
797
+ const oh = await this.sendCommand('DOM.getOuterHTML', {
798
+ nodeId: f.nodeId
799
+ }, sessionId);
800
+ let html = String(oh?.outerHTML ?? '');
801
+ let truncated = false;
802
+ if (maxBytes > 0 && html.length > maxBytes) {
803
+ html = html.slice(0, maxBytes);
804
+ truncated = true;
805
+ }
806
+ out.push({
807
+ host: f.host,
808
+ type: 'closed',
809
+ html,
810
+ ...truncated ? {
811
+ truncated
812
+ } : {}
813
+ });
814
+ } catch {
815
+ out.push({
816
+ host: f.host,
817
+ type: 'closed',
818
+ html: ''
819
+ });
820
+ }
821
+ return out;
822
+ }
774
823
  async closeTarget(targetId) {
775
824
  await this.sendCommand('Target.closeTarget', {
776
825
  targetId
@@ -1127,6 +1176,23 @@ exports.modules = {
1127
1176
  else obj[key] = value;
1128
1177
  return obj;
1129
1178
  }
1179
+ const __fileReadCache = new Map();
1180
+ function readTextFileCached(filePath) {
1181
+ try {
1182
+ const stat = external_fs_.statSync(filePath);
1183
+ const key = `${stat.mtimeMs}:${stat.size}`;
1184
+ const cached = __fileReadCache.get(filePath);
1185
+ if (cached && cached.key === key) return cached.text;
1186
+ const text = external_fs_.readFileSync(filePath, 'utf-8');
1187
+ __fileReadCache.set(filePath, {
1188
+ key,
1189
+ text
1190
+ });
1191
+ return text;
1192
+ } catch {
1193
+ return external_fs_.readFileSync(filePath, 'utf-8');
1194
+ }
1195
+ }
1130
1196
  class CDPExtensionController {
1131
1197
  async connect() {
1132
1198
  if (this.cdp) return;
@@ -1155,7 +1221,7 @@ exports.modules = {
1155
1221
  info = await this.cdp.getExtensionInfo(this.extensionId);
1156
1222
  } catch {}
1157
1223
  if (!info) {
1158
- const manifest = JSON.parse(external_fs_.readFileSync(external_path_.join(this.outPath, 'manifest.json'), 'utf-8'));
1224
+ const manifest = JSON.parse(readTextFileCached(external_path_.join(this.outPath, 'manifest.json')));
1159
1225
  return {
1160
1226
  extensionId: this.extensionId,
1161
1227
  name: manifest.name,
@@ -1402,7 +1468,7 @@ exports.modules = {
1402
1468
  for (const rule of matchingRules){
1403
1469
  const bundlePath = (0, content_script_targets.nG)(this.outPath, rule.index, 'js');
1404
1470
  if (!bundlePath || !external_fs_.existsSync(bundlePath)) continue;
1405
- const source = this.patchReinjectSourceForInvalidatedRuntime(external_fs_.readFileSync(bundlePath, 'utf-8'));
1471
+ const source = this.patchReinjectSourceForInvalidatedRuntime(readTextFileCached(bundlePath));
1406
1472
  if (!source.trim()) continue;
1407
1473
  const bundleId = (0, content_script_contracts.Y)(rule.index);
1408
1474
  const expression = this.buildReinjectExpression(bundleId, source, true);
@@ -1441,7 +1507,7 @@ exports.modules = {
1441
1507
  if (!jsPath || !external_fs_.existsSync(jsPath)) return null;
1442
1508
  const jsFile = external_path_.relative(this.outPath, jsPath).replace(/\\/g, '/');
1443
1509
  const cssFile = cssPath && external_fs_.existsSync(cssPath) ? external_path_.relative(this.outPath, cssPath).replace(/\\/g, '/') : null;
1444
- const jsSource = external_fs_.readFileSync(jsPath, 'utf-8');
1510
+ const jsSource = readTextFileCached(jsPath);
1445
1511
  const buildTokenMatch = jsSource.match(/__EXTENSIONJS_REINJECT_BUILD_TOKEN\s*=\s*"([^"]+)"/);
1446
1512
  const proofMatch = jsSource.match(/extjs-chromium-live-content-css-modules:script-primary-\d+/) || jsSource.match(/Live Update Proof [A-Za-z0-9_-]+/);
1447
1513
  return {
@@ -1778,7 +1844,7 @@ exports.modules = {
1778
1844
  version = info?.extensionInfo?.version;
1779
1845
  } catch {
1780
1846
  try {
1781
- const manifest = JSON.parse(external_fs_.readFileSync(external_path_.join(this.outPath, 'manifest.json'), 'utf-8'));
1847
+ const manifest = JSON.parse(readTextFileCached(external_path_.join(this.outPath, 'manifest.json')));
1782
1848
  name = manifest?.name;
1783
1849
  version = manifest?.version;
1784
1850
  } catch {}
@@ -1798,7 +1864,7 @@ exports.modules = {
1798
1864
  const bundlePath = (0, content_script_targets.nG)(this.outPath, rule.index, 'js');
1799
1865
  if (!bundlePath || !external_fs_.existsSync(bundlePath)) return false;
1800
1866
  const sourceOverride = sourceOverridesByBundleId && 'object' == typeof sourceOverridesByBundleId ? sourceOverridesByBundleId[bundleId] : void 0;
1801
- const source = this.patchReinjectSourceForInvalidatedRuntime('string' == typeof sourceOverride ? sourceOverride : external_fs_.readFileSync(bundlePath, 'utf-8'));
1867
+ const source = this.patchReinjectSourceForInvalidatedRuntime('string' == typeof sourceOverride ? sourceOverride : readTextFileCached(bundlePath));
1802
1868
  const buildTokenMatch = source.match(/__EXTENSIONJS_REINJECT_BUILD_TOKEN\s*=\s*"([^"]+)"/);
1803
1869
  const proofMatch = source.match(/extjs-chromium-live-content-css-modules:script-primary-\d+/) || source.match(/Live Update Proof [A-Za-z0-9_-]+/);
1804
1870
  if (!source.trim()) return false;
@@ -2093,6 +2159,18 @@ exports.modules = {
2093
2159
  });
2094
2160
  await cdpExtensionController.connect();
2095
2161
  if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(messages.M3V('127.0.0.1', chromeRemoteDebugPort));
2162
+ try {
2163
+ if (extensionOutputPath && Number.isFinite(chromeRemoteDebugPort)) {
2164
+ const readyPath = external_path_.join(external_path_.dirname(extensionOutputPath), 'extension-js', external_path_.basename(extensionOutputPath), 'ready.json');
2165
+ if (external_fs_.existsSync(readyPath)) {
2166
+ const ready = JSON.parse(external_fs_.readFileSync(readyPath, 'utf-8'));
2167
+ if (ready.cdpPort !== chromeRemoteDebugPort) {
2168
+ ready.cdpPort = chromeRemoteDebugPort;
2169
+ external_fs_.writeFileSync(readyPath, JSON.stringify(ready, null, 2));
2170
+ }
2171
+ }
2172
+ }
2173
+ } catch {}
2096
2174
  const mode = compilation?.options?.mode || 'development';
2097
2175
  let earlyBannerPrinted = false;
2098
2176
  if ('development' === mode) try {