Skip to content

Commit 595ceed

Browse files
committed
Make sure to properly initialize the HAR collector
1 parent cf7123a commit 595ceed

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lib/trigger-toolbox-overlay.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ const TriggerToolboxOverlay = Class(
8080
return;
8181
}
8282

83-
let autoExportToFile = Services.prefs.getBoolPref(
84-
"devtools.netmonitor.har.enableAutoExportToFile");
83+
let harOverlay = getHarOverlay(this.toolbox);
8584

8685
// Call make remote to make sure the target.client exists.
8786
let target = this.toolbox.target;
@@ -92,11 +91,30 @@ const TriggerToolboxOverlay = Class(
9291
// But, if users want to use HAR content API to trigger HAR export
9392
// when needed, HAR automation needs to be activated. Let's do it now
9493
// if 'extensions.netmonitor.har.enableAutomation' preference is true.
95-
if (prefs.enableAutomation && !autoExportToFile) {
96-
let harOverlay = getHarOverlay(this.toolbox);
94+
if (prefs.enableAutomation && !harOverlay.automation) {
95+
Trace.sysout("TriggerToolboxOverlay.onReady; Init automation");
96+
97+
// Initialize automation.
9798
harOverlay.initAutomation();
9899
}
99100

101+
// This is a bit hacky, but the HarAutomation starts monitoring
102+
// after target.makeRemote() promise is resolved.
103+
// It's resolved after the parent target.makeRemote() (we are just within)
104+
// finishes.
105+
// So, let's register another promise handler and reset the collector
106+
// after the HarAutomation.startMonitoring() is actually executed.
107+
target.makeRemote().then(() => {
108+
// Make sure the collector exists. The collector is automatically
109+
// created when the page load begins, but the toolbox can be opened
110+
// in the middle of page session (after page load event).
111+
// And HAR API consumer might want to export any time.
112+
let automation = harOverlay.automation;
113+
if (automation && !automation.collector) {
114+
automation.resetCollector();
115+
}
116+
});
117+
100118
this.attach().then(front => {
101119
Trace.sysout("TriggerToolboxOverlay.onReady; HAR driver ready!");
102120
});

0 commit comments

Comments
 (0)