Skip to content

Commit 601cab7

Browse files
committed
Fix compatibility with lastest Firefox Nightly
1 parent c31888d commit 601cab7

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Firefox add-on improving automated HAR (HTTP Archive) export of collected
33
data from the Network panel. This add-on is built on top of native developer
44
tools in Firefox. Firebug is not needed for this add-on.
55

6-
The add-on HAR exports HAR API directly to the page. Any automated system can
6+
The add-on exports HAR API directly to the page. Any automated system can
77
be consequently built on top of the API and trigger HAR export using a simple
88
JavaScript call at any time. It can be also nicely integrated with e.g.
99
Selenium to implement automated HAR export robots for existing automated test

lib/har-driver-actor.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,41 @@ const Events = require("sdk/event/core");
1515
// Platform
1616
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
1717

18-
// DevTools
19-
// See also: https://bugzilla.mozilla.org/show_bug.cgi?id=912121
20-
var devtools;
21-
try {
22-
devtools = Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {}).devtools;
23-
} catch (err) {
24-
devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
18+
function safeImport(...args) {
19+
for (var i=0; i<args.length; i++) {
20+
try {
21+
return Cu["import"](args[i], {});
22+
}
23+
catch (err) {
24+
}
25+
}
26+
return {};
2527
}
2628

27-
var DevToolsUtils;
28-
try {
29-
DevToolsUtils = devtools["require"]("devtools/shared/DevToolsUtils");
30-
} catch (err) {
31-
DevToolsUtils = devtools["require"]("devtools/toolkit/DevToolsUtils");
29+
function safeRequire(devtools, ...args) {
30+
for (var i=0; i<args.length; i++) {
31+
try {
32+
return devtools["require"](args[i]);
33+
}
34+
catch (err) {
35+
}
36+
}
37+
return {};
3238
}
3339

40+
// DevTools
41+
// See also: https://bugzilla.mozilla.org/show_bug.cgi?id=912121
42+
const devtools = safeImport(
43+
"resource://devtools/shared/Loader.jsm",
44+
"resource://gre/modules/devtools/shared/Loader.jsm",
45+
"resource://gre/modules/devtools/Loader.jsm"
46+
).devtools;
47+
48+
const DevToolsUtils = safeRequire(devtools,
49+
"devtools/shared/DevToolsUtils",
50+
"devtools/toolkit/DevToolsUtils"
51+
);
52+
3453
const { DebuggerServer } = devtools["require"]("devtools/server/main");
3554
const protocol = devtools["require"]("devtools/server/protocol");
3655
const { method, RetVal, ActorClass, Actor, Arg, types } = protocol;
@@ -69,7 +88,7 @@ function expectState(expectedState, method) {
6988
}
7089

7190
/**
72-
* @actor
91+
* @actor
7392
*
7493
* Read more about Protocol API:
7594
* https://github.com/mozilla/gecko-dev/blob/master/toolkit/devtools/server/docs/protocol.js.md

lib/har-driver-front.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.metadata = {
1010
const { Cu } = require("chrome");
1111

1212
// DevTools
13-
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
13+
const { devtools } = require("firebug.sdk/lib/core/devtools.js");
1414
const { Front, FrontClass } = devtools["require"]("devtools/server/protocol");
1515

1616
// Firebug SDK

lib/trigger-toolbox-overlay.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const { get: getHarOverlay } = safeRequire(devtools,
2929
const { Trace, TraceError } = require("firebug.sdk/lib/core/trace.js").get(module.id);
3030
const { ToolboxOverlay } = require("firebug.sdk/lib/toolbox-overlay.js");
3131
const { Rdp } = require("firebug.sdk/lib/core/rdp.js");
32+
const { Options } = require("firebug.sdk/lib/core/options.js");
3233

3334
// HARExportTrigger
3435
const { HarDriverFront } = require("./har-driver-front");
@@ -99,6 +100,12 @@ const TriggerToolboxOverlay = Class(
99100

100101
// Initialize automation.
101102
let harOverlay = getHarOverlay(this.toolbox);
103+
if (!harOverlay) {
104+
TraceError.sysout("TriggerToolboxOverlay.onReady; ERROR " +
105+
"No HAR Overlay!");
106+
return;
107+
}
108+
102109
if (!harOverlay.automation) {
103110
harOverlay.initAutomation();
104111
}
@@ -149,6 +156,18 @@ const TriggerToolboxOverlay = Class(
149156
});
150157
}
151158
}
159+
160+
// xxxHonza: needs testing
161+
/*automation.pageLoadBegin = function(response) {
162+
// If the persist log preference is on do not clear the HAR log.
163+
// It'll be collecting all data as the tab content is reloaded
164+
// or navigated to different location.
165+
// See also: https://github.com/firebug/har-export-trigger/issues/14
166+
let persist = Options.getPref("devtools.webconsole.persistlog");
167+
if (!persist) {
168+
this.resetCollector();
169+
}
170+
}*/
152171
},
153172

154173
onPageLoadDone: function(response) {
@@ -242,8 +261,6 @@ const TriggerToolboxOverlay = Class(
242261
"Failed to parse HAR log " + err);
243262
}
244263

245-
Trace.sysout("TriggerToolboxOverlay.triggerExport; DONE", har);
246-
247264
// Send event back to the backend notifying that it has
248265
// finished. If 'getData' is true include also the HAR string.
249266
// The content API call will be resolved as soon as the packet

0 commit comments

Comments
 (0)