Bug 1533144 - Include hostname from parent/window in HAR save default filename. r=Honza
authorlloan <lloanalas@outlook.com>
Mon, 29 Apr 2019 06:35:02 +0000
changeset 530532 0afabdb9bf0445c54b50f3fe03b548c51b2017ba
parent 530529 e75bfefbe44260b79d057374184329bb19068a4f
child 530533 fcb59a0c2c447b65a172a1caf52d0d5df40f4311
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1533144
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533144 - Include hostname from parent/window in HAR save default filename. r=Honza Include the name of the window/parent hostname in the save HAR filename, e.g. if on mozilla.org, would download as "mozilla.org_Archive [time].har" Differential Revision: https://phabricator.services.mozilla.com/D28732
devtools/client/netmonitor/src/har/har-exporter.js
devtools/client/preferences/devtools-client.js
--- a/devtools/client/netmonitor/src/har/har-exporter.js
+++ b/devtools/client/netmonitor/src/har/har-exporter.js
@@ -67,17 +67,17 @@ const HarExporter = {
     const defaultFileName = Services.prefs.getCharPref(
       "devtools.netmonitor.har.defaultFileName");
     const compress = Services.prefs.getBoolPref(
       "devtools.netmonitor.har.compress");
 
     trace.log("HarExporter.save; " + defaultFileName, options);
 
     let data = await this.fetchHarData(options);
-    let fileName = this.getHarFileName(defaultFileName, options.jsonp, compress);
+    let fileName = this.getHarFileName(defaultFileName, options.jsonp, compress, options);
 
     if (compress) {
       data = await JSZip().file(fileName, data).generateAsync({
         compression: "DEFLATE",
         platform: Services.appinfo.OS === "WINNT" ? "DOS" : "UNIX",
         type: "blob",
       });
     }
@@ -94,18 +94,22 @@ const HarExporter = {
     const day = String(date.getDate()).padStart(2, "0");
     const hour = String(date.getHours()).padStart(2, "0");
     const minutes = String(date.getMinutes()).padStart(2, "0");
     const seconds = String(date.getSeconds()).padStart(2, "0");
 
     return `${year}-${month}-${day} ${hour}-${minutes}-${seconds}`;
   },
 
-  getHarFileName(defaultFileName, jsonp, compress) {
+  getHarFileName(defaultFileName, jsonp, compress, options) {
+    const tabTarget = options.connector.getTabTarget();
+    const host = new URL(tabTarget.url);
+
     let name = defaultFileName.replace(/%date/g, this.formatDate(new Date()));
+    name = name.replace(/%hostname/g, host.hostname);
     name = name.replace(/\:/gm, "-", "");
     name = name.replace(/\//gm, "_", "");
     return `${name}.${jsonp ? "harp" : "har"}`;
   },
 
   /**
    * Copy HAR string into the clipboard.
    *
--- a/devtools/client/preferences/devtools-client.js
+++ b/devtools/client/preferences/devtools-client.js
@@ -175,17 +175,17 @@ pref("devtools.netmonitor.features.resiz
 
 pref("devtools.netmonitor.response.ui.limit", 10240);
 
 // Save request/response bodies yes/no.
 pref("devtools.netmonitor.saveRequestAndResponseBodies", true);
 
 // The default Network monitor HAR export setting
 pref("devtools.netmonitor.har.defaultLogDir", "");
-pref("devtools.netmonitor.har.defaultFileName", "Archive %date");
+pref("devtools.netmonitor.har.defaultFileName", "%hostname_Archive [%date]");
 pref("devtools.netmonitor.har.jsonp", false);
 pref("devtools.netmonitor.har.jsonpCallback", "");
 pref("devtools.netmonitor.har.includeResponseBodies", true);
 pref("devtools.netmonitor.har.compress", false);
 pref("devtools.netmonitor.har.forceExport", false);
 pref("devtools.netmonitor.har.pageLoadedTimeout", 1500);
 pref("devtools.netmonitor.har.enableAutoExportToFile", false);