Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inspector debug #20775

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions broccoli/amd-compat-entrypoints/ember.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ d('@ember/controller/index', emberControllerIndex);
import * as emberDebugIndex from '@ember/debug/index';
d('@ember/debug/index', emberDebugIndex);

import * as emberDebugInspectorSupportIndex from '@ember/debug/ember-inspector-support/index';
d('@ember/debug/ember-inspector-support/index', emberDebugInspectorSupportIndex);

import * as emberDebugLibCaptureRenderTree from '@ember/debug/lib/capture-render-tree';
d('@ember/debug/lib/capture-render-tree', emberDebugLibCaptureRenderTree);

Expand Down
46 changes: 44 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"router_js": "^8.0.5",
"semver": "^7.5.2",
"silent-error": "^1.1.1",
"simple-html-tokenizer": "^0.5.11"
"simple-html-tokenizer": "^0.5.11",
"source-map-js": "^1.2.1"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.321.1",
Expand All @@ -113,6 +114,7 @@
"@embroider/shared-internals": "^2.5.0",
"@glimmer/component": "^1.1.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.0",
"@simple-dom/document": "^1.4.0",
"@swc-node/register": "^1.6.8",
"@swc/core": "^1.3.100",
Expand Down Expand Up @@ -235,6 +237,46 @@
"@ember/controller/index.js": "ember-source/@ember/controller/index.js",
"@ember/debug/container-debug-adapter.js": "ember-source/@ember/debug/container-debug-adapter.js",
"@ember/debug/data-adapter.js": "ember-source/@ember/debug/data-adapter.js",
"@ember/debug/ember-inspector-support/adapters/basic.js": "ember-source/@ember/debug/ember-inspector-support/adapters/basic.js",
"@ember/debug/ember-inspector-support/adapters/bookmarklet.js": "ember-source/@ember/debug/ember-inspector-support/adapters/bookmarklet.js",
"@ember/debug/ember-inspector-support/adapters/chrome.js": "ember-source/@ember/debug/ember-inspector-support/adapters/chrome.js",
"@ember/debug/ember-inspector-support/adapters/firefox.js": "ember-source/@ember/debug/ember-inspector-support/adapters/firefox.js",
"@ember/debug/ember-inspector-support/adapters/index.js": "ember-source/@ember/debug/ember-inspector-support/adapters/index.js",
"@ember/debug/ember-inspector-support/adapters/web-extension.js": "ember-source/@ember/debug/ember-inspector-support/adapters/web-extension.js",
"@ember/debug/ember-inspector-support/adapters/websocket.js": "ember-source/@ember/debug/ember-inspector-support/adapters/websocket.js",
"@ember/debug/ember-inspector-support/container-debug.js": "ember-source/@ember/debug/ember-inspector-support/container-debug.js",
"@ember/debug/ember-inspector-support/data-debug.js": "ember-source/@ember/debug/ember-inspector-support/data-debug.js",
"@ember/debug/ember-inspector-support/debug-port.js": "ember-source/@ember/debug/ember-inspector-support/debug-port.js",
"@ember/debug/ember-inspector-support/deprecation-debug.js": "ember-source/@ember/debug/ember-inspector-support/deprecation-debug.js",
"@ember/debug/ember-inspector-support/general-debug.js": "ember-source/@ember/debug/ember-inspector-support/general-debug.js",
"@ember/debug/ember-inspector-support/index.js": "ember-source/@ember/debug/ember-inspector-support/index.js",
"@ember/debug/ember-inspector-support/libs/capture-render-tree.js": "ember-source/@ember/debug/ember-inspector-support/libs/capture-render-tree.js",
"@ember/debug/ember-inspector-support/libs/promise-assembler.js": "ember-source/@ember/debug/ember-inspector-support/libs/promise-assembler.js",
"@ember/debug/ember-inspector-support/libs/render-tree.js": "ember-source/@ember/debug/ember-inspector-support/libs/render-tree.js",
"@ember/debug/ember-inspector-support/libs/source-map.js": "ember-source/@ember/debug/ember-inspector-support/libs/source-map.js",
"@ember/debug/ember-inspector-support/libs/view-inspection.js": "ember-source/@ember/debug/ember-inspector-support/libs/view-inspection.js",
"@ember/debug/ember-inspector-support/main.js": "ember-source/@ember/debug/ember-inspector-support/main.js",
"@ember/debug/ember-inspector-support/models/profile-manager.js": "ember-source/@ember/debug/ember-inspector-support/models/profile-manager.js",
"@ember/debug/ember-inspector-support/models/profile-node.js": "ember-source/@ember/debug/ember-inspector-support/models/profile-node.js",
"@ember/debug/ember-inspector-support/models/promise.js": "ember-source/@ember/debug/ember-inspector-support/models/promise.js",
"@ember/debug/ember-inspector-support/object-inspector.js": "ember-source/@ember/debug/ember-inspector-support/object-inspector.js",
"@ember/debug/ember-inspector-support/port.js": "ember-source/@ember/debug/ember-inspector-support/port.js",
"@ember/debug/ember-inspector-support/promise-debug.js": "ember-source/@ember/debug/ember-inspector-support/promise-debug.js",
"@ember/debug/ember-inspector-support/render-debug.js": "ember-source/@ember/debug/ember-inspector-support/render-debug.js",
"@ember/debug/ember-inspector-support/route-debug.js": "ember-source/@ember/debug/ember-inspector-support/route-debug.js",
"@ember/debug/ember-inspector-support/services/session.js": "ember-source/@ember/debug/ember-inspector-support/services/session.js",
"@ember/debug/ember-inspector-support/utils/base-object.js": "ember-source/@ember/debug/ember-inspector-support/utils/base-object.js",
"@ember/debug/ember-inspector-support/utils/bound-method.js": "ember-source/@ember/debug/ember-inspector-support/utils/bound-method.js",
"@ember/debug/ember-inspector-support/utils/classify.js": "ember-source/@ember/debug/ember-inspector-support/utils/classify.js",
"@ember/debug/ember-inspector-support/utils/dasherize.js": "ember-source/@ember/debug/ember-inspector-support/utils/dasherize.js",
"@ember/debug/ember-inspector-support/utils/ember-object-names.js": "ember-source/@ember/debug/ember-inspector-support/utils/ember-object-names.js",
"@ember/debug/ember-inspector-support/utils/ember/object/internals.js": "ember-source/@ember/debug/ember-inspector-support/utils/ember/object/internals.js",
"@ember/debug/ember-inspector-support/utils/evented.js": "ember-source/@ember/debug/ember-inspector-support/utils/evented.js",
"@ember/debug/ember-inspector-support/utils/get-object-name.js": "ember-source/@ember/debug/ember-inspector-support/utils/get-object-name.js",
"@ember/debug/ember-inspector-support/utils/name-functions.js": "ember-source/@ember/debug/ember-inspector-support/utils/name-functions.js",
"@ember/debug/ember-inspector-support/utils/on-ready.js": "ember-source/@ember/debug/ember-inspector-support/utils/on-ready.js",
"@ember/debug/ember-inspector-support/utils/type-check.js": "ember-source/@ember/debug/ember-inspector-support/utils/type-check.js",
"@ember/debug/ember-inspector-support/view-debug.js": "ember-source/@ember/debug/ember-inspector-support/view-debug.js",
"@ember/debug/index.js": "ember-source/@ember/debug/index.js",
"@ember/debug/lib/assert.js": "ember-source/@ember/debug/lib/assert.js",
"@ember/debug/lib/capture-render-tree.js": "ember-source/@ember/debug/lib/capture-render-tree.js",
Expand Down Expand Up @@ -372,4 +414,4 @@
"node": "16.20.0",
"pnpm": "8.10.0"
}
}
}
156 changes: 156 additions & 0 deletions packages/@ember/debug/ember-inspector-support/adapters/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/* eslint no-console: 0 */
import BaseObject from '../utils/base-object';
import { DEBUG } from '@glimmer/env';
import { onReady } from '../utils/on-ready';

export default class BasicAdapter extends BaseObject {
private _messageCallbacks: any[] = [];
private __environment = '';
declare interval: number | undefined;
init() {
Promise.resolve(this.connect()).then(() => {
this.onConnectionReady();
}, null);

this._messageCallbacks = [];
}

/**
* Uses the current build's config module to determine
* the environment.
*/
get environment() {
if (!this.__environment) {
this.__environment = DEBUG ? 'development' : 'production';
}
return this.__environment;
}

debug(...args: any[]) {
return console.debug(...args);
}

log(...args: any[]) {
return console.log(...args);
}

/**
* A wrapper for `console.warn`.
*
*/
warn(...args: any[]) {
return console.warn(...args);
}

/**
Used to send messages to EmberExtension

@param {Object} type the message to the send
*/
sendMessage(_options: any) {}

/**
Register functions to be called
when a message from EmberExtension is received

@param {Function} callback
*/
onMessageReceived(callback: (msg: any) => void) {
this._messageCallbacks.push(callback);
}

/**
Inspect a js value or specific DOM node. This usually
means using the current environment's tools
to inspect the node in the DOM.

For example, in chrome, `inspect(node)`
will open the Elements tab in dev tools
and highlight the DOM node.
For functions, it will open the sources tab and goto the definition
@param {Node|Function} node
*/
inspectValue(_value: any) {}

_messageReceived(message: any) {
this._messageCallbacks.forEach((callback) => {
callback(message);
});
}

/**
* Handle an error caused by EmberDebug.
*
* This function rethrows in development and test envs,
* but warns instead in production.
*
* The idea is to control errors triggered by the inspector
* and make sure that users don't get mislead by inspector-caused
* bugs.
* @param {Error} error
*/
handleError(error: any) {
if (this.environment === 'production') {
if (error && error instanceof Error) {
error = `Error message: ${error.message}\nStack trace: ${error.stack}`;
}
this.warn(
`Ember Inspector has errored.\n` +
`This is likely a bug in the inspector itself.\n` +
`You can report bugs at https://github.com/emberjs/ember-inspector.\n${error}`
);
} else {
this.warn('EmberDebug has errored:');
throw error;
}
}

/**

A promise that resolves when the connection
with the inspector is set up and ready.
*/
connect() {
return new Promise((resolve, reject) => {
onReady(() => {
if (this.isDestroyed) {
reject();
}
this.interval = setInterval(() => {
if (document.documentElement.dataset['emberExtension']) {
clearInterval(this.interval);
resolve(true);
}
}, 10);
});
});
}

willDestroy() {
super.willDestroy();
clearInterval(this.interval);
}

_isReady = false;
_pendingMessages: any[] = [];

send(options: any) {
if (this._isReady) {
this.sendMessage(options);
} else {
this._pendingMessages.push(options);
}
}

/**
Called when the connection is set up.
Flushes the pending messages.
*/
onConnectionReady() {
// Flush pending messages
const messages = this._pendingMessages;
messages.forEach((options) => this.sendMessage(options));
messages.length = 0;
this._isReady = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import BasicAdapter from './basic';

export default class BookmarkletAdapter extends BasicAdapter {
init() {
super.init();
this._listen();
}

sendMessage(options: any) {
options = options || {};
const w = window as any;
w.emberInspector.w.postMessage(options, w.emberInspector.url);
}

_listen() {
const w = window as any;
window.addEventListener('message', (e) => {
if (e.origin !== w.emberInspector.url) {
return;
}
const message = e.data;
if (message.from === 'devtools') {
this._messageReceived(message);
}
});

window.onunload = () => {
this.sendMessage({
unloading: true,
});
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import WebExtension from './web-extension';
export default class ChromeAdapter extends WebExtension {}
24 changes: 24 additions & 0 deletions packages/@ember/debug/ember-inspector-support/adapters/firefox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint no-empty:0 */
import WebExtension from './web-extension';

export default class FirefoxAdapter extends WebExtension {
debug(...args: unknown[]) {
// WORKAROUND: temporarily workaround issues with firebug console object:
// - https://github.com/tildeio/ember-extension/issues/94
// - https://github.com/firebug/firebug/pull/109
// - https://code.google.com/p/fbug/issues/detail?id=7045
try {
super.debug(...args);
} catch {}
}

log(...args: any[]) {
// WORKAROUND: temporarily workaround issues with firebug console object:
// - https://github.com/tildeio/ember-extension/issues/94
// - https://github.com/firebug/firebug/pull/109
// - https://code.google.com/p/fbug/issues/detail?id=7045
try {
super.log(...args);
} catch {}
}
}
15 changes: 15 additions & 0 deletions packages/@ember/debug/ember-inspector-support/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { default as BasicAdapter } from './basic';
import { default as BookmarkletAdapter } from './bookmarklet';
import { default as ChromeAdapter } from './chrome';
import { default as FirefoxAdapter } from './firefox';
import { default as WebsocketAdapter } from './websocket';
import { default as WebExtensionAdapter } from './web-extension';

export default {
basic: BasicAdapter,
bookmarklet: BookmarkletAdapter,
chrome: ChromeAdapter,
firefox: FirefoxAdapter,
webExtension: WebExtensionAdapter,
websocket: WebsocketAdapter,
};
Loading
Loading