Commit adae89f2 authored by Nicolas Chevobbe's avatar Nicolas Chevobbe
Browse files

Bug 1486446 - Remove Console Launchpad support; r=bgrins.

It's broken and unmaintained for a long time now,
the Console Team does not use it and has no plan doing so.

Differential Revision: https://phabricator.services.mozilla.com/D4348

--HG--
extra : moz-landing-system : lando
parent 12340428
Loading
Loading
Loading
Loading
+11 −93
Original line number Diff line number Diff line
@@ -6,125 +6,39 @@ It can also display network logs, and you can evaluate expressions using the con
input, a.k.a. JsTerm. You can read more about it on [MDN](https://developer.mozilla.org/en-US/docs/Tools/Web_Console)
to learn all the features and how to use the tool.

## Old / New frontend

The current console used in the toolbox is called the new frontend, and the code lives at
the root of the `devtools/client/webconsole/` folder.
The old console code is located in the `devtools/client/webconsole/old` folder.
Both frontends use the same code for the console input, also called JsTerm (see `jsterm.js`).
The old frontend is still used for the Browser Console, but is planned to be removed in the
near future (see Bug 1381834).

## Run WebConsole in DevTools panel
## Run WebConsole

If you want to build the WebConsole inside of the DevTools toolbox (Firefox Devtools Panels),
follow the [simple Firefox build](http://docs.firefox-dev.tools/getting-started/build.html)
document in MDN. Start your compiled firefox and open the Firefox developer tool, you can
documentation. Start your compiled firefox and open the Firefox developer tool, you can
then see the WebConsole tab.

## Run WebConsole in a browser tab (experimental)

### Prerequisite

If you would like to run the WebConsole in the browser tab, you need following packages:

* [node](https://nodejs.org/) >= 7.10.0 JavaScript runtime.
* [yarn](https://yarnpkg.com/docs/install) >= 1.0.0 the package dependency management tool.
* [Firefox](https://www.mozilla.org/firefox/new/) any version or build from the source code.

### Run WebConsole

Navigate to the `mozilla-central/devtools/client/webconsole` folder with your terminal.
Note that this folder is available after `mozilla-central` was cloned in order to get a
local copy of the repository. Then run the following commands:

```bash
# Install packages
yarn install

# Create a dev server instance for hosting webconsole on browser
yarn start
```

Open `localhost:8000` to see what we call the [launchpad](https://github.com/devtools-html/devtools-core/tree/master/packages/devtools-launchpad).
The UI that let you start a new Firefox window which will be the target (or debuggee).
Launchpad will communicate with Firefox (the remote debugging server) and list all opened tabs from Firefox.
You can then navigate to a website you want in the target window, and you should see it appears
in the `localhost:8000` page. Clicking on it will start the WebConsole in the browser tab.

### How it works

The WebConsole uses [webpack](https://webpack.js.org/) and several packages from [devtools-core](https://github.com/devtools-html/devtools-core)
to run as a normal web page. The WebConsole uses [Mozilla remote debugging protocol](http://searchfox.org/mozilla-central/source/devtools/docs/backend/protocol.md)
to fetch messages and execute commands against Firefox.

Open `localhost:8000` in any browser to see the
interface. Devtools Launchpad will communicate with Firefox (the remote debugging server)
and list all opened tabs from Firefox. Click one of the browser tab entry, now you can see
the WebConsole runs in a browser tab.

### DevTools shared modules

When working on console running via launchpad, you may need to modify code on external modules.
Besides the third party modules, here are modules required for the WebConsole
(hosted under the `devtools-core` Github repo, which contains modules shared across Devtools).

* [devtools-config](https://github.com/devtools-html/devtools-core/blob/master/packages/devtools-config/#readme) config used in dev server
* [devtools-launchpad](https://github.com/devtools-html/devtools-core/blob/master/packages/devtools-launchpad/#readme) provide the dev server, landing page and the bootstrap functions to run devtools in the browser tab.
* [devtools-modules](https://github.com/devtools-html/devtools-core/blob/master/packages/devtools-modules/#readme) Devtools shared and shim modules.
* [devtools-source-editor](https://github.com/devtools-html/devtools-core/blob/master/packages/devtools-source-editor/#readme) Source Editor component.
* [devtools-reps](https://github.com/devtools-html/debugger.html/blob/master/packages/devtools-reps/#readme) remote object formatter for variables representation.

Changes to those modules need to be done on Github, using the Pull Request workflow.
Then, a new version of the modified package need to be released on npm so the version number
can be updated in WebConsole's `package.json`. Some modules have a release process,
look for `RELEASE.md` file in the module folder, or ask a maintainer if you are
unsure about the release process.

## Code Structure

Top level files are used to launch the WebConsole inside of the DevTools toolbox or run in
the browser tab (experimental). The same code base is used to run in both environments.

### Run inside of the DevTools toolbox

Files used to run the WebConsole inside of the DevTools toolbox.
Top level files are used to launch the WebConsole inside of the DevTools toolbox.
The main files used to run the WebConsole are:

* `main.js` called by devtools toolbox to launch the WebConsole panel.
* `index.html` panel UI and launch scripts.

### Run in the browser tab (experimental)

Files used to run the WebConsole in the browser tab

* `bin/` files to launch test server.
* `configs/` dev configs.
* `local-dev/index.js` the entry point, equivalent to `index.html`.
* `webpack.config.js` the webpack config file, including plenty of module aliases map to shims and polyfills.
* `package.json` declare every required packages and available commands.

To run in the browser tab, the WebConsole needs to get some dependencies from npm module.
Check `package.json` to see all dependencies. Check `webpack.config.js` to find the module alias,
and check [devtools-core](https://github.com/devtools-html/devtools-core) packages to dive
into actual modules used by the WebConsole and other Devtools.

### UI

The WebConsole UI is built using [React](http://docs.firefox-dev.tools/frontend/react.html)
components (in `components/`).

The React application is rendered from `webconsole-output-wrapper.js`.
It contains 3 top components:
It contains 4 top components:
* **ConsoleOutput** (in `ConsoleOutput.js`) is the component where messages are rendered.
* **FilterBar** (in `FilterBar.js`) is the component for the filter bars (filter input and toggle buttons).
* **SideBar** (in `SideBar.js`) is the component that render the sidebar where objects can be placed in.
* **JsTerm** (in `JsTerm.js`) is the component that render the console input.

We prefer stateless component (defined by function) instead of stateful component
(defined by class) unless the component has to maintain its internal state.

### State

Besides the UI, the WebConsole manages the app state via [Redux](When working on console running via launchpad).
Besides the UI, the WebConsole manages the app state via [Redux].
The following locations define the app state:

* `src/constants.js` constants used across the tool including action and event names.
@@ -137,8 +51,12 @@ The redux state is a plain javascript object with the following properties:
{
  // State of the filter input and toggle buttons
  filters,
  // State of the input history
  history,
  // Console messages data and state (hidden, expanded, groups, …)
  messages,
  // State of notifications displayed on the output (e.g. self-XSS warning message)
  notifications,
  // Preferences (persist message, message limit, …)
  prefs,
  // Interface state (filter bar visible, sidebar visible, …)
+0 −29
Original line number Diff line number Diff line
/* 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/. */

/* eslint-env node */

"use strict";

const fs = require("fs");
const path = require("path");

function getConfig() {
  if (process.env.TARGET === "firefox-panel") {
    return require("../configs/firefox-panel.json");
  }

  const developmentConfig = require("../configs/development.json");

  let localConfig = {};
  if (fs.existsSync(path.resolve(__dirname, "../configs/local.json"))) {
    localConfig = require("../configs/local.json");
  }

  return Object.assign({}, developmentConfig, localConfig);
}

module.exports = {
  getConfig,
};
+0 −19
Original line number Diff line number Diff line
/* 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/. */

/* eslint-env node */

"use strict";

const toolbox = require("devtools-launchpad/index");
const feature = require("devtools-config");
const { getConfig } = require("./configure");

const envConfig = getConfig();

feature.setConfig(envConfig);

const webpackConfig = require("../webpack.config");

toolbox.startDevServer(envConfig, webpackConfig, __dirname);
+0 −99
Original line number Diff line number Diff line
/* 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/. */

 /* eslint-env browser */

"use strict";

const React = require("react");
const ReactDOM = require("react-dom");
const { EventEmitter } = require("devtools-modules");
const { Services: { appinfo, pref } } = require("devtools-modules");
const { bootstrap } = require("devtools-launchpad");

EventEmitter.decorate(window);

require("../../themes/widgets.css");
require("../../themes/webconsole.css");
require("../../themes/components-frame.css");
require("../../themes/light-theme.css");
require("../../shared/components/reps/reps.css");
require("../../shared/components/tabs/Tabs.css");
require("../../shared/components/tabs/TabBar.css");
require("../../netmonitor/src/assets/styles/httpi.css");

pref("devtools.debugger.remote-timeout", 10000);
pref("devtools.hud.loglimit", 10000);
pref("devtools.webconsole.filter.error", true);
pref("devtools.webconsole.filter.warn", true);
pref("devtools.webconsole.filter.info", true);
pref("devtools.webconsole.filter.log", true);
pref("devtools.webconsole.filter.debug", true);
pref("devtools.webconsole.filter.css", false);
pref("devtools.webconsole.filter.net", false);
pref("devtools.webconsole.filter.netxhr", false);
pref("devtools.webconsole.ui.filterbar", false);
pref("devtools.webconsole.inputHistoryCount", 50);
pref("devtools.webconsole.persistlog", false);
pref("devtools.webconsole.timestampMessages", false);
pref("devtools.webconsole.sidebarToggle", true);

const WebConsoleOutputWrapper = require("../webconsole-output-wrapper");
const WebConsoleFrame = require("../webconsole-frame").WebConsoleFrame;

// Copied from netmonitor/index.js:
window.addEventListener("DOMContentLoaded", () => {
  for (const link of document.head.querySelectorAll("link")) {
    link.href = link.href.replace(/(resource|chrome)\:\/\//, "/");
  }

  if (appinfo.OS === "Darwin") {
    document.documentElement.setAttribute("platform", "mac");
  } else if (appinfo.OS === "Linux") {
    document.documentElement.setAttribute("platform", "linux");
  } else {
    document.documentElement.setAttribute("platform", "win");
  }
});

let consoleFrame;
function onConnect(connection) {
  // If we are on the main dashboard don't render the component
  if (!connection || !connection.tabConnection || !connection.tabConnection.tabTarget) {
    return;
  }

  // Replicate the DOM that the root component lives within
  document.querySelector("#mount").innerHTML = `
    <div id="app-wrapper" class="theme-body">
      <div id="output-container" role="document" aria-live="polite" />
    </div>
  `;

  // Stub out properties that are received from hudservice
  const owner = {
    iframeWindow: window,
    chromeWindow: window,
    hudId: "hud_0",
    getDebuggerFrames: () => { },
    getInspectorSelection: () => { },
    target: connection.tabConnection.tabTarget,
    _browserConsole: false,
    WebConsoleOutputWrapper,
  };
  consoleFrame = new WebConsoleFrame(owner);
  consoleFrame.init().then(function() {
    console.log("WebConsoleFrame initialized");
  });
}

// This is just a hack until the local dev environment includes jsterm
window.evaluateJS = function(input) {
  consoleFrame.webConsoleClient.evaluateJSAsync(`${input}`, function(r) {
    consoleFrame.consoleOutput.dispatchMessageAdd(r);
  }, {});
};

document.documentElement.classList.add("theme-light");
bootstrap(React, ReactDOM).then(onConnect);
+0 −29
Original line number Diff line number Diff line
{
  "name": "webconsole",
  "version": "0.0.1",
  "engines": {
    "node": ">=7.10.0"
  },
  "scripts": {
    "start": "cross-env NODE_ENV=production node bin/dev-server",
    "dev": " cross-env NODE_ENV=development node bin/dev-server"
  },
  "dependencies": {
    "babel-plugin-transform-flow-strip-types": "^6.22.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "cross-env": "^3.1.3",
    "devtools-config": "0.0.12",
    "devtools-launchpad": "^0.0.119",
    "devtools-modules": "0.0.37",
    "file-loader": "^1.1.6",
    "netmonitor": "file:../netmonitor",
    "raw-loader": "^0.5.1",
    "react": "=16.2.0",
    "react-dom": "=16.2.0",
    "react-prop-types": "=0.4.0",
    "react-redux": "=5.0.6",
    "redux": "^3.7.2",
    "require-hacker": "^2.1.4"
  }
}
Loading