Skip to content

Commit

Permalink
Merge branch 'master' into no-deep-clone
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner committed Dec 18, 2019
2 parents 50ac13b + e9ebeda commit 794dfb5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
9 changes: 6 additions & 3 deletions app/adapters/web-extension.js
Expand Up @@ -80,10 +80,13 @@ export default BasicAdapter.extend({
* Open the devtools "Elements" tab and select a specific DOM node.
*
* @method inspectDOMNode
* @param {String} selector XPath selector
* @param {String} name
*/
inspectDOMNode(selector) {
chrome.devtools.inspectedWindow.eval(`inspect($x('${selector}')[0])`);
inspectDOMNode(name) {
chrome.devtools.inspectedWindow.eval(`
inspect(window[${JSON.stringify(name)}]);
delete window[${JSON.stringify(name)}];
`);
},

/**
Expand Down
4 changes: 2 additions & 2 deletions app/routes/component-tree.js
Expand Up @@ -58,8 +58,8 @@ export default TabRoute.extend({
this.set('controller.inspectingViews', false);
},

inspectDOMNode({ selector }) {
this.get('port.adapter').inspectDOMNode(selector);
inspectDOMNode({ name }) {
this.port.adapter.inspectDOMNode(name);
},

actions: {
Expand Down
12 changes: 6 additions & 6 deletions ember_debug/adapters/basic.js
Expand Up @@ -60,17 +60,17 @@ export default EmberObject.extend({
},

/**
Inspect a specific element. This usually
Inspect a specific DOM node. This usually
means using the current environment's tools
to inspect the element in the DOM.
to inspect the node in the DOM.
For example, in chrome, `inspect(elem)`
For example, in chrome, `inspect(node)`
will open the Elements tab in dev tools
and highlight the element.
and highlight the DOM node.
@param {DOM Element} elem
@param {Node} node
*/
inspectElement(/* elem */) {},
inspectNode(/* node */) {},

_messageReceived(message) {
this._messageCallbacks.forEach(callback => {
Expand Down
43 changes: 27 additions & 16 deletions ember_debug/adapters/web-extension.js
Expand Up @@ -32,24 +32,35 @@ export default BasicAdapter.extend({
},

/**
* Open the devtools "Elements" and select an element.
* Open the devtools "Elements" and select an DOM node.
*
* NOTE:
* This method was supposed to call `inspect` which is a Chrome specific function
* that can either be called from the console or from code evaled using `inspectedWindow.eval`
* (which is how this code is executed). See https://developer.chrome.com/extensions/devtools#evaluating-js.
* However for some reason Chrome 52+ has started throwing an Error that `inspect`
* is not a function when called from this code. The current workaround is to
* message the Ember Ibspector asking it to execute `inspected.Window.eval('inspect(element)')`
* for us.
*
* @param {HTMLElement} elem The element to select
* @param {Node} node The DOM node to select
*/
inspectElement(elem) {
/* inspect(elem); */
this.get('namespace.port').send('view:inspectDOMNode', {
selector: `//*[@id="${elem.getAttribute('id')}"]`
});
inspectNode(node) {
// NOTE:
//
// Basically, we are just trying to call `inspect(node)` here.
// However, `inspect` is a special function that is in the global
// scope but not on the global object (i.e. `window.inspect`) does
// not work. This sometimes causes problems, because, e.g. if the
// page has a div with the ID `inspect`, `window.inspect` will point
// to that div and shadown the "global" inspect function with no way
// to get it back. That causes "`inspect` is not a function" errors.
//
// As it turns out, however, when the extension page evals, the
// `inspect` function does not get shadowed. So, we can ask the
// inspector extension page to call that function for us, using
// `inspected.Window.eval('inspect(node)')`.
//
// However, since we cannot just send the DOM node directly to the
// extension, we will have to store it in a temporary global variable
// so that the extension can find it.

let name = `__EMBER_INSPECTOR_${(Math.random() * 100000000).toFixed(0)}`;

window[name] = node;

this.get('namespace.port').send('view:inspectDOMNode', { name });
},

_listen() {
Expand Down
2 changes: 1 addition & 1 deletion ember_debug/view-debug.js
Expand Up @@ -168,7 +168,7 @@ export default EmberObject.extend(PortMixin, {
* @param {Element} element The element to inspect
*/
inspectElement(element) {
this.get('adapter').inspectElement(element);
this.get('adapter').inspectNode(element);
},

sendTree() {
Expand Down

0 comments on commit 794dfb5

Please sign in to comment.