1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 /* exported initialize */
9 * This script is the entry point of Network monitor panel.
10 * See README.md for more information.
12 const { BrowserLoader
} = ChromeUtils
.importESModule(
13 "resource://devtools/shared/loader/browser-loader.sys.mjs"
16 const require
= (window
.windowRequire
= BrowserLoader({
17 baseURI
: "resource://devtools/client/netmonitor/",
23 } = require("resource://devtools/client/netmonitor/src/app.js");
24 const EventEmitter
= require("resource://devtools/shared/event-emitter.js");
26 // Inject EventEmitter into global window.
27 EventEmitter
.decorate(window
);
30 * This is the initialization point for the Network monitor.
32 * @param {Object} api Allows reusing existing API object.
34 function initialize(api
) {
35 const app
= new NetMonitorApp(api
);
37 // Inject to global window for testing
38 window
.Netmonitor
= app
;
40 window
.store
= app
.api
.store
;
41 window
.connector
= app
.api
.connector
;
42 window
.actions
= app
.api
.actions
;
48 * The following code is used to open Network monitor in a tab.
49 * Like the Launchpad, but without Launchpad.
52 * chrome://devtools/content/netmonitor/index.html?type=process
53 * loads the netmonitor for the parent process, exactly like the
54 * one in the browser toolbox
56 * It's also possible to connect to a tab.
57 * 1) go in about:debugging
58 * 2) In menu Tabs, click on a Debug button for particular tab
60 * This will open an about:devtools-toolbox url, from which you can
61 * take type and id query parameters and reuse them for the chrome url
64 * chrome://devtools/content/netmonitor/index.html?type=tab&id=1234 URLs
65 * where 1234 is the tab id, you can retrieve from about:debugging#tabs links.
66 * Simply copy the id from about:devtools-toolbox?type=tab&id=1234 URLs.
69 // URL constructor doesn't support chrome: scheme
70 const href
= window
.location
.href
.replace(/chrome:/, "http://");
71 const url
= new window
.URL(href
);
73 // If query parameters are given in a chrome tab, the inspector
74 // is running in standalone.
75 if (window
.location
.protocol
=== "chrome:" && url
.search
.length
> 1) {
78 } = require("resource://devtools/client/framework/commands-from-url.js");
82 const commands
= await
commandsFromURL(url
);
83 const target
= await commands
.descriptorFront
.getTarget();
84 // Create a fake toolbox object
87 viewSourceInDebugger() {
89 "toolbox.viewSourceInDebugger is not implement from a tab"
97 } = require("resource://devtools/client/netmonitor/src/api.js");
98 const api
= new NetMonitorAPI();
99 await api
.connect(toolbox
);
100 const app
= window
.initialize(api
);
103 document
: window
.document
,
106 window
.alert("Unable to start the network monitor:" + err
);