Skip to content

Commit af8d7c7

Browse files
committed
Support automation without creating a HAR file
1 parent 618ec92 commit af8d7c7

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/trigger-toolbox-overlay.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,23 @@ const TriggerToolboxOverlay = Class(
7272

7373
Trace.sysout("TriggerToolboxOverlay.onReady;", options);
7474

75+
let autoExportToFile = Services.prefs.getBoolPref(
76+
"devtools.netmonitor.har.enableAutoExportToFile");
77+
7578
// Call make remote to make sure the target.client exists.
7679
let target = this.toolbox.target;
7780
target.makeRemote().then(() => {
81+
// The 'devtools.netmonitor.har.enableAutoExportToFile' option doesn't
82+
// have to be set if users don't want to auto export to file after
83+
// every page load.
84+
// But, if users want to use HAR content API to trigger HAR export
85+
// when needed, HAR automation needs to be activated. Let's do it now
86+
// if 'extensions.netmonitor.har.enableAutomation' preference is true.
87+
if (prefs.enableAutomation && !autoExportToFile) {
88+
let harOverlay = getHarOverlay(this.toolbox);
89+
harOverlay.initAutomation();
90+
}
91+
7892
this.attach().then(front => {
7993
Trace.sysout("TriggerToolboxOverlay.onReady; HAR driver ready!");
8094
});
@@ -166,8 +180,9 @@ const TriggerToolboxOverlay = Class(
166180
return;
167181
}
168182

169-
// Trigger HAR export now!
170-
harOverlay.automation.triggerExport(data).then(jsonString => {
183+
// Trigger HAR export now! Use executeExport() not triggerExport()
184+
// since we don't want to have the default name automatically provided.
185+
harOverlay.automation.executeExport(data).then(jsonString => {
171186
Trace.sysout("TriggerToolboxOverlay.triggerExport; DONE", jsonString);
172187

173188
// Send event back to the backend notifying that it has

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@
3333
"description": "Set to true to expose HAR trigger API into the content",
3434
"type": "string",
3535
"value": ""
36+
}, {
37+
"name": "enableAutomation",
38+
"title": "Enable automatic collecting of HAR data",
39+
"description": "Flip this option to enable automatic collecting of HAR data, so HAR export can be triggered when necessary",
40+
"type": "bool",
41+
"value": false
3642
}]
3743
}

0 commit comments

Comments
 (0)