2018-01-10 19:16:37 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2018-04-17 15:09:34 +03:00
|
|
|
/* exported initialize */
|
2018-01-10 19:16:37 +03:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This script is the entry point of Network monitor panel.
|
|
|
|
* See README.md for more information.
|
|
|
|
*/
|
2018-01-30 02:20:18 +03:00
|
|
|
const { BrowserLoader } = ChromeUtils.import(
|
2018-01-10 19:16:37 +03:00
|
|
|
"resource://devtools/client/shared/browser-loader.js", {});
|
|
|
|
|
|
|
|
const require = window.windowRequire = BrowserLoader({
|
|
|
|
baseURI: "resource://devtools/client/netmonitor/",
|
|
|
|
window,
|
|
|
|
}).require;
|
|
|
|
|
2018-04-17 15:09:34 +03:00
|
|
|
const { NetMonitorAPI } = require("./src/api");
|
|
|
|
const { NetMonitorApp } = require("./src/app");
|
2018-03-14 16:58:24 +03:00
|
|
|
const EventEmitter = require("devtools/shared/event-emitter");
|
2018-01-10 19:16:37 +03:00
|
|
|
|
|
|
|
// Inject EventEmitter into global window.
|
|
|
|
EventEmitter.decorate(window);
|
|
|
|
|
|
|
|
/**
|
2018-04-17 15:09:34 +03:00
|
|
|
* This is the initialization point for the Network monitor.
|
|
|
|
*
|
|
|
|
* @param {Object} api Allows reusing existing API object.
|
2018-01-10 19:16:37 +03:00
|
|
|
*/
|
2018-04-17 15:09:34 +03:00
|
|
|
function initialize(api) {
|
|
|
|
const app = new NetMonitorApp(api);
|
2018-04-17 15:09:29 +03:00
|
|
|
|
2018-04-17 15:09:34 +03:00
|
|
|
// Inject to global window for testing
|
|
|
|
window.Netmonitor = app;
|
2018-04-17 15:38:25 +03:00
|
|
|
window.api = api;
|
2018-04-17 15:09:34 +03:00
|
|
|
window.store = app.api.store;
|
|
|
|
window.connector = app.api.connector;
|
|
|
|
window.actions = app.api.actions;
|
2018-04-17 15:09:29 +03:00
|
|
|
|
2018-04-17 15:09:34 +03:00
|
|
|
return app;
|
|
|
|
}
|
2018-04-17 15:09:29 +03:00
|
|
|
|
2018-04-17 15:09:34 +03:00
|
|
|
/**
|
|
|
|
* The following code is used to open Network monitor in a tab.
|
|
|
|
* Like the Launchpad, but without Launchpad.
|
|
|
|
*
|
|
|
|
* For example:
|
|
|
|
* chrome://devtools/content/netmonitor/index.html?type=process
|
|
|
|
* loads the netmonitor for the parent process, exactly like the
|
|
|
|
* one in the browser toolbox
|
|
|
|
*
|
|
|
|
* It's also possible to connect to a tab.
|
|
|
|
* 1) go in about:debugging
|
|
|
|
* 2) In menu Tabs, click on a Debug button for particular tab
|
|
|
|
*
|
|
|
|
* This will open an about:devtools-toolbox url, from which you can
|
|
|
|
* take type and id query parameters and reuse them for the chrome url
|
|
|
|
* of the netmonitor
|
|
|
|
*
|
|
|
|
* chrome://devtools/content/netmonitor/index.html?type=tab&id=1234 URLs
|
|
|
|
* where 1234 is the tab id, you can retrieve from about:debugging#tabs links.
|
|
|
|
* Simply copy the id from about:devtools-toolbox?type=tab&id=1234 URLs.
|
|
|
|
*/
|
2018-01-10 19:16:37 +03:00
|
|
|
|
|
|
|
// URL constructor doesn't support chrome: scheme
|
|
|
|
let href = window.location.href.replace(/chrome:/, "http://");
|
|
|
|
let url = new window.URL(href);
|
|
|
|
|
|
|
|
// If query parameters are given in a chrome tab, the inspector
|
|
|
|
// is running in standalone.
|
|
|
|
if (window.location.protocol === "chrome:" && url.search.length > 1) {
|
|
|
|
const { targetFromURL } = require("devtools/client/framework/target-from-url");
|
|
|
|
|
2018-03-12 21:24:38 +03:00
|
|
|
(async function() {
|
2018-01-10 19:16:37 +03:00
|
|
|
try {
|
|
|
|
let target = await targetFromURL(url);
|
|
|
|
|
|
|
|
// Start the network event listening as it is done in the toolbox code
|
|
|
|
await target.activeConsole.startListeners([
|
|
|
|
"NetworkActivity",
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Create a fake toolbox object
|
|
|
|
let toolbox = {
|
|
|
|
target,
|
|
|
|
viewSourceInDebugger() {
|
|
|
|
throw new Error("toolbox.viewSourceInDebugger is not implement from a tab");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-17 15:09:34 +03:00
|
|
|
let api = new NetMonitorAPI();
|
|
|
|
await api.connect(toolbox);
|
|
|
|
let app = window.initialize(api);
|
|
|
|
app.bootstrap({
|
|
|
|
toolbox,
|
|
|
|
document: window.document,
|
|
|
|
});
|
2018-01-10 19:16:37 +03:00
|
|
|
} catch (err) {
|
|
|
|
window.alert("Unable to start the network monitor:" + err);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}
|