extension 3.14.0 → 3.14.2-canary.280.67296cf

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/631.cjs CHANGED
@@ -14,153 +14,6 @@ exports.modules = {
14
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
- async function deriveExtensionIdFromTargetsHelper(cdp, outPath, maxRetries = 6, backoffMs = 150, profilePath, extensionPaths) {
18
- let expectedName;
19
- let expectedVersion;
20
- let expectedManifestVersion;
21
- let expectedNameIsMsg = false;
22
- try {
23
- const manifest = JSON.parse(external_fs_.readFileSync(external_path_.join(outPath, 'manifest.json'), 'utf-8'));
24
- expectedName = manifest?.name;
25
- expectedVersion = manifest?.version;
26
- expectedManifestVersion = manifest?.manifest_version;
27
- expectedNameIsMsg = 'string' == typeof expectedName && /__MSG_/i.test(expectedName);
28
- if (expectedNameIsMsg) {
29
- const defaultLocale = String(manifest?.default_locale || '').trim();
30
- const msgKeyMatch = String(expectedName || '').match(/__MSG_(.+)__/i);
31
- const msgKey = msgKeyMatch ? msgKeyMatch[1] : '';
32
- if (defaultLocale && msgKey) {
33
- const messagesPath = external_path_.join(outPath, '_locales', defaultLocale, 'messages.json');
34
- if (external_fs_.existsSync(messagesPath)) {
35
- const messagesJson = JSON.parse(external_fs_.readFileSync(messagesPath, 'utf-8'));
36
- const resolved = String(messagesJson?.[msgKey]?.message || '').trim();
37
- if (resolved) {
38
- expectedName = resolved;
39
- expectedNameIsMsg = false;
40
- }
41
- }
42
- }
43
- }
44
- } catch {}
45
- const trimTrailingSep = (p)=>{
46
- let end = p.length;
47
- while(end > 0 && ('/' === p[end - 1] || '\\' === p[end - 1]))end--;
48
- return p.slice(0, end);
49
- };
50
- const normalizePath = (p)=>{
51
- try {
52
- const resolved = external_path_.resolve(p);
53
- if (external_fs_.existsSync(resolved)) return trimTrailingSep(external_fs_.realpathSync(resolved));
54
- return trimTrailingSep(resolved);
55
- } catch {
56
- return trimTrailingSep(external_path_.resolve(p));
57
- }
58
- };
59
- const resolvedOutPath = normalizePath(outPath);
60
- const normalizedCandidates = Array.isArray(extensionPaths) ? extensionPaths.map((p)=>p ? normalizePath(p) : '').filter(Boolean) : [];
61
- const resolvedCandidates = normalizedCandidates.length ? normalizedCandidates : [
62
- resolvedOutPath
63
- ];
64
- const platformIsCaseInsensitive = 'win32' === process.platform || 'darwin' === process.platform;
65
- const normalizeForCompare = (p)=>platformIsCaseInsensitive ? p.toLowerCase() : p;
66
- const matchesAnyCandidate = (p)=>{
67
- const n = normalizeForCompare(p);
68
- return resolvedCandidates.some((candidate)=>n === normalizeForCompare(candidate));
69
- };
70
- const deriveFromProfile = ()=>{
71
- if (!profilePath) return null;
72
- const candidates = [];
73
- const pushPrefIfExists = (dir)=>{
74
- const prefPath = external_path_.join(dir, 'Preferences');
75
- if (external_fs_.existsSync(prefPath)) candidates.push(prefPath);
76
- };
77
- try {
78
- pushPrefIfExists(profilePath);
79
- pushPrefIfExists(external_path_.join(profilePath, 'Default'));
80
- const entries = external_fs_.readdirSync(profilePath);
81
- for (const entry of entries)if (/^Profile\s+\d+$/i.test(entry)) pushPrefIfExists(external_path_.join(profilePath, entry));
82
- } catch {}
83
- for (const prefPath of candidates)try {
84
- if (!external_fs_.existsSync(prefPath)) continue;
85
- const prefs = JSON.parse(external_fs_.readFileSync(prefPath, 'utf-8'));
86
- const settings = prefs?.extensions?.settings;
87
- if (!settings || 'object' != typeof settings) continue;
88
- const entries = Object.entries(settings);
89
- let fallbackId = null;
90
- for (const [id, info] of entries){
91
- const storedPath = String(info?.path || '');
92
- if (!storedPath) continue;
93
- const normalized = normalizePath(storedPath);
94
- if (!matchesAnyCandidate(normalized)) continue;
95
- const manifestName = String(info?.manifest?.name || '');
96
- const manifestVersion = String(info?.manifest?.version || '');
97
- if (expectedName && manifestName === expectedName) return id;
98
- if (expectedVersion && manifestVersion === expectedVersion) return id;
99
- fallbackId = id;
100
- }
101
- if (fallbackId) return fallbackId;
102
- } catch {}
103
- return null;
104
- };
105
- let retries = 0;
106
- let deferredFirstEvalId = null;
107
- let deferredUrlDerivedId = null;
108
- const hasExpectedManifestIdentity = Boolean(expectedName || expectedVersion || expectedManifestVersion);
109
- while(retries <= maxRetries){
110
- try {
111
- const targets = await cdp.getTargets();
112
- const profileCandidateId = deriveFromProfile();
113
- let firstEvalId = null;
114
- let evalIdCount = 0;
115
- let urlDerivedId = null;
116
- for (const t of targets || []){
117
- const url = String(t?.url || '');
118
- const type = String(t?.type || '');
119
- const typeOk = [
120
- 'service_worker',
121
- 'background_page',
122
- 'worker'
123
- ].includes(type);
124
- if (!typeOk) continue;
125
- const urlMatch = url.match(/^chrome-extension:\/\/([^\/]+)/);
126
- if (!urlDerivedId && urlMatch?.[1]) urlDerivedId = String(urlMatch[1]);
127
- if (url && !url.startsWith('chrome-extension://')) continue;
128
- const targetId = t?.targetId;
129
- if (targetId) try {
130
- const sessionId = await cdp.attachToTarget(targetId);
131
- if (!sessionId) continue;
132
- await cdp.sendCommand('Runtime.enable', {}, sessionId);
133
- const info = await cdp.evaluate(sessionId, '(()=>{try{const m=chrome.runtime.getManifest?.();return {id:chrome.runtime?.id||"",name:m?.name||"",version:m?.version||"",manifestVersion:m?.manifest_version||0}}catch(_){return null}})()');
134
- const id = String(info?.id || '').trim();
135
- if (!id) continue;
136
- evalIdCount += 1;
137
- if (!firstEvalId) firstEvalId = id;
138
- if (profileCandidateId && id === profileCandidateId) return id;
139
- const gotName = String(info?.name || '');
140
- const gotVersion = String(info?.version || '');
141
- const gotManifestVersion = Number(info?.manifestVersion || 0);
142
- const nameMatches = expectedName && !expectedNameIsMsg ? gotName === expectedName : false;
143
- const versionMatches = expectedVersion ? gotVersion === expectedVersion : false;
144
- const manifestVersionMatches = expectedManifestVersion ? gotManifestVersion === expectedManifestVersion : false;
145
- if (nameMatches && (!profileCandidateId || id === profileCandidateId)) return id;
146
- if (expectedVersion && versionMatches && (expectedManifestVersion ? manifestVersionMatches : true) && (!profileCandidateId || id === profileCandidateId)) return id;
147
- } catch {}
148
- }
149
- if (1 === evalIdCount && firstEvalId) {
150
- if (!hasExpectedManifestIdentity) return firstEvalId;
151
- deferredFirstEvalId = deferredFirstEvalId || firstEvalId;
152
- }
153
- if (profileCandidateId) return profileCandidateId;
154
- if (urlDerivedId) {
155
- if (!hasExpectedManifestIdentity) return urlDerivedId;
156
- deferredUrlDerivedId = deferredUrlDerivedId || urlDerivedId;
157
- }
158
- } catch {}
159
- await new Promise((r)=>setTimeout(r, backoffMs));
160
- retries++;
161
- }
162
- return deriveFromProfile() || deferredFirstEvalId || deferredUrlDerivedId;
163
- }
164
17
  var external_ws_ = __webpack_require__("ws");
165
18
  var external_ws_default = /*#__PURE__*/ __webpack_require__.n(external_ws_);
166
19
  var constants = __webpack_require__("./browsers/browsers-lib/constants.ts");
@@ -648,6 +501,17 @@ exports.modules = {
648
501
  else obj[key] = value;
649
502
  return obj;
650
503
  }
504
+ const EXTENSION_AUTO_ATTACH_FILTER = [
505
+ {
506
+ type: 'page',
507
+ exclude: true
508
+ },
509
+ {
510
+ type: 'iframe',
511
+ exclude: true
512
+ },
513
+ {}
514
+ ];
651
515
  class CDPClient {
652
516
  isDev() {
653
517
  return 'true' === process.env.EXTENSION_AUTHOR_MODE;
@@ -1001,6 +865,153 @@ exports.modules = {
1001
865
  this.host = host;
1002
866
  }
1003
867
  }
868
+ async function deriveExtensionIdFromTargetsHelper(cdp, outPath, maxRetries = 6, backoffMs = 150, profilePath, extensionPaths) {
869
+ let expectedName;
870
+ let expectedVersion;
871
+ let expectedManifestVersion;
872
+ let expectedNameIsMsg = false;
873
+ try {
874
+ const manifest = JSON.parse(external_fs_.readFileSync(external_path_.join(outPath, 'manifest.json'), 'utf-8'));
875
+ expectedName = manifest?.name;
876
+ expectedVersion = manifest?.version;
877
+ expectedManifestVersion = manifest?.manifest_version;
878
+ expectedNameIsMsg = 'string' == typeof expectedName && /__MSG_/i.test(expectedName);
879
+ if (expectedNameIsMsg) {
880
+ const defaultLocale = String(manifest?.default_locale || '').trim();
881
+ const msgKeyMatch = String(expectedName || '').match(/__MSG_(.+)__/i);
882
+ const msgKey = msgKeyMatch ? msgKeyMatch[1] : '';
883
+ if (defaultLocale && msgKey) {
884
+ const messagesPath = external_path_.join(outPath, '_locales', defaultLocale, 'messages.json');
885
+ if (external_fs_.existsSync(messagesPath)) {
886
+ const messagesJson = JSON.parse(external_fs_.readFileSync(messagesPath, 'utf-8'));
887
+ const resolved = String(messagesJson?.[msgKey]?.message || '').trim();
888
+ if (resolved) {
889
+ expectedName = resolved;
890
+ expectedNameIsMsg = false;
891
+ }
892
+ }
893
+ }
894
+ }
895
+ } catch {}
896
+ const trimTrailingSep = (p)=>{
897
+ let end = p.length;
898
+ while(end > 0 && ('/' === p[end - 1] || '\\' === p[end - 1]))end--;
899
+ return p.slice(0, end);
900
+ };
901
+ const normalizePath = (p)=>{
902
+ try {
903
+ const resolved = external_path_.resolve(p);
904
+ if (external_fs_.existsSync(resolved)) return trimTrailingSep(external_fs_.realpathSync(resolved));
905
+ return trimTrailingSep(resolved);
906
+ } catch {
907
+ return trimTrailingSep(external_path_.resolve(p));
908
+ }
909
+ };
910
+ const resolvedOutPath = normalizePath(outPath);
911
+ const normalizedCandidates = Array.isArray(extensionPaths) ? extensionPaths.map((p)=>p ? normalizePath(p) : '').filter(Boolean) : [];
912
+ const resolvedCandidates = normalizedCandidates.length ? normalizedCandidates : [
913
+ resolvedOutPath
914
+ ];
915
+ const platformIsCaseInsensitive = 'win32' === process.platform || 'darwin' === process.platform;
916
+ const normalizeForCompare = (p)=>platformIsCaseInsensitive ? p.toLowerCase() : p;
917
+ const matchesAnyCandidate = (p)=>{
918
+ const n = normalizeForCompare(p);
919
+ return resolvedCandidates.some((candidate)=>n === normalizeForCompare(candidate));
920
+ };
921
+ const deriveFromProfile = ()=>{
922
+ if (!profilePath) return null;
923
+ const candidates = [];
924
+ const pushPrefIfExists = (dir)=>{
925
+ const prefPath = external_path_.join(dir, 'Preferences');
926
+ if (external_fs_.existsSync(prefPath)) candidates.push(prefPath);
927
+ };
928
+ try {
929
+ pushPrefIfExists(profilePath);
930
+ pushPrefIfExists(external_path_.join(profilePath, 'Default'));
931
+ const entries = external_fs_.readdirSync(profilePath);
932
+ for (const entry of entries)if (/^Profile\s+\d+$/i.test(entry)) pushPrefIfExists(external_path_.join(profilePath, entry));
933
+ } catch {}
934
+ for (const prefPath of candidates)try {
935
+ if (!external_fs_.existsSync(prefPath)) continue;
936
+ const prefs = JSON.parse(external_fs_.readFileSync(prefPath, 'utf-8'));
937
+ const settings = prefs?.extensions?.settings;
938
+ if (!settings || 'object' != typeof settings) continue;
939
+ const entries = Object.entries(settings);
940
+ let fallbackId = null;
941
+ for (const [id, info] of entries){
942
+ const storedPath = String(info?.path || '');
943
+ if (!storedPath) continue;
944
+ const normalized = normalizePath(storedPath);
945
+ if (!matchesAnyCandidate(normalized)) continue;
946
+ const manifestName = String(info?.manifest?.name || '');
947
+ const manifestVersion = String(info?.manifest?.version || '');
948
+ if (expectedName && manifestName === expectedName) return id;
949
+ if (expectedVersion && manifestVersion === expectedVersion) return id;
950
+ fallbackId = id;
951
+ }
952
+ if (fallbackId) return fallbackId;
953
+ } catch {}
954
+ return null;
955
+ };
956
+ let retries = 0;
957
+ let deferredFirstEvalId = null;
958
+ let deferredUrlDerivedId = null;
959
+ const hasExpectedManifestIdentity = Boolean(expectedName || expectedVersion || expectedManifestVersion);
960
+ while(retries <= maxRetries){
961
+ try {
962
+ const targets = await cdp.getTargets();
963
+ const profileCandidateId = deriveFromProfile();
964
+ let firstEvalId = null;
965
+ let evalIdCount = 0;
966
+ let urlDerivedId = null;
967
+ for (const t of targets || []){
968
+ const url = String(t?.url || '');
969
+ const type = String(t?.type || '');
970
+ const typeOk = [
971
+ 'service_worker',
972
+ 'background_page',
973
+ 'worker'
974
+ ].includes(type);
975
+ if (!typeOk) continue;
976
+ const urlMatch = url.match(/^chrome-extension:\/\/([^\/]+)/);
977
+ if (!urlDerivedId && urlMatch?.[1]) urlDerivedId = String(urlMatch[1]);
978
+ if (url && !url.startsWith('chrome-extension://')) continue;
979
+ const targetId = t?.targetId;
980
+ if (targetId) try {
981
+ const sessionId = await cdp.attachToTarget(targetId);
982
+ if (!sessionId) continue;
983
+ await cdp.sendCommand('Runtime.enable', {}, sessionId);
984
+ const info = await cdp.evaluate(sessionId, '(()=>{try{const m=chrome.runtime.getManifest?.();return {id:chrome.runtime?.id||"",name:m?.name||"",version:m?.version||"",manifestVersion:m?.manifest_version||0}}catch(_){return null}})()');
985
+ const id = String(info?.id || '').trim();
986
+ if (!id) continue;
987
+ evalIdCount += 1;
988
+ if (!firstEvalId) firstEvalId = id;
989
+ if (profileCandidateId && id === profileCandidateId) return id;
990
+ const gotName = String(info?.name || '');
991
+ const gotVersion = String(info?.version || '');
992
+ const gotManifestVersion = Number(info?.manifestVersion || 0);
993
+ const nameMatches = expectedName && !expectedNameIsMsg ? gotName === expectedName : false;
994
+ const versionMatches = expectedVersion ? gotVersion === expectedVersion : false;
995
+ const manifestVersionMatches = expectedManifestVersion ? gotManifestVersion === expectedManifestVersion : false;
996
+ if (nameMatches && (!profileCandidateId || id === profileCandidateId)) return id;
997
+ if (expectedVersion && versionMatches && (expectedManifestVersion ? manifestVersionMatches : true) && (!profileCandidateId || id === profileCandidateId)) return id;
998
+ } catch {}
999
+ }
1000
+ if (1 === evalIdCount && firstEvalId) {
1001
+ if (!hasExpectedManifestIdentity) return firstEvalId;
1002
+ deferredFirstEvalId = deferredFirstEvalId || firstEvalId;
1003
+ }
1004
+ if (profileCandidateId) return profileCandidateId;
1005
+ if (urlDerivedId) {
1006
+ if (!hasExpectedManifestIdentity) return urlDerivedId;
1007
+ deferredUrlDerivedId = deferredUrlDerivedId || urlDerivedId;
1008
+ }
1009
+ } catch {}
1010
+ await new Promise((r)=>setTimeout(r, backoffMs));
1011
+ retries++;
1012
+ }
1013
+ return deriveFromProfile() || deferredFirstEvalId || deferredUrlDerivedId;
1014
+ }
1004
1015
  function isRecoverableBootstrapError(error) {
1005
1016
  const msg = String(error?.message || error || '').toLowerCase();
1006
1017
  return msg.includes('econnreset') || msg.includes('websocket is not open') || msg.includes('cdp transport is not open') || msg.includes('cdp connection closed') || msg.includes('cdp pipe closed') || msg.includes('socket hang up') || msg.includes('timed out') || msg.includes('no cdp websocket url');
@@ -1015,7 +1026,8 @@ exports.modules = {
1015
1026
  await cdp.sendCommand('Target.setAutoAttach', {
1016
1027
  autoAttach: true,
1017
1028
  waitForDebuggerOnStart: false,
1018
- flatten: true
1029
+ flatten: true,
1030
+ filter: EXTENSION_AUTO_ATTACH_FILTER
1019
1031
  });
1020
1032
  return cdp;
1021
1033
  } catch (error) {
@@ -1045,7 +1057,8 @@ exports.modules = {
1045
1057
  await cdp.sendCommand('Target.setAutoAttach', {
1046
1058
  autoAttach: true,
1047
1059
  waitForDebuggerOnStart: false,
1048
- flatten: true
1060
+ flatten: true,
1061
+ filter: EXTENSION_AUTO_ATTACH_FILTER
1049
1062
  });
1050
1063
  return cdp;
1051
1064
  } catch (error) {
@@ -1482,7 +1495,8 @@ exports.modules = {
1482
1495
  await this.cdp.sendCommand('Target.setAutoAttach', {
1483
1496
  autoAttach: true,
1484
1497
  waitForDebuggerOnStart: false,
1485
- flatten: true
1498
+ flatten: true,
1499
+ filter: EXTENSION_AUTO_ATTACH_FILTER
1486
1500
  });
1487
1501
  } catch (error) {
1488
1502
  if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.warn(messages.wXK(String(error?.message || error)));
package/dist/browsers.cjs CHANGED
@@ -1500,7 +1500,8 @@ var __webpack_modules__ = {
1500
1500
  '--no-pings',
1501
1501
  '--enable-features=SidePanelUpdates',
1502
1502
  '--disable-features=DisableLoadExtensionCommandLineSwitch',
1503
- '--enable-unsafe-extension-debugging'
1503
+ '--enable-unsafe-extension-debugging',
1504
+ '--silent-debugger-extension-api'
1504
1505
  ];
1505
1506
  function isPlainObject(value) {
1506
1507
  return !!value && 'object' == typeof value && !Array.isArray(value);
package/dist/cli.cjs CHANGED
@@ -1702,7 +1702,8 @@ var __webpack_modules__ = {
1702
1702
  '--no-pings',
1703
1703
  '--enable-features=SidePanelUpdates',
1704
1704
  '--disable-features=DisableLoadExtensionCommandLineSwitch',
1705
- '--enable-unsafe-extension-debugging'
1705
+ '--enable-unsafe-extension-debugging',
1706
+ '--silent-debugger-extension-api'
1706
1707
  ];
1707
1708
  function isPlainObject(value) {
1708
1709
  return !!value && 'object' == typeof value && !Array.isArray(value);
@@ -46,7 +46,7 @@ export interface BrowserConfig {
46
46
  *
47
47
  * Each flag disables or modifies a specific browser feature for a more controlled development environment.
48
48
  */
49
- export type DefaultBrowserFlags = '--no-first-run' | '--disable-client-side-phishing-detection' | '--disable-component-extensions-with-background-pages' | '--disable-default-apps' | '--disable-features=InterestFeedContentSuggestions' | '--disable-features=Translate' | '--hide-scrollbars' | '--mute-audio' | '--no-default-browser-check' | '--ash-no-nudges' | '--disable-search-engine-choice-screen' | '--disable-features=MediaRoute' | '--use-mock-keychain' | '--disable-background-networking' | '--disable-breakpad' | '--disable-component-update' | '--disable-domain-reliability' | '--disable-features=AutofillServerCommunicatio' | '--disable-features=CertificateTransparencyComponentUpdate' | '--disable-sync' | '--disable-features=OptimizationHints' | '--disable-features=DialMediaRouteProvider' | '--no-pings' | '--enable-features=SidePanelUpdates' | '--enable-unsafe-extension-debugging';
49
+ export type DefaultBrowserFlags = '--no-first-run' | '--disable-client-side-phishing-detection' | '--disable-component-extensions-with-background-pages' | '--disable-default-apps' | '--disable-features=InterestFeedContentSuggestions' | '--disable-features=Translate' | '--hide-scrollbars' | '--mute-audio' | '--no-default-browser-check' | '--ash-no-nudges' | '--disable-search-engine-choice-screen' | '--disable-features=MediaRoute' | '--use-mock-keychain' | '--disable-background-networking' | '--disable-breakpad' | '--disable-component-update' | '--disable-domain-reliability' | '--disable-features=AutofillServerCommunicatio' | '--disable-features=CertificateTransparencyComponentUpdate' | '--disable-sync' | '--disable-features=OptimizationHints' | '--disable-features=DialMediaRouteProvider' | '--no-pings' | '--enable-features=SidePanelUpdates' | '--enable-unsafe-extension-debugging' | '--silent-debugger-extension-api';
50
50
  /**
51
51
  * Options for the browser plugin.
52
52
  */
@@ -1,5 +1,9 @@
1
1
  import type { Readable, Writable } from 'stream';
2
2
  import { type ExtensionRootMetaPayload } from './page';
3
+ export declare const EXTENSION_AUTO_ATTACH_FILTER: Array<{
4
+ type?: string;
5
+ exclude?: boolean;
6
+ }>;
3
7
  export declare class CDPClient {
4
8
  private port;
5
9
  private host;
package/package.json CHANGED
@@ -38,7 +38,7 @@
38
38
  "extension": "./bin/extension.cjs"
39
39
  },
40
40
  "name": "extension",
41
- "version": "3.14.0",
41
+ "version": "3.14.2-canary.280.67296cf",
42
42
  "description": "Create cross-browser extensions with no build configuration.",
43
43
  "homepage": "https://extension.js.org/",
44
44
  "bugs": {
@@ -100,9 +100,9 @@
100
100
  "cross-spawn": "^7.0.6",
101
101
  "edge-location": "2.2.0",
102
102
  "firefox-location2": "3.0.0",
103
- "extension-create": "3.14.0",
104
- "extension-develop": "3.14.0",
105
- "extension-install": "3.14.0",
103
+ "extension-create": "3.14.2-canary.280.67296cf",
104
+ "extension-develop": "3.14.2-canary.280.67296cf",
105
+ "extension-install": "3.14.2-canary.280.67296cf",
106
106
  "commander": "^14.0.3",
107
107
  "pintor": "0.3.0",
108
108
  "semver": "^7.7.3",