web-ext 7.12.0 → 8.0.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.
Files changed (66) hide show
  1. package/README.md +6 -8
  2. package/bin/web-ext.js +1 -1
  3. package/lib/cmd/build.js +1 -3
  4. package/lib/cmd/build.js.map +1 -1
  5. package/lib/cmd/docs.js +1 -0
  6. package/lib/cmd/docs.js.map +1 -1
  7. package/lib/cmd/dump-config.js +6 -0
  8. package/lib/cmd/dump-config.js.map +1 -0
  9. package/lib/cmd/index.js +16 -8
  10. package/lib/cmd/index.js.map +1 -1
  11. package/lib/cmd/lint.js +0 -8
  12. package/lib/cmd/lint.js.map +1 -1
  13. package/lib/cmd/run.js +0 -7
  14. package/lib/cmd/run.js.map +1 -1
  15. package/lib/cmd/sign.js +29 -85
  16. package/lib/cmd/sign.js.map +1 -1
  17. package/lib/config.js +53 -7
  18. package/lib/config.js.map +1 -1
  19. package/lib/errors.js.map +1 -1
  20. package/lib/extension-runners/chromium.js +11 -3
  21. package/lib/extension-runners/chromium.js.map +1 -1
  22. package/lib/extension-runners/firefox-android.js +15 -3
  23. package/lib/extension-runners/firefox-android.js.map +1 -1
  24. package/lib/extension-runners/firefox-desktop.js +7 -8
  25. package/lib/extension-runners/firefox-desktop.js.map +1 -1
  26. package/lib/extension-runners/index.js +2 -2
  27. package/lib/extension-runners/index.js.map +1 -1
  28. package/lib/firefox/index.js +1 -8
  29. package/lib/firefox/index.js.map +1 -1
  30. package/lib/firefox/package-identifiers.js +3 -1
  31. package/lib/firefox/package-identifiers.js.map +1 -1
  32. package/lib/firefox/preferences.js +0 -2
  33. package/lib/firefox/preferences.js.map +1 -1
  34. package/lib/firefox/rdp-client.js +10 -2
  35. package/lib/firefox/rdp-client.js.map +1 -1
  36. package/lib/firefox/remote.js +3 -2
  37. package/lib/firefox/remote.js.map +1 -1
  38. package/lib/main.js.map +1 -1
  39. package/lib/program.js +25 -48
  40. package/lib/program.js.map +1 -1
  41. package/lib/util/adb.js +15 -9
  42. package/lib/util/adb.js.map +1 -1
  43. package/lib/util/artifacts.js.map +1 -1
  44. package/lib/util/desktop-notifier.js.map +1 -1
  45. package/lib/util/file-exists.js +1 -0
  46. package/lib/util/file-exists.js.map +1 -1
  47. package/lib/util/file-filter.js +2 -0
  48. package/lib/util/file-filter.js.map +1 -1
  49. package/lib/util/is-directory.js.map +1 -1
  50. package/lib/util/logger.js +5 -5
  51. package/lib/util/logger.js.map +1 -1
  52. package/lib/util/manifest.js +1 -1
  53. package/lib/util/manifest.js.map +1 -1
  54. package/lib/util/promisify.js +0 -7
  55. package/lib/util/promisify.js.map +1 -1
  56. package/lib/util/stdin.js +0 -2
  57. package/lib/util/stdin.js.map +1 -1
  58. package/lib/util/submit-addon.js +214 -50
  59. package/lib/util/submit-addon.js.map +1 -1
  60. package/lib/util/temp-dir.js +2 -0
  61. package/lib/util/temp-dir.js.map +1 -1
  62. package/lib/util/updates.js.map +1 -1
  63. package/lib/watcher.js.map +1 -1
  64. package/package.json +36 -38
  65. package/lib/extension-runners/base.js +0 -2
  66. package/lib/extension-runners/base.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"preferences.js","names":["WebExtError","UsageError","createLogger","log","import","meta","url","nonOverridablePreferences","prefsCommon","prefsFennec","prefsFirefox","prefs","common","fennec","firefox","getPrefs","app","appPrefs","coerceCLICustomPreference","cliPrefs","customPrefs","pref","prefsAry","split","length","key","value","slice","join","test","parseInt","includes","warn"],"sources":["../../src/firefox/preferences.js"],"sourcesContent":["/* @flow */\nimport { WebExtError, UsageError } from '../errors.js';\nimport { createLogger } from '../util/logger.js';\n\nconst log = createLogger(import.meta.url);\n\nexport const nonOverridablePreferences = [\n 'devtools.debugger.remote-enabled',\n 'devtools.debugger.prompt-connection',\n 'xpinstall.signatures.required',\n];\n\n// Flow Types\n\nexport type FirefoxPreferences = {\n [key: string]: boolean | string | number,\n};\n\nexport type PreferencesAppName = 'firefox' | 'fennec';\n\n// Preferences Maps\n\nconst prefsCommon: FirefoxPreferences = {\n // Allow debug output via dump to be printed to the system console\n 'browser.dom.window.dump.enabled': true,\n\n // From:\n // https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/internals/preferences.html#data-choices-notification\n // This is the data submission master kill switch. If disabled, no policy is shown or upload takes place, ever.\n 'datareporting.policy.dataSubmissionEnabled': false,\n\n // Allow remote connections to the debugger.\n 'devtools.debugger.remote-enabled': true,\n // Disable the prompt for allowing connections.\n 'devtools.debugger.prompt-connection': false,\n // Allow extensions to log messages on browser's console.\n 'devtools.browserconsole.contentMessages': true,\n\n // Turn off platform logging because it is a lot of info.\n 'extensions.logging.enabled': false,\n\n // Disable extension updates and notifications.\n 'extensions.checkCompatibility.nightly': false,\n 'extensions.update.enabled': false,\n 'extensions.update.notifyUser': false,\n\n // From:\n // http://hg.mozilla.org/mozilla-central/file/1dd81c324ac7/build/automation.py.in//l372\n // Only load extensions from the application and user profile.\n // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION\n 'extensions.enabledScopes': 5,\n // Disable metadata caching for installed add-ons by default.\n 'extensions.getAddons.cache.enabled': false,\n // Disable intalling any distribution add-ons.\n 'extensions.installDistroAddons': false,\n // Allow installing extensions dropped into the profile folder.\n 'extensions.autoDisableScopes': 10,\n\n // Disable app update.\n 'app.update.enabled': false,\n\n // Allow unsigned add-ons.\n 'xpinstall.signatures.required': false,\n\n // browser.link.open_newwindow is changed from 3 to 2 in:\n // https://github.com/saadtazi/firefox-profile-js/blob/cafc793d940a779d280103ae17d02a92de862efc/lib/firefox_profile.js#L32\n // Restore original value to avoid https://github.com/mozilla/web-ext/issues/1592\n 'browser.link.open_newwindow': 3,\n};\n\n// Prefs specific to Firefox for Android.\nconst prefsFennec: FirefoxPreferences = {\n 'browser.console.showInPanel': true,\n 'browser.firstrun.show.uidiscovery': false,\n 'devtools.remote.usb.enabled': true,\n};\n\n// Prefs specific to Firefox for desktop.\nconst prefsFirefox: FirefoxPreferences = {\n 'browser.startup.homepage': 'about:blank',\n 'startup.homepage_welcome_url': 'about:blank',\n 'startup.homepage_welcome_url.additional': '',\n 'devtools.errorconsole.enabled': true,\n 'devtools.chrome.enabled': true,\n\n // From:\n // http://hg.mozilla.org/mozilla-central/file/1dd81c324ac7/build/automation.py.in//l388\n // Make url-classifier updates so rare that they won't affect tests.\n 'urlclassifier.updateinterval': 172800,\n // Point the url-classifier to a nonexistent local URL for fast failures.\n 'browser.safebrowsing.provider.0.gethashURL':\n 'http://localhost/safebrowsing-dummy/gethash',\n 'browser.safebrowsing.provider.0.keyURL':\n 'http://localhost/safebrowsing-dummy/newkey',\n 'browser.safebrowsing.provider.0.updateURL':\n 'http://localhost/safebrowsing-dummy/update',\n\n // Disable self repair/SHIELD\n 'browser.selfsupport.url': 'https://localhost/selfrepair',\n // Disable Reader Mode UI tour\n 'browser.reader.detectedFirstArticle': true,\n\n // Set the policy firstURL to an empty string to prevent\n // the privacy info page to be opened on every \"web-ext run\".\n // (See #1114 for rationale)\n 'datareporting.policy.firstRunURL': '',\n};\n\nconst prefs = {\n common: prefsCommon,\n fennec: prefsFennec,\n firefox: prefsFirefox,\n};\n\n// Module exports\n\nexport type PreferencesGetterFn = (\n appName: PreferencesAppName\n) => FirefoxPreferences;\n\nexport function getPrefs(\n app: PreferencesAppName = 'firefox'\n): FirefoxPreferences {\n const appPrefs = prefs[app];\n if (!appPrefs) {\n throw new WebExtError(`Unsupported application: ${app}`);\n }\n return {\n ...prefsCommon,\n ...appPrefs,\n };\n}\n\nexport function coerceCLICustomPreference(\n cliPrefs: Array<string>\n): FirefoxPreferences {\n const customPrefs = {};\n\n for (const pref of cliPrefs) {\n const prefsAry = pref.split('=');\n\n if (prefsAry.length < 2) {\n throw new UsageError(\n `Incomplete custom preference: \"${pref}\". ` +\n 'Syntax expected: \"prefname=prefvalue\".'\n );\n }\n\n const key = prefsAry[0];\n let value = prefsAry.slice(1).join('=');\n\n if (/[^\\w{@}.-]/.test(key)) {\n throw new UsageError(`Invalid custom preference name: ${key}`);\n }\n\n if (value === `${parseInt(value)}`) {\n value = parseInt(value, 10);\n } else if (value === 'true' || value === 'false') {\n value = value === 'true';\n }\n\n if (nonOverridablePreferences.includes(key)) {\n log.warn(`'${key}' preference cannot be customized.`);\n continue;\n }\n customPrefs[`${key}`] = value;\n }\n\n return customPrefs;\n}\n"],"mappings":"AACA,SAASA,WAAW,EAAEC,UAAU,QAAQ,cAAc;AACtD,SAASC,YAAY,QAAQ,mBAAmB;AAEhD,MAAMC,GAAG,GAAGD,YAAY,CAACE,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;AAEzC,OAAO,MAAMC,yBAAyB,GAAG,CACvC,kCAAkC,EAClC,qCAAqC,EACrC,+BAA+B,CAChC;;AAED;;AAQA;;AAEA,MAAMC,WAA+B,GAAG;EACtC;EACA,iCAAiC,EAAE,IAAI;EAEvC;EACA;EACA;EACA,4CAA4C,EAAE,KAAK;EAEnD;EACA,kCAAkC,EAAE,IAAI;EACxC;EACA,qCAAqC,EAAE,KAAK;EAC5C;EACA,yCAAyC,EAAE,IAAI;EAE/C;EACA,4BAA4B,EAAE,KAAK;EAEnC;EACA,uCAAuC,EAAE,KAAK;EAC9C,2BAA2B,EAAE,KAAK;EAClC,8BAA8B,EAAE,KAAK;EAErC;EACA;EACA;EACA;EACA,0BAA0B,EAAE,CAAC;EAC7B;EACA,oCAAoC,EAAE,KAAK;EAC3C;EACA,gCAAgC,EAAE,KAAK;EACvC;EACA,8BAA8B,EAAE,EAAE;EAElC;EACA,oBAAoB,EAAE,KAAK;EAE3B;EACA,+BAA+B,EAAE,KAAK;EAEtC;EACA;EACA;EACA,6BAA6B,EAAE;AACjC,CAAC;;AAED;AACA,MAAMC,WAA+B,GAAG;EACtC,6BAA6B,EAAE,IAAI;EACnC,mCAAmC,EAAE,KAAK;EAC1C,6BAA6B,EAAE;AACjC,CAAC;;AAED;AACA,MAAMC,YAAgC,GAAG;EACvC,0BAA0B,EAAE,aAAa;EACzC,8BAA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I,CAACJ,GAAG,CAAC,EAAE;MAC1B,MAAM,IAAIxB,UAAU,CAAE,mCAAkCwB,GAAI,EAAC,CAAC;IAChE;IAEA,IAAIC,KAAK,KAAM,GAAEI,QAAQ,CAACJ,KAAK,CAAE,EAAC,EAAE;MAClCA,KAAK,GAAGI,QAAQ,CAACJ,KAAK,EAAE,EAAE,CAAC;IAC7B,CAAC,MAAM,IAAIA,KAAK,KAAK,MAAM,IAAIA,KAAK,KAAK,OAAO,EAAE;MAChDA,KAAK,GAAGA,KAAK,KAAK,MAAM;IAC1B;IAEA,IAAInB,yBAAyB,CAACwB,QAAQ,CAACN,GAAG,CAAC,EAAE;MAC3CtB,GAAG,CAAC6B,IAAI,CAAE,IAAGP,GAAI,oCAAmC,CAAC;MACrD;IACF;IACAL,WAAW,CAAE,GAAEK,GAAI,EAAC,CAAC,GAAGC,KAAK;EAC/B;EAEA,OAAON,WAAW;AACpB"}
1
+ {"version":3,"file":"preferences.js","names":["WebExtError","UsageError","createLogger","log","import","meta","url","nonOverridablePreferences","prefsCommon","prefsFennec","prefsFirefox","prefs","common","fennec","firefox","getPrefs","app","appPrefs","coerceCLICustomPreference","cliPrefs","customPrefs","pref","prefsAry","split","length","key","value","slice","join","test","parseInt","includes","warn"],"sources":["../../src/firefox/preferences.js"],"sourcesContent":["import { WebExtError, UsageError } from '../errors.js';\nimport { createLogger } from '../util/logger.js';\n\nconst log = createLogger(import.meta.url);\n\nexport const nonOverridablePreferences = [\n 'devtools.debugger.remote-enabled',\n 'devtools.debugger.prompt-connection',\n 'xpinstall.signatures.required',\n];\n\n// Preferences Maps\n\nconst prefsCommon = {\n // Allow debug output via dump to be printed to the system console\n 'browser.dom.window.dump.enabled': true,\n\n // From:\n // https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/internals/preferences.html#data-choices-notification\n // This is the data submission master kill switch. If disabled, no policy is shown or upload takes place, ever.\n 'datareporting.policy.dataSubmissionEnabled': false,\n\n // Allow remote connections to the debugger.\n 'devtools.debugger.remote-enabled': true,\n // Disable the prompt for allowing connections.\n 'devtools.debugger.prompt-connection': false,\n // Allow extensions to log messages on browser's console.\n 'devtools.browserconsole.contentMessages': true,\n\n // Turn off platform logging because it is a lot of info.\n 'extensions.logging.enabled': false,\n\n // Disable extension updates and notifications.\n 'extensions.checkCompatibility.nightly': false,\n 'extensions.update.enabled': false,\n 'extensions.update.notifyUser': false,\n\n // From:\n // http://hg.mozilla.org/mozilla-central/file/1dd81c324ac7/build/automation.py.in//l372\n // Only load extensions from the application and user profile.\n // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION\n 'extensions.enabledScopes': 5,\n // Disable metadata caching for installed add-ons by default.\n 'extensions.getAddons.cache.enabled': false,\n // Disable intalling any distribution add-ons.\n 'extensions.installDistroAddons': false,\n // Allow installing extensions dropped into the profile folder.\n 'extensions.autoDisableScopes': 10,\n\n // Disable app update.\n 'app.update.enabled': false,\n\n // Allow unsigned add-ons.\n 'xpinstall.signatures.required': false,\n\n // browser.link.open_newwindow is changed from 3 to 2 in:\n // https://github.com/saadtazi/firefox-profile-js/blob/cafc793d940a779d280103ae17d02a92de862efc/lib/firefox_profile.js#L32\n // Restore original value to avoid https://github.com/mozilla/web-ext/issues/1592\n 'browser.link.open_newwindow': 3,\n};\n\n// Prefs specific to Firefox for Android.\nconst prefsFennec = {\n 'browser.console.showInPanel': true,\n 'browser.firstrun.show.uidiscovery': false,\n 'devtools.remote.usb.enabled': true,\n};\n\n// Prefs specific to Firefox for desktop.\nconst prefsFirefox = {\n 'browser.startup.homepage': 'about:blank',\n 'startup.homepage_welcome_url': 'about:blank',\n 'startup.homepage_welcome_url.additional': '',\n 'devtools.errorconsole.enabled': true,\n 'devtools.chrome.enabled': true,\n\n // From:\n // http://hg.mozilla.org/mozilla-central/file/1dd81c324ac7/build/automation.py.in//l388\n // Make url-classifier updates so rare that they won't affect tests.\n 'urlclassifier.updateinterval': 172800,\n // Point the url-classifier to a nonexistent local URL for fast failures.\n 'browser.safebrowsing.provider.0.gethashURL':\n 'http://localhost/safebrowsing-dummy/gethash',\n 'browser.safebrowsing.provider.0.keyURL':\n 'http://localhost/safebrowsing-dummy/newkey',\n 'browser.safebrowsing.provider.0.updateURL':\n 'http://localhost/safebrowsing-dummy/update',\n\n // Disable self repair/SHIELD\n 'browser.selfsupport.url': 'https://localhost/selfrepair',\n // Disable Reader Mode UI tour\n 'browser.reader.detectedFirstArticle': true,\n\n // Set the policy firstURL to an empty string to prevent\n // the privacy info page to be opened on every \"web-ext run\".\n // (See #1114 for rationale)\n 'datareporting.policy.firstRunURL': '',\n};\n\nconst prefs = {\n common: prefsCommon,\n fennec: prefsFennec,\n firefox: prefsFirefox,\n};\n\n// Module exports\n\nexport function getPrefs(app = 'firefox') {\n const appPrefs = prefs[app];\n if (!appPrefs) {\n throw new WebExtError(`Unsupported application: ${app}`);\n }\n return {\n ...prefsCommon,\n ...appPrefs,\n };\n}\n\nexport function coerceCLICustomPreference(cliPrefs) {\n const customPrefs = {};\n\n for (const pref of cliPrefs) {\n const prefsAry = pref.split('=');\n\n if (prefsAry.length < 2) {\n throw new UsageError(\n `Incomplete custom preference: \"${pref}\". ` +\n 'Syntax expected: \"prefname=prefvalue\".',\n );\n }\n\n const key = prefsAry[0];\n let value = prefsAry.slice(1).join('=');\n\n if (/[^\\w{@}.-]/.test(key)) {\n throw new UsageError(`Invalid custom preference name: ${key}`);\n }\n\n if (value === `${parseInt(value)}`) {\n value = parseInt(value, 10);\n } else if (value === 'true' || value === 'false') {\n value = value === 'true';\n }\n\n if (nonOverridablePreferences.includes(key)) {\n log.warn(`'${key}' preference cannot be customized.`);\n continue;\n }\n customPrefs[`${key}`] = value;\n }\n\n return customPrefs;\n}\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,UAAU,QAAQ,cAAc;AACtD,SAASC,YAAY,QAAQ,mBAAmB;AAEhD,MAAMC,GAAG,GAAGD,YAAY,CAACE,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;AAEzC,O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AC,EAAE;MAC3CtB,GAAG,CAAC6B,IAAI,CAAC,IAAIP,GAAG,oCAAoC,CAAC;MACrD;IACF;IACAL,WAAW,CAAC,GAAGK,GAAG,EAAE,CAAC,GAAGC,KAAK;EAC/B;EAEA,OAAON,WAAW;AACpB","ignoreList":[]}
@@ -50,6 +50,14 @@ export function connectToFirefox(port) {
50
50
  return client.connect(port).then(() => client);
51
51
  }
52
52
  export default class FirefoxRDPClient extends EventEmitter {
53
+ _incoming;
54
+ _pending;
55
+ _active;
56
+ _rdpConnection;
57
+ _onData;
58
+ _onError;
59
+ _onEnd;
60
+ _onTimeout;
53
61
  constructor() {
54
62
  super();
55
63
  this._incoming = Buffer.alloc(0);
@@ -187,9 +195,9 @@ export default class FirefoxRDPClient extends EventEmitter {
187
195
  const deferred = this._active.get(rdpData.from);
188
196
  this._active.delete(rdpData.from);
189
197
  if (rdpData.error) {
190
- deferred === null || deferred === void 0 ? void 0 : deferred.reject(rdpData);
198
+ deferred === null || deferred === void 0 || deferred.reject(rdpData);
191
199
  } else {
192
- deferred === null || deferred === void 0 ? void 0 : deferred.resolve(rdpData);
200
+ deferred === null || deferred === void 0 || deferred.resolve(rdpData);
193
201
  }
194
202
  this._flushPendingRequests();
195
203
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"rdp-client.js","names":["net","EventEmitter","domain","DEFAULT_PORT","DEFAULT_HOST","UNSOLICITED_EVENTS","Set","parseRDPMessage","data","str","toString","sepIdx","indexOf","byteLen","parseInt","slice","isNaN","error","Error","fatal","length","msg","rdpMessage","JSON","parse","connectToFirefox","port","client","FirefoxRDPClient","connect","then","constructor","_incoming","Buffer","alloc","_pending","_active","Map","_onData","args","onData","_onError","onError","_onEnd","onEnd","_onTimeout","onTimeout","Promise","resolve","reject","d","create","once","run","conn","createConnection","host","_rdpConnection","on","_expectReply","disconnect","off","end","_rejectAllRequests","activeDeferred","values","clear","deferred","request","requestProps","to","type","push","_flushPendingRequests","filter","has","stringify","from","write","err","targetActor","set","_handleMessage","rdpData","emit","get","delete","_readMessage","String","concat"],"sources":["../../src/firefox/rdp-client.js"],"sourcesContent":["/* @flow */\nimport net from 'net';\nimport EventEmitter from 'events';\nimport domain from 'domain';\n\nexport type RDPRequest = {\n to: string,\n type: string,\n};\n\nexport type RDPResult = {\n from: string,\n type: string,\n};\n\nexport type Deferred = {|\n resolve: Function,\n reject: Function,\n|};\n\ntype ParseResult = {|\n data: Buffer,\n rdpMessage?: Object,\n error?: Error,\n fatal?: boolean,\n|};\n\nexport const DEFAULT_PORT = 6000;\nexport const DEFAULT_HOST = '127.0.0.1';\n\nconst UNSOLICITED_EVENTS = new Set([\n 'tabNavigated',\n 'styleApplied',\n 'propertyChange',\n 'networkEventUpdate',\n 'networkEvent',\n 'propertyChange',\n 'newMutations',\n 'frameUpdate',\n 'tabListChanged',\n]);\n\n// Parse RDP packets: BYTE_LENGTH + ':' + DATA.\nexport function parseRDPMessage(data: Buffer): ParseResult {\n const str = data.toString();\n const sepIdx = str.indexOf(':');\n if (sepIdx < 1) {\n return { data };\n }\n\n const byteLen = parseInt(str.slice(0, sepIdx));\n if (isNaN(byteLen)) {\n const error = new Error('Error parsing RDP message length');\n return { data, error, fatal: true };\n }\n\n if (data.length - (sepIdx + 1) < byteLen) {\n // Can't parse yet, will retry once more data has been received.\n return { data };\n }\n\n data = data.slice(sepIdx + 1);\n const msg = data.slice(0, byteLen);\n data = data.slice(byteLen);\n\n try {\n return { data, rdpMessage: JSON.parse(msg.toString()) };\n } catch (error) {\n return { data, error, fatal: false };\n }\n}\n\nexport function connectToFirefox(port: number): Promise<FirefoxRDPClient> {\n const client = new FirefoxRDPClient();\n return client.connect(port).then(() => client);\n}\n\nexport default class FirefoxRDPClient extends EventEmitter {\n _incoming: Buffer;\n _pending: Array<{| request: RDPRequest, deferred: Deferred |}>;\n _active: Map<string, Deferred>;\n _rdpConnection: net.Socket;\n _onData: Function;\n _onError: Function;\n _onEnd: Function;\n _onTimeout: Function;\n\n constructor() {\n super();\n this._incoming = Buffer.alloc(0);\n this._pending = [];\n this._active = new Map();\n\n this._onData = (...args) => this.onData(...args);\n this._onError = (...args) => this.onError(...args);\n this._onEnd = (...args) => this.onEnd(...args);\n this._onTimeout = (...args) => this.onTimeout(...args);\n }\n\n connect(port: number): Promise<void> {\n return new Promise((resolve, reject) => {\n // Create a domain to wrap the errors that may be triggered\n // by creating the client connection (e.g. ECONNREFUSED)\n // so that we can reject the promise returned instead of\n // exiting the entire process.\n const d = domain.create();\n d.once('error', reject);\n d.run(() => {\n const conn = net.createConnection({\n port,\n host: DEFAULT_HOST,\n });\n\n this._rdpConnection = conn;\n conn.on('data', this._onData);\n conn.on('error', this._onError);\n conn.on('end', this._onEnd);\n conn.on('timeout', this._onTimeout);\n\n // Resolve once the expected initial root message\n // has been received.\n this._expectReply('root', { resolve, reject });\n });\n });\n }\n\n disconnect(): void {\n if (!this._rdpConnection) {\n return;\n }\n\n const conn = this._rdpConnection;\n conn.off('data', this._onData);\n conn.off('error', this._onError);\n conn.off('end', this._onEnd);\n conn.off('timeout', this._onTimeout);\n conn.end();\n\n this._rejectAllRequests(new Error('RDP connection closed'));\n }\n\n _rejectAllRequests(error: Error) {\n for (const activeDeferred of this._active.values()) {\n activeDeferred.reject(error);\n }\n this._active.clear();\n\n for (const { deferred } of this._pending) {\n deferred.reject(error);\n }\n this._pending = [];\n }\n\n async request(requestProps: string | RDPRequest): Promise<RDPResult> {\n let request: RDPRequest;\n\n if (typeof requestProps === 'string') {\n request = { to: 'root', type: requestProps };\n } else {\n request = requestProps;\n }\n\n if (request.to == null) {\n throw new Error(\n `Unexpected RDP request without target actor: ${request.type}`\n );\n }\n\n return new Promise((resolve, reject) => {\n const deferred = { resolve, reject };\n this._pending.push({ request, deferred });\n this._flushPendingRequests();\n });\n }\n\n _flushPendingRequests(): void {\n this._pending = this._pending.filter(({ request, deferred }) => {\n if (this._active.has(request.to)) {\n // Keep in the pending requests until there are no requests\n // active on the target RDP actor.\n return true;\n }\n\n const conn = this._rdpConnection;\n if (!conn) {\n throw new Error('RDP connection closed');\n }\n\n try {\n let str = JSON.stringify(request);\n str = `${Buffer.from(str).length}:${str}`;\n conn.write(str);\n this._expectReply(request.to, deferred);\n } catch (err) {\n deferred.reject(err);\n }\n\n // Remove the pending request from the queue.\n return false;\n });\n }\n\n _expectReply(targetActor: string, deferred: Deferred): void {\n if (this._active.has(targetActor)) {\n throw new Error(`${targetActor} does already have an active request`);\n }\n\n this._active.set(targetActor, deferred);\n }\n\n _handleMessage(rdpData: Object): void {\n if (rdpData.from == null) {\n if (rdpData.error) {\n this.emit('rdp-error', rdpData);\n return;\n }\n\n this.emit(\n 'error',\n new Error(\n `Received an RDP message without a sender actor: ${JSON.stringify(\n rdpData\n )}`\n )\n );\n return;\n }\n\n if (UNSOLICITED_EVENTS.has(rdpData.type)) {\n this.emit('unsolicited-event', rdpData);\n return;\n }\n\n if (this._active.has(rdpData.from)) {\n const deferred = this._active.get(rdpData.from);\n this._active.delete(rdpData.from);\n if (rdpData.error) {\n deferred?.reject(rdpData);\n } else {\n deferred?.resolve(rdpData);\n }\n this._flushPendingRequests();\n return;\n }\n\n this.emit(\n 'error',\n new Error(`Unexpected RDP message received: ${JSON.stringify(rdpData)}`)\n );\n }\n\n _readMessage(): boolean {\n const { data, rdpMessage, error, fatal } = parseRDPMessage(this._incoming);\n\n this._incoming = data;\n\n if (error) {\n this.emit(\n 'error',\n new Error(`Error parsing RDP packet: ${String(error)}`)\n );\n // Disconnect automatically on a fatal error.\n if (fatal) {\n this.disconnect();\n }\n // Caller can parse the next message if the error wasn't fatal\n // (e.g. the RDP packet that couldn't be parsed has been already\n // removed from the incoming data buffer).\n return !fatal;\n }\n\n if (!rdpMessage) {\n // Caller will need to wait more data to parse the next message.\n return false;\n }\n\n this._handleMessage(rdpMessage);\n // Caller can try to parse the next message from the remining data.\n return true;\n }\n\n onData(data: Buffer) {\n this._incoming = Buffer.concat([this._incoming, data]);\n while (this._readMessage()) {\n // Keep parsing and handling messages until readMessage\n // returns false.\n }\n }\n\n onError(error: Error) {\n this.emit('error', error);\n }\n\n onEnd() {\n this.emit('end');\n }\n\n onTimeout() {\n this.emit('timeout');\n }\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAAM,KAAK;AACrB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,MAAM,MAAM,QAAQ;AAwB3B,OAAO,MAAMC,YAAY,GAAG,IAAI;AAChC,OAAO,MAAMC,YAAY,GAAG,WAAW;AAEvC,MAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CACjC,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,CACjB,CAAC;;AAEF;AACA,OAAO,SAASC,eAAeA,CAACC,IAAY,EAAe;EACzD,MAAMC,GAAG,GAAGD,IAAI,CAACE,QAAQ,CAAC,CAAC;EAC3B,MAAMC,MAAM,GAAGF,GAAG,CAACG,OAAO,CAAC,GAAG,CAAC;EAC/B,IAAID,MAAM,GAAG,CAAC,EAAE;IACd,OAAO;MAAEH;IAAK,CAAC;EACjB;EAEA,MAAMK,OAAO,GAAGC,QAAQ,CAACL,GAAG,CAACM,KAAK,CAAC,CAAC,EAAEJ,MAAM,CAAC,CAAC;EAC9C,IAAIK,KAAK,CAACH,OAAO,CAAC,EAAE;IAClB,MAAMI,KAAK,GAAG,IAAIC,KAAK,CAAC,kCAAkC,CAAC;IAC3D,OAAO;MAAEV,IAAI;MAAES,KAAK;MAAEE,KAAK,EAAE;IAAK,CAAC;EACrC;EAEA,IAAIX,IAAI,CAACY,MAAM,IAAIT,MAAM,GAAG,CAAC,CAAC,GAAGE,OAAO,EAAE;IACxC;IACA,OAAO;MAAEL;IAAK,CAAC;EACjB;EAEAA,IAAI,GAAGA,IAAI,CAACO,KAAK,CAACJ,MAAM,GAAG,CAAC,CAAC;EAC7B,MAAMU,GAAG,GAAGb,IAAI,CAACO,KAAK,CAAC,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,OAAO,CAACzC,KAAK;IACf;IAEA,IAAI,CAACG,UAAU,EAAE;MACf;MACA,OAAO,KAAK;IACd;IAEA,IAAI,CAAC4D,cAAc,CAAC5D,UAAU,CAAC;IAC/B;IACA,OAAO,IAAI;EACb;EAEAkB,MAAMA,CAAChC,IAAY,EAAE;IACnB,IAAI,CAACwB,SAAS,GAAGC,MAAM,CAACwD,MAAM,CAAC,CAAC,IAAI,CAACzD,SAAS,EAAExB,IAAI,CAAC,CAAC;IACtD,OAAO,IAAI,CAAC+E,YAAY,CAAC,CAAC,EAAE;MAC1B;MACA;IAAA;EAEJ;EAEA7C,OAAOA,CAACzB,KAAY,EAAE;IACpB,IAAI,CAACmE,IAAI,CAAC,OAAO,EAAEnE,KAAK,CAAC;EAC3B;EAEA2B,KAAKA,CAAA,EAAG;IACN,IAAI,CAACwC,IAAI,CAAC,KAAK,CAAC;EAClB;EAEAtC,SAASA,CAAA,EAAG;IACV,IAAI,CAACsC,IAAI,CAAC,SAAS,CAAC;EACtB;AACF"}
1
+ {"version":3,"file":"rdp-client.js","names":["net","EventEmitter","domain","DEFAULT_PORT","DEFAULT_HOST","UNSOLICITED_EVENTS","Set","parseRDPMessage","data","str","toString","sepIdx","indexOf","byteLen","parseInt","slice","isNaN","error","Error","fatal","length","msg","rdpMessage","JSON","parse","connectToFirefox","port","client","FirefoxRDPClient","connect","then","_incoming","_pending","_active","_rdpConnection","_onData","_onError","_onEnd","_onTimeout","constructor","Buffer","alloc","Map","args","onData","onError","onEnd","onTimeout","Promise","resolve","reject","d","create","once","run","conn","createConnection","host","on","_expectReply","disconnect","off","end","_rejectAllRequests","activeDeferred","values","clear","deferred","request","requestProps","to","type","push","_flushPendingRequests","filter","has","stringify","from","write","err","targetActor","set","_handleMessage","rdpData","emit","get","delete","_readMessage","String","concat"],"sources":["../../src/firefox/rdp-client.js"],"sourcesContent":["import net from 'net';\nimport EventEmitter from 'events';\nimport domain from 'domain';\n\nexport const DEFAULT_PORT = 6000;\nexport const DEFAULT_HOST = '127.0.0.1';\n\nconst UNSOLICITED_EVENTS = new Set([\n 'tabNavigated',\n 'styleApplied',\n 'propertyChange',\n 'networkEventUpdate',\n 'networkEvent',\n 'propertyChange',\n 'newMutations',\n 'frameUpdate',\n 'tabListChanged',\n]);\n\n// Parse RDP packets: BYTE_LENGTH + ':' + DATA.\nexport function parseRDPMessage(data) {\n const str = data.toString();\n const sepIdx = str.indexOf(':');\n if (sepIdx < 1) {\n return { data };\n }\n\n const byteLen = parseInt(str.slice(0, sepIdx));\n if (isNaN(byteLen)) {\n const error = new Error('Error parsing RDP message length');\n return { data, error, fatal: true };\n }\n\n if (data.length - (sepIdx + 1) < byteLen) {\n // Can't parse yet, will retry once more data has been received.\n return { data };\n }\n\n data = data.slice(sepIdx + 1);\n const msg = data.slice(0, byteLen);\n data = data.slice(byteLen);\n\n try {\n return { data, rdpMessage: JSON.parse(msg.toString()) };\n } catch (error) {\n return { data, error, fatal: false };\n }\n}\n\nexport function connectToFirefox(port) {\n const client = new FirefoxRDPClient();\n return client.connect(port).then(() => client);\n}\n\nexport default class FirefoxRDPClient extends EventEmitter {\n _incoming;\n _pending;\n _active;\n _rdpConnection;\n _onData;\n _onError;\n _onEnd;\n _onTimeout;\n\n constructor() {\n super();\n this._incoming = Buffer.alloc(0);\n this._pending = [];\n this._active = new Map();\n\n this._onData = (...args) => this.onData(...args);\n this._onError = (...args) => this.onError(...args);\n this._onEnd = (...args) => this.onEnd(...args);\n this._onTimeout = (...args) => this.onTimeout(...args);\n }\n\n connect(port) {\n return new Promise((resolve, reject) => {\n // Create a domain to wrap the errors that may be triggered\n // by creating the client connection (e.g. ECONNREFUSED)\n // so that we can reject the promise returned instead of\n // exiting the entire process.\n const d = domain.create();\n d.once('error', reject);\n d.run(() => {\n const conn = net.createConnection({\n port,\n host: DEFAULT_HOST,\n });\n\n this._rdpConnection = conn;\n conn.on('data', this._onData);\n conn.on('error', this._onError);\n conn.on('end', this._onEnd);\n conn.on('timeout', this._onTimeout);\n\n // Resolve once the expected initial root message\n // has been received.\n this._expectReply('root', { resolve, reject });\n });\n });\n }\n\n disconnect() {\n if (!this._rdpConnection) {\n return;\n }\n\n const conn = this._rdpConnection;\n conn.off('data', this._onData);\n conn.off('error', this._onError);\n conn.off('end', this._onEnd);\n conn.off('timeout', this._onTimeout);\n conn.end();\n\n this._rejectAllRequests(new Error('RDP connection closed'));\n }\n\n _rejectAllRequests(error) {\n for (const activeDeferred of this._active.values()) {\n activeDeferred.reject(error);\n }\n this._active.clear();\n\n for (const { deferred } of this._pending) {\n deferred.reject(error);\n }\n this._pending = [];\n }\n\n async request(requestProps) {\n let request;\n\n if (typeof requestProps === 'string') {\n request = { to: 'root', type: requestProps };\n } else {\n request = requestProps;\n }\n\n if (request.to == null) {\n throw new Error(\n `Unexpected RDP request without target actor: ${request.type}`,\n );\n }\n\n return new Promise((resolve, reject) => {\n const deferred = { resolve, reject };\n this._pending.push({ request, deferred });\n this._flushPendingRequests();\n });\n }\n\n _flushPendingRequests() {\n this._pending = this._pending.filter(({ request, deferred }) => {\n if (this._active.has(request.to)) {\n // Keep in the pending requests until there are no requests\n // active on the target RDP actor.\n return true;\n }\n\n const conn = this._rdpConnection;\n if (!conn) {\n throw new Error('RDP connection closed');\n }\n\n try {\n let str = JSON.stringify(request);\n str = `${Buffer.from(str).length}:${str}`;\n conn.write(str);\n this._expectReply(request.to, deferred);\n } catch (err) {\n deferred.reject(err);\n }\n\n // Remove the pending request from the queue.\n return false;\n });\n }\n\n _expectReply(targetActor, deferred) {\n if (this._active.has(targetActor)) {\n throw new Error(`${targetActor} does already have an active request`);\n }\n\n this._active.set(targetActor, deferred);\n }\n\n _handleMessage(rdpData) {\n if (rdpData.from == null) {\n if (rdpData.error) {\n this.emit('rdp-error', rdpData);\n return;\n }\n\n this.emit(\n 'error',\n new Error(\n `Received an RDP message without a sender actor: ${JSON.stringify(\n rdpData,\n )}`,\n ),\n );\n return;\n }\n\n if (UNSOLICITED_EVENTS.has(rdpData.type)) {\n this.emit('unsolicited-event', rdpData);\n return;\n }\n\n if (this._active.has(rdpData.from)) {\n const deferred = this._active.get(rdpData.from);\n this._active.delete(rdpData.from);\n if (rdpData.error) {\n deferred?.reject(rdpData);\n } else {\n deferred?.resolve(rdpData);\n }\n this._flushPendingRequests();\n return;\n }\n\n this.emit(\n 'error',\n new Error(`Unexpected RDP message received: ${JSON.stringify(rdpData)}`),\n );\n }\n\n _readMessage() {\n const { data, rdpMessage, error, fatal } = parseRDPMessage(this._incoming);\n\n this._incoming = data;\n\n if (error) {\n this.emit(\n 'error',\n new Error(`Error parsing RDP packet: ${String(error)}`),\n );\n // Disconnect automatically on a fatal error.\n if (fatal) {\n this.disconnect();\n }\n // Caller can parse the next message if the error wasn't fatal\n // (e.g. the RDP packet that couldn't be parsed has been already\n // removed from the incoming data buffer).\n return !fatal;\n }\n\n if (!rdpMessage) {\n // Caller will need to wait more data to parse the next message.\n return false;\n }\n\n this._handleMessage(rdpMessage);\n // Caller can try to parse the next message from the remining data.\n return true;\n }\n\n onData(data) {\n this._incoming = Buffer.concat([this._incoming, data]);\n while (this._readMessage()) {\n // Keep parsing and handling messages until readMessage\n // returns false.\n }\n }\n\n onError(error) {\n this.emit('error', error);\n }\n\n onEnd() {\n this.emit('end');\n }\n\n onTimeout() {\n this.emit('timeout');\n }\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,MAAM,MAAM,QAAQ;AAE3B,OAAO,MAAMC,YAAY,GAAG,IAAI;AAChC,OAAO,MAAMC,YAAY,GAAG,WAAW;AAEvC,MAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CACjC,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,CACjB,CAAC;;AAEF;AACA,OAAO,SAASC,eAAeA,CAACC,IAAI,EAAE;EACpC,M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IAAI,CAAC,OAAO,EAAEnE,KAAK,CAAC;EAC3B;EAEA6B,KAAKA,CAAA,EAAG;IACN,IAAI,CAACsC,IAAI,CAAC,KAAK,CAAC;EAClB;EAEArC,SAASA,CAAA,EAAG;IACV,IAAI,CAACqC,IAAI,CAAC,SAAS,CAAC;EACtB;AACF","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import net from 'net';
2
- import FirefoxRDPClient, { connectToFirefox as defaultFirefoxConnector } from './rdp-client.js';
2
+ import { connectToFirefox as defaultFirefoxConnector } from './rdp-client.js';
3
3
  import { createLogger } from '../util/logger.js';
4
4
  import { isErrorWithCode, RemoteTempInstallNotSupported, UsageError, WebExtError } from '../errors.js';
5
5
  const log = createLogger(import.meta.url);
@@ -14,6 +14,8 @@ function requestErrorToMessage(err) {
14
14
  return `${err.error}: ${err.message}`;
15
15
  }
16
16
  export class RemoteFirefox {
17
+ client;
18
+ checkedForAddonReloading;
17
19
  constructor(client) {
18
20
  this.client = client;
19
21
  this.checkedForAddonReloading = false;
@@ -182,7 +184,6 @@ export async function connectWithMaxRetries(
182
184
  export function findFreeTcpPort() {
183
185
  return new Promise(resolve => {
184
186
  const srv = net.createServer();
185
- // $FlowFixMe: signature for listen() is missing - see https://github.com/facebook/flow/pull/8290
186
187
  srv.listen(0, '127.0.0.1', () => {
187
188
  const freeTcpPort = srv.address().port;
188
189
  srv.close(() => resolve(freeTcpPort));
@@ -1 +1 @@
1
- {"version":3,"file":"remote.js","names":["net","FirefoxRDPClient","connectToFirefox","defaultFirefoxConnector","createLogger","isErrorWithCode","RemoteTempInstallNotSupported","UsageError","WebExtError","log","import","meta","url","requestErrorToMessage","err","Error","String","error","message","RemoteFirefox","constructor","client","checkedForAddonReloading","on","debug","info","JSON","stringify","rdpError","disconnect","addonRequest","addon","request","response","to","actor","type","getAddonsActor","addonsActor","Promise","reject","installTemporaryAddon","addonPath","openDevTools","getInstalledAddon","addonId","addons","id","map","a","checkForAddonReloading","requestTypes","indexOf","supportedRequestTypes","reloadAddon","process","stdout","write","Date","toTimeString","connect","port","connectWithMaxRetries","maxRetries","retryInterval","establishConnection","lastError","retries","resolve","setTimeout","stack","findFreeTcpPort","srv","createServer","listen","freeTcpPort","address","close"],"sources":["../../src/firefox/remote.js"],"sourcesContent":["/* @flow */\nimport net from 'net';\n\nimport FirefoxRDPClient, {\n connectToFirefox as defaultFirefoxConnector,\n} from './rdp-client.js';\nimport { createLogger } from '../util/logger.js';\nimport {\n isErrorWithCode,\n RemoteTempInstallNotSupported,\n UsageError,\n WebExtError,\n} from '../errors.js';\n\nconst log = createLogger(import.meta.url);\n\nexport type FirefoxConnectorFn = (port: number) => Promise<FirefoxRDPClient>;\n\nexport type FirefoxRDPAddonActor = {|\n id: string,\n actor: string,\n|};\n\nexport type FirefoxRDPResponseError = {|\n error: string,\n message: string,\n|};\n\nexport type FirefoxRDPResponseAddon = {|\n addon: FirefoxRDPAddonActor,\n|};\n\nexport type FirefoxRDPResponseRequestTypes = {|\n requestTypes: Array<string>,\n|};\n\n// NOTE: this type aliases Object to catch any other possible response.\nexport type FirefoxRDPResponseAny = Object;\n\nexport type FirefoxRDPResponseMaybe =\n | FirefoxRDPResponseRequestTypes\n | FirefoxRDPResponseAny;\n\n// Convert a request rejection to a message string.\nfunction requestErrorToMessage(err: Error | FirefoxRDPResponseError) {\n if (err instanceof Error) {\n return String(err);\n }\n return `${err.error}: ${err.message}`;\n}\n\nexport class RemoteFirefox {\n client: Object;\n checkedForAddonReloading: boolean;\n\n constructor(client: FirefoxRDPClient) {\n this.client = client;\n this.checkedForAddonReloading = false;\n\n client.on('disconnect', () => {\n log.debug('Received \"disconnect\" from Firefox client');\n });\n client.on('end', () => {\n log.debug('Received \"end\" from Firefox client');\n });\n client.on('unsolicited-event', (info) => {\n log.debug(`Received message from client: ${JSON.stringify(info)}`);\n });\n client.on('rdp-error', (rdpError) => {\n log.debug(`Received error from client: ${JSON.stringify(rdpError)}`);\n });\n client.on('error', (error) => {\n log.debug(`Received error from client: ${String(error)}`);\n });\n }\n\n disconnect() {\n this.client.disconnect();\n }\n\n async addonRequest(\n addon: FirefoxRDPAddonActor,\n request: string\n ): Promise<FirefoxRDPResponseMaybe> {\n try {\n const response = await this.client.request({\n to: addon.actor,\n type: request,\n });\n return response;\n } catch (err) {\n log.debug(`Client responded to '${request}' request with error:`, err);\n const message = requestErrorToMessage(err);\n throw new WebExtError(`Remote Firefox: addonRequest() error: ${message}`);\n }\n }\n\n async getAddonsActor(): Promise<string> {\n try {\n // getRoot should work since Firefox 55 (bug 1352157).\n const response = await this.client.request('getRoot');\n if (response.addonsActor == null) {\n return Promise.reject(\n new RemoteTempInstallNotSupported(\n 'This version of Firefox does not provide an add-ons actor for ' +\n 'remote installation.'\n )\n );\n }\n return response.addonsActor;\n } catch (err) {\n // Fallback to listTabs otherwise, Firefox 49 - 77 (bug 1618691).\n log.debug('Falling back to listTabs because getRoot failed', err);\n }\n\n try {\n const response = await this.client.request('listTabs');\n // addonsActor was added to listTabs in Firefox 49 (bug 1273183).\n if (response.addonsActor == null) {\n log.debug(\n 'listTabs returned a falsey addonsActor: ' +\n `${JSON.stringify(response)}`\n );\n return Promise.reject(\n new RemoteTempInstallNotSupported(\n 'This is an older version of Firefox that does not provide an ' +\n 'add-ons actor for remote installation. Try Firefox 49 or ' +\n 'higher.'\n )\n );\n }\n return response.addonsActor;\n } catch (err) {\n log.debug('listTabs error', err);\n const message = requestErrorToMessage(err);\n throw new WebExtError(`Remote Firefox: listTabs() error: ${message}`);\n }\n }\n\n async installTemporaryAddon(\n addonPath: string,\n openDevTools?: boolean\n ): Promise<FirefoxRDPResponseAddon> {\n const addonsActor = await this.getAddonsActor();\n\n try {\n const response = await this.client.request({\n to: addonsActor,\n type: 'installTemporaryAddon',\n addonPath,\n openDevTools,\n });\n log.debug(`installTemporaryAddon: ${JSON.stringify(response)}`);\n log.info(`Installed ${addonPath} as a temporary add-on`);\n return response;\n } catch (err) {\n const message = requestErrorToMessage(err);\n throw new WebExtError(`installTemporaryAddon: Error: ${message}`);\n }\n }\n\n async getInstalledAddon(addonId: string): Promise<FirefoxRDPAddonActor> {\n try {\n const response = await this.client.request('listAddons');\n for (const addon of response.addons) {\n if (addon.id === addonId) {\n return addon;\n }\n }\n log.debug(\n `Remote Firefox has these addons: ${response.addons.map((a) => a.id)}`\n );\n return Promise.reject(\n new WebExtError(\n 'The remote Firefox does not have your extension installed'\n )\n );\n } catch (err) {\n const message = requestErrorToMessage(err);\n throw new WebExtError(`Remote Firefox: listAddons() error: ${message}`);\n }\n }\n\n async checkForAddonReloading(\n addon: FirefoxRDPAddonActor\n ): Promise<FirefoxRDPAddonActor> {\n if (this.checkedForAddonReloading) {\n // We only need to check once if reload() is supported.\n return addon;\n } else {\n const response = await this.addonRequest(addon, 'requestTypes');\n\n if (response.requestTypes.indexOf('reload') === -1) {\n const supportedRequestTypes = JSON.stringify(response.requestTypes);\n log.debug(`Remote Firefox only supports: ${supportedRequestTypes}`);\n throw new UsageError(\n 'This Firefox version does not support add-on reloading. ' +\n 'Re-run with --no-reload'\n );\n } else {\n this.checkedForAddonReloading = true;\n return addon;\n }\n }\n }\n\n async reloadAddon(addonId: string): Promise<void> {\n const addon = await this.getInstalledAddon(addonId);\n await this.checkForAddonReloading(addon);\n await this.addonRequest(addon, 'reload');\n process.stdout.write(\n `\\rLast extension reload: ${new Date().toTimeString()}`\n );\n log.debug('\\n');\n }\n}\n\n// Connect types and implementation\n\nexport type ConnectOptions = {\n connectToFirefox: FirefoxConnectorFn,\n};\n\nexport async function connect(\n port: number,\n { connectToFirefox = defaultFirefoxConnector }: ConnectOptions = {}\n): Promise<RemoteFirefox> {\n log.debug(`Connecting to Firefox on port ${port}`);\n const client = await connectToFirefox(port);\n log.debug(`Connected to the remote Firefox debugger on port ${port}`);\n return new RemoteFirefox(client);\n}\n\n// ConnectWithMaxRetries types and implementation\n\nexport type ConnectWithMaxRetriesParams = {|\n maxRetries?: number,\n retryInterval?: number,\n port: number,\n|};\n\nexport type ConnectWithMaxRetriesDeps = {\n connectToFirefox: typeof connect,\n};\n\nexport async function connectWithMaxRetries(\n // A max of 250 will try connecting for 30 seconds.\n { maxRetries = 250, retryInterval = 120, port }: ConnectWithMaxRetriesParams,\n { connectToFirefox = connect }: ConnectWithMaxRetriesDeps = {}\n): Promise<RemoteFirefox> {\n async function establishConnection() {\n var lastError;\n\n for (let retries = 0; retries <= maxRetries; retries++) {\n try {\n return await connectToFirefox(port);\n } catch (error) {\n if (isErrorWithCode('ECONNREFUSED', error)) {\n // Wait for `retryInterval` ms.\n await new Promise((resolve) => {\n setTimeout(resolve, retryInterval);\n });\n\n lastError = error;\n log.debug(\n `Retrying Firefox (${retries}); connection error: ${error}`\n );\n } else {\n log.error(error.stack);\n throw error;\n }\n }\n }\n\n log.debug('Connect to Firefox debugger: too many retries');\n throw lastError;\n }\n\n log.debug('Connecting to the remote Firefox debugger');\n return establishConnection();\n}\n\nexport function findFreeTcpPort(): Promise<number> {\n return new Promise((resolve) => {\n const srv = net.createServer();\n // $FlowFixMe: signature for listen() is missing - see https://github.com/facebook/flow/pull/8290\n srv.listen(0, '127.0.0.1', () => {\n const freeTcpPort = srv.address().port;\n srv.close(() => resolve(freeTcpPort));\n });\n });\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAAM,KAAK;AAErB,OAAOC,gBAAgB,IACrBC,gBAAgB,IAAIC,uBAAuB,QACtC,iBAAiB;AACxB,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SACEC,eAAe,EACfC,6BAA6B,EAC7BC,UAAU,EACVC,WAAW,QACN,cAAc;AAErB,MAAMC,GAAG,GAAGL,YAAY,CAACM,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;;AAsBzC;;AAOA;AACA,SAASC,qBAAqBA,CAACC,GAAoC,EAAE;EACnE,IAAIA,GAAG,YAAYC,KAAK,EAAE;IACxB,OAAOC,MAAM,CAACF,GAAG,CAAC;EACpB;EACA,OAAQ,GAAEA,GAAG,CAACG,KAAM,KAAIH,GA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AC9B,MAAMI,GAAG,GAAGxE,GAAG,CAACyE,YAAY,CAAC,CAAC;IAC9B;IACAD,GAAG,CAACE,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM;MAC/B,MAAMC,WAAW,GAAGH,GAAG,CAACI,OAAO,CAAC,CAAC,CAACf,IAAI;MACtCW,GAAG,CAACK,KAAK,CAAC,MAAMT,OAAO,CAACO,WAAW,CAAC,CAAC;IACvC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"remote.js","names":["net","connectToFirefox","defaultFirefoxConnector","createLogger","isErrorWithCode","RemoteTempInstallNotSupported","UsageError","WebExtError","log","import","meta","url","requestErrorToMessage","err","Error","String","error","message","RemoteFirefox","client","checkedForAddonReloading","constructor","on","debug","info","JSON","stringify","rdpError","disconnect","addonRequest","addon","request","response","to","actor","type","getAddonsActor","addonsActor","Promise","reject","installTemporaryAddon","addonPath","openDevTools","getInstalledAddon","addonId","addons","id","map","a","checkForAddonReloading","requestTypes","indexOf","supportedRequestTypes","reloadAddon","process","stdout","write","Date","toTimeString","connect","port","connectWithMaxRetries","maxRetries","retryInterval","establishConnection","lastError","retries","resolve","setTimeout","stack","findFreeTcpPort","srv","createServer","listen","freeTcpPort","address","close"],"sources":["../../src/firefox/remote.js"],"sourcesContent":["import net from 'net';\n\nimport { connectToFirefox as defaultFirefoxConnector } from './rdp-client.js';\nimport { createLogger } from '../util/logger.js';\nimport {\n isErrorWithCode,\n RemoteTempInstallNotSupported,\n UsageError,\n WebExtError,\n} from '../errors.js';\n\nconst log = createLogger(import.meta.url);\n\n// NOTE: this type aliases Object to catch any other possible response.\n\n// Convert a request rejection to a message string.\nfunction requestErrorToMessage(err) {\n if (err instanceof Error) {\n return String(err);\n }\n return `${err.error}: ${err.message}`;\n}\n\nexport class RemoteFirefox {\n client;\n checkedForAddonReloading;\n\n constructor(client) {\n this.client = client;\n this.checkedForAddonReloading = false;\n\n client.on('disconnect', () => {\n log.debug('Received \"disconnect\" from Firefox client');\n });\n client.on('end', () => {\n log.debug('Received \"end\" from Firefox client');\n });\n client.on('unsolicited-event', (info) => {\n log.debug(`Received message from client: ${JSON.stringify(info)}`);\n });\n client.on('rdp-error', (rdpError) => {\n log.debug(`Received error from client: ${JSON.stringify(rdpError)}`);\n });\n client.on('error', (error) => {\n log.debug(`Received error from client: ${String(error)}`);\n });\n }\n\n disconnect() {\n this.client.disconnect();\n }\n\n async addonRequest(addon, request) {\n try {\n const response = await this.client.request({\n to: addon.actor,\n type: request,\n });\n return response;\n } catch (err) {\n log.debug(`Client responded to '${request}' request with error:`, err);\n const message = requestErrorToMessage(err);\n throw new WebExtError(`Remote Firefox: addonRequest() error: ${message}`);\n }\n }\n\n async getAddonsActor() {\n try {\n // getRoot should work since Firefox 55 (bug 1352157).\n const response = await this.client.request('getRoot');\n if (response.addonsActor == null) {\n return Promise.reject(\n new RemoteTempInstallNotSupported(\n 'This version of Firefox does not provide an add-ons actor for ' +\n 'remote installation.',\n ),\n );\n }\n return response.addonsActor;\n } catch (err) {\n // Fallback to listTabs otherwise, Firefox 49 - 77 (bug 1618691).\n log.debug('Falling back to listTabs because getRoot failed', err);\n }\n\n try {\n const response = await this.client.request('listTabs');\n // addonsActor was added to listTabs in Firefox 49 (bug 1273183).\n if (response.addonsActor == null) {\n log.debug(\n 'listTabs returned a falsey addonsActor: ' +\n `${JSON.stringify(response)}`,\n );\n return Promise.reject(\n new RemoteTempInstallNotSupported(\n 'This is an older version of Firefox that does not provide an ' +\n 'add-ons actor for remote installation. Try Firefox 49 or ' +\n 'higher.',\n ),\n );\n }\n return response.addonsActor;\n } catch (err) {\n log.debug('listTabs error', err);\n const message = requestErrorToMessage(err);\n throw new WebExtError(`Remote Firefox: listTabs() error: ${message}`);\n }\n }\n\n async installTemporaryAddon(addonPath, openDevTools) {\n const addonsActor = await this.getAddonsActor();\n\n try {\n const response = await this.client.request({\n to: addonsActor,\n type: 'installTemporaryAddon',\n addonPath,\n openDevTools,\n });\n log.debug(`installTemporaryAddon: ${JSON.stringify(response)}`);\n log.info(`Installed ${addonPath} as a temporary add-on`);\n return response;\n } catch (err) {\n const message = requestErrorToMessage(err);\n throw new WebExtError(`installTemporaryAddon: Error: ${message}`);\n }\n }\n\n async getInstalledAddon(addonId) {\n try {\n const response = await this.client.request('listAddons');\n for (const addon of response.addons) {\n if (addon.id === addonId) {\n return addon;\n }\n }\n log.debug(\n `Remote Firefox has these addons: ${response.addons.map((a) => a.id)}`,\n );\n return Promise.reject(\n new WebExtError(\n 'The remote Firefox does not have your extension installed',\n ),\n );\n } catch (err) {\n const message = requestErrorToMessage(err);\n throw new WebExtError(`Remote Firefox: listAddons() error: ${message}`);\n }\n }\n\n async checkForAddonReloading(addon) {\n if (this.checkedForAddonReloading) {\n // We only need to check once if reload() is supported.\n return addon;\n } else {\n const response = await this.addonRequest(addon, 'requestTypes');\n\n if (response.requestTypes.indexOf('reload') === -1) {\n const supportedRequestTypes = JSON.stringify(response.requestTypes);\n log.debug(`Remote Firefox only supports: ${supportedRequestTypes}`);\n throw new UsageError(\n 'This Firefox version does not support add-on reloading. ' +\n 'Re-run with --no-reload',\n );\n } else {\n this.checkedForAddonReloading = true;\n return addon;\n }\n }\n }\n\n async reloadAddon(addonId) {\n const addon = await this.getInstalledAddon(addonId);\n await this.checkForAddonReloading(addon);\n await this.addonRequest(addon, 'reload');\n process.stdout.write(\n `\\rLast extension reload: ${new Date().toTimeString()}`,\n );\n log.debug('\\n');\n }\n}\n\n// Connect types and implementation\n\nexport async function connect(\n port,\n { connectToFirefox = defaultFirefoxConnector } = {},\n) {\n log.debug(`Connecting to Firefox on port ${port}`);\n const client = await connectToFirefox(port);\n log.debug(`Connected to the remote Firefox debugger on port ${port}`);\n return new RemoteFirefox(client);\n}\n\n// ConnectWithMaxRetries types and implementation\n\nexport async function connectWithMaxRetries(\n // A max of 250 will try connecting for 30 seconds.\n { maxRetries = 250, retryInterval = 120, port },\n { connectToFirefox = connect } = {},\n) {\n async function establishConnection() {\n var lastError;\n\n for (let retries = 0; retries <= maxRetries; retries++) {\n try {\n return await connectToFirefox(port);\n } catch (error) {\n if (isErrorWithCode('ECONNREFUSED', error)) {\n // Wait for `retryInterval` ms.\n await new Promise((resolve) => {\n setTimeout(resolve, retryInterval);\n });\n\n lastError = error;\n log.debug(\n `Retrying Firefox (${retries}); connection error: ${error}`,\n );\n } else {\n log.error(error.stack);\n throw error;\n }\n }\n }\n\n log.debug('Connect to Firefox debugger: too many retries');\n throw lastError;\n }\n\n log.debug('Connecting to the remote Firefox debugger');\n return establishConnection();\n}\n\nexport function findFreeTcpPort() {\n return new Promise((resolve) => {\n const srv = net.createServer();\n srv.listen(0, '127.0.0.1', () => {\n const freeTcpPort = srv.address().port;\n srv.close(() => resolve(freeTcpPort));\n });\n });\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,SAASC,gBAAgB,IAAIC,uBAAuB,QAAQ,iBAAiB;AAC7E,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SACEC,eAAe,EACfC,6BAA6B,EAC7BC,UAAU,EACVC,WAAW,QACN,cAAc;AAErB,MAAMC,GAAG,GAAGL,YAAY,CAACM,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;;AAEzC;;AAEA;AACA,SAASC,qBAAqBA,CAACC,GAAG,EAAE;EAClC,IAAIA,GAAG,YAAYC,KAAK,EAAE;IACxB,OAAOC,MAAM,CAACF,GAAG,CAAC;EACpB;EACA,OAAO,GAAGA,GAAG,CAACG,KAAK,KAAKH,GAAG,CAACI,OAAO,EAAE;AACvC;AAEA,OAAO,MAAMC,aAAa,CAAC;EACzBC,MAAM;EACNC,wBAAwB;EAExBC,WAAWA,CAACF,MAAM,EAAE;IAClB,IAAI,CAACA,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,wBAAwB,GAAG,KAAK;IAErCD,MAAM,CAACG,EAAE,CAAC,YAAY,EAAE,MAAM;MAC5Bd,GAAG,CAACe,KAAK,CAAC,2CAA2C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AAC;AACJ","ignoreList":[]}
package/lib/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","names":["main","cmd"],"sources":["../src/main.js"],"sourcesContent":["/* @flow */\nimport { main } from './program.js';\nimport cmd from './cmd/index.js';\n\n// This only exposes main and cmd, while util/logger and util/adb are defined as\n// separate additional exports in the package.json.\nexport default { main, cmd };\n"],"mappings":"AACA,SAASA,IAAI,QAAQ,cAAc;AACnC,OAAOC,GAAG,MAAM,gBAAgB;;AAEhC;AACA;AACA,eAAe;EAAED,IAAI;EAAEC;AAAI,CAAC"}
1
+ {"version":3,"file":"main.js","names":["main","cmd"],"sources":["../src/main.js"],"sourcesContent":["import { main } from './program.js';\nimport cmd from './cmd/index.js';\n\n// This only exposes main and cmd, while util/logger and util/adb are defined as\n// separate additional exports in the package.json.\nexport default { main, cmd };\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,cAAc;AACnC,OAAOC,GAAG,MAAM,gBAAgB;;AAEhC;AACA;AACA,eAAe;EAAED,IAAI;EAAEC;AAAI,CAAC","ignoreList":[]}
package/lib/program.js CHANGED
@@ -16,15 +16,20 @@ const envPrefix = 'WEB_EXT';
16
16
  // Default to "development" (the value actually assigned will be interpolated
17
17
  // by babel-plugin-transform-inline-environment-variables).
18
18
  const defaultGlobalEnv = "production" || 'development';
19
-
20
- // TODO: add pipes to Flow type after https://github.com/facebook/flow/issues/2405 is fixed
21
-
22
19
  export const AMO_BASE_URL = 'https://addons.mozilla.org/api/v5/';
23
20
 
24
21
  /*
25
22
  * The command line program.
26
23
  */
27
24
  export class Program {
25
+ absolutePackageDir;
26
+ yargs;
27
+ commands;
28
+ shouldExitProgram;
29
+ verboseEnabled;
30
+ options;
31
+ programArgv;
32
+ demandedOptions;
28
33
  constructor(argv, {
29
34
  absolutePackageDir = process.cwd()
30
35
  } = {}) {
@@ -163,9 +168,6 @@ export class Program {
163
168
  if (argv.startUrl && !argv.startUrl.length) {
164
169
  throw new UsageError('Not enough arguments following: start-url');
165
170
  }
166
- if (Array.isArray(argv.firefoxPreview) && !argv.firefoxPreview.length) {
167
- argv.firefoxPreview = ['mv3'];
168
- }
169
171
  return argv;
170
172
  }
171
173
 
@@ -248,10 +250,10 @@ export class Program {
248
250
  }
249
251
  if (configFiles.length) {
250
252
  const niceFileList = configFiles.map(f => f.replace(process.cwd(), '.')).map(f => f.replace(os.homedir(), '~')).join(', ');
251
- log.info('Applying config file' + `${configFiles.length !== 1 ? 's' : ''}: ` + `${niceFileList}`);
253
+ log.debug('Applying config file' + `${configFiles.length !== 1 ? 's' : ''}: ` + `${niceFileList}`);
252
254
  }
253
- configFiles.forEach(configFileName => {
254
- const configObject = loadJSConfigFile(configFileName);
255
+ for (const configFileName of configFiles) {
256
+ const configObject = await loadJSConfigFile(configFileName);
255
257
  adjustedArgv = applyConfigToArgv({
256
258
  argv: adjustedArgv,
257
259
  argvFromCLI: argv,
@@ -259,7 +261,7 @@ export class Program {
259
261
  configObject,
260
262
  options: this.options
261
263
  });
262
- });
264
+ }
263
265
  if (adjustedArgv.verbose) {
264
266
  // Ensure that the verbose is enabled when specified in a config file.
265
267
  this.enableVerboseMode(logStream, version);
@@ -306,9 +308,6 @@ export async function defaultVersionGetter(absolutePackageDir, {
306
308
  return `${git.branch(absolutePackageDir)}-${git.long(absolutePackageDir)}`;
307
309
  }
308
310
  }
309
-
310
- // TODO: add pipes to Flow type after https://github.com/facebook/flow/issues/2405 is fixed
311
-
312
311
  export function throwUsageErrorIfArray(errorMessage) {
313
312
  return value => {
314
313
  if (Array.isArray(value)) {
@@ -328,14 +327,6 @@ export async function main(absolutePackageDir, {
328
327
  });
329
328
  const version = await getVersion(absolutePackageDir);
330
329
 
331
- // This is an option shared by some commands but not all of them, hence why
332
- // it isn't a global option.
333
- const firefoxPreviewOption = {
334
- describe: 'Turn on developer preview features in Firefox' + ' (defaults to "mv3")',
335
- demandOption: false,
336
- type: 'array'
337
- };
338
-
339
330
  // yargs uses magic camel case expansion to expose options on the
340
331
  // final argv object. For example, the 'artifacts-dir' option is alternatively
341
332
  // available as argv.artifactsDir.
@@ -428,9 +419,9 @@ Example: $0 --help run.
428
419
  describe: 'Overwrite destination package if it exists.',
429
420
  type: 'boolean'
430
421
  }
431
- }).command('sign', 'Sign the extension so it can be installed in Firefox', commands.sign, {
422
+ }).command('dump-config', 'Run config discovery and dump the resulting config data as JSON', commands.dumpConfig, {}).command('sign', 'Sign the extension so it can be installed in Firefox', commands.sign, {
432
423
  'amo-base-url': {
433
- describe: 'Signing API URL prefix - only used with `use-submission-api`',
424
+ describe: 'Submission API URL prefix',
434
425
  default: AMO_BASE_URL,
435
426
  demandOption: true,
436
427
  type: 'string'
@@ -445,42 +436,30 @@ Example: $0 --help run.
445
436
  demandOption: true,
446
437
  type: 'string'
447
438
  },
448
- 'api-url-prefix': {
449
- describe: 'Signing API URL prefix',
450
- default: 'https://addons.mozilla.org/api/v4',
451
- demandOption: true,
452
- type: 'string'
453
- },
454
439
  'api-proxy': {
455
440
  describe: 'Use a proxy to access the signing API. ' + 'Example: https://yourproxy:6000 ',
456
441
  demandOption: false,
457
442
  type: 'string'
458
443
  },
459
- 'use-submission-api': {
460
- describe: 'Sign using the addon submission API',
461
- demandOption: false,
462
- type: 'boolean'
463
- },
464
- id: {
465
- describe: 'A custom ID for the extension. This has no effect if the ' + 'extension already declares an explicit ID in its manifest.',
466
- demandOption: false,
467
- type: 'string'
468
- },
469
444
  timeout: {
470
445
  describe: 'Number of milliseconds to wait before giving up',
471
446
  type: 'number'
472
447
  },
473
- 'disable-progress-bar': {
474
- describe: 'Disable the progress bar in sign-addon',
475
- demandOption: false,
476
- type: 'boolean'
448
+ 'approval-timeout': {
449
+ describe: 'Number of milliseconds to wait for approval before giving up. ' + 'Set to 0 to disable waiting for approval. Fallback to `timeout` if not set.',
450
+ type: 'number'
477
451
  },
478
452
  channel: {
479
- describe: 'The channel for which to sign the addon. Either ' + "'listed' or 'unlisted'",
453
+ describe: "The channel for which to sign the addon. Either 'listed' or 'unlisted'.",
454
+ demandOption: true,
480
455
  type: 'string'
481
456
  },
482
457
  'amo-metadata': {
483
- describe: 'Path to a JSON file containing an object with metadata ' + 'to be passed to the API. ' + 'See https://addons-server.readthedocs.io' + '/en/latest/topics/api/addons.html for details. ' + 'Only used with `use-submission-api`',
458
+ describe: 'Path to a JSON file containing an object with metadata to be passed to the API. ' + 'See https://addons-server.readthedocs.io/en/latest/topics/api/addons.html for details.',
459
+ type: 'string'
460
+ },
461
+ 'upload-source-code': {
462
+ describe: 'Path to an archive file containing human readable source code of this submission, ' + 'if the code in --source-dir has been processed to make it unreadable. ' + 'See https://extensionworkshop.com/documentation/publish/source-code-submission/ for ' + 'details.',
484
463
  type: 'string'
485
464
  }
486
465
  }).command('run', 'Run the extension', commands.run, {
@@ -576,7 +555,6 @@ Example: $0 --help run.
576
555
  demandOption: false,
577
556
  type: 'array'
578
557
  },
579
- 'firefox-preview': firefoxPreviewOption,
580
558
  // Firefox for Android CLI options.
581
559
  'adb-bin': {
582
560
  describe: 'Specify a custom path to the adb binary',
@@ -664,8 +642,7 @@ Example: $0 --help run.
664
642
  describe: 'Disables colorful shell output',
665
643
  type: 'boolean',
666
644
  default: false
667
- },
668
- 'firefox-preview': firefoxPreviewOption
645
+ }
669
646
  }).command('docs', 'Open the web-ext documentation in a browser', commands.docs, {});
670
647
  return program.execute({
671
648
  getVersion,