This repository was archived by the owner on Feb 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 339
Fix crash introduced in v0.10.8 and slightly improve loader #311
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ function brokerMessage(message, sender) { | |
transformMessage(tabId, message); | ||
bufferData(tabId, message); | ||
} | ||
|
||
if (devToolsPort) { | ||
devToolsPort.postMessage(message); | ||
} | ||
|
@@ -47,8 +48,8 @@ function transformMessage(tabId, message) { | |
} | ||
|
||
if (message.event === 'model:change') { | ||
message.data.value = (typeof message.data.value === 'undefined') ? | ||
undefined : JSON.parse(message.data.value) | ||
message.data.value = (message.data.value === undefined) ? | ||
undefined : JSON.parse(message.data.value); | ||
} | ||
} | ||
|
||
|
@@ -71,13 +72,18 @@ function bufferData(tabId, message) { | |
} | ||
|
||
if (message.event === 'scope:new') { | ||
tabData.scopes[message.data.child] = { | ||
parent: message.data.parent, | ||
var childId = message.data.child; | ||
var parentId = message.data.parent; | ||
var parentScopeData = tabData.scopes[parentId]; | ||
|
||
tabData.scopes[childId] = { | ||
parent: parentId, | ||
children: [], | ||
models: {} | ||
}; | ||
if (tabData.scopes[message.data.parent]) { | ||
tabData.scopes[message.data.parent].children.push(message.data.child); | ||
|
||
if (parentScopeData) { | ||
parentScopeData.children.push(childId); | ||
} | ||
} else if (message.data.id && (scope = tabData.scopes[message.data.id])) { | ||
if (message.event === 'scope:destroy') { | ||
|
@@ -101,8 +107,7 @@ function bufferData(tabId, message) { | |
// context script –> background | ||
chrome.runtime.onMessage.addListener(brokerMessage); | ||
|
||
chrome.runtime.onConnect.addListener(function(devToolsPort) { | ||
|
||
chrome.runtime.onConnect.addListener(function (devToolsPort) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is it with adding spaces after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It falls under the random changes category 😃 |
||
devToolsPort.onMessage.addListener(registerInspectedTabId); | ||
|
||
function registerInspectedTabId(inspectedTabId) { | ||
|
@@ -122,7 +127,6 @@ chrome.runtime.onConnect.addListener(function(devToolsPort) { | |
|
||
//devToolsPort.onMessage.removeListener(registerInspectedTabId); | ||
} | ||
|
||
}); | ||
|
||
chrome.tabs.onRemoved.addListener(function (tabId) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,47 @@ | ||
var panels = chrome && chrome.devtools && chrome.devtools.panels; | ||
var elementsPanel = panels && panels.elements; | ||
|
||
if (elementsPanel) { | ||
elementsPanel.createSidebarPane('$scope', function onSidebarCreated(sidebar) { | ||
elementsPanel.onSelectionChanged.addListener(function updateElementProperties() { | ||
sidebar.setExpression('(' + getPanelContents.toString() + ')()'); | ||
}); | ||
|
||
// AngularJS panel | ||
panels.create('AngularJS', 'img/angular.png', 'panel/app.html'); | ||
}); | ||
} | ||
|
||
// The function below is executed in the context of the inspected page. | ||
function getPanelContents() { | ||
var angular = window.angular; | ||
var panelContents = {}; | ||
|
||
var getPanelContents = function () { | ||
if (window.angular && $0) { | ||
//TODO: can we move this scope export into updateElementProperties | ||
if (angular && $0) { | ||
var scope = getScope($0); | ||
|
||
// Export $scope to the console | ||
window.$scope = scope; | ||
return (function (scope) { | ||
var panelContents = { | ||
__private__: {} | ||
}; | ||
|
||
for (prop in scope) { | ||
if (scope.hasOwnProperty(prop)) { | ||
if (prop.substr(0, 2) === '$$') { | ||
panelContents.__private__[prop] = scope[prop]; | ||
} else { | ||
panelContents[prop] = scope[prop]; | ||
} | ||
} | ||
} | ||
return panelContents; | ||
}(scope)); | ||
} else { | ||
return {}; | ||
|
||
// Get sidebar contents | ||
panelContents.__private__ = {}; | ||
Object.keys(scope).forEach(function (prop) { | ||
var dest = (prop.substr(0, 2) === '$$') ? panelContents.__private__ : panelContents; | ||
dest[prop] = scope[prop]; | ||
}); | ||
} | ||
|
||
return panelContents; | ||
|
||
// Helpers | ||
function getScope(node) { | ||
var scope = window.angular.element(node).scope(); | ||
var scope = angular.element(node).scope(); | ||
if (!scope) { | ||
// Might be a child of a DocumentFragment... | ||
while (node && node.nodeType === 1) node = node.parentNode; | ||
if (node && node.nodeType === 11) node = (node.parentNode || node.host); | ||
return getScope(node); | ||
while (node && node.nodeType === Node.ELEMENT_NODE) node = node.parentNode; | ||
if (node && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) node = node.parentNode || node.host; | ||
return node && getScope(node); | ||
} | ||
return scope; | ||
} | ||
}; | ||
|
||
panels && panels.elements.createSidebarPane( | ||
"$scope", | ||
function (sidebar) { | ||
panels.elements.onSelectionChanged.addListener(function updateElementProperties() { | ||
sidebar.setExpression("(" + getPanelContents.toString() + ")()"); | ||
}); | ||
|
||
// Angular panel | ||
var angularPanel = panels.create( | ||
"AngularJS", | ||
"img/angular.png", | ||
"panel/app.html" | ||
); | ||
}); | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note that this change no longer modifies the
tabData.scope
object. Is that on purpose?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does. I just stored some properties as local var (
childScopeData = tabData.scopes[childId]
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At no point do you write to
tabData.scopes[message.data.child]
any moreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
childScopeData
never gets assigned onto thetabData.scopes
object.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG, you are right 😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this was used to "hydrate" the Scopes view when the DevTools would open, at which point the DevTools app would take over maintaining the scopes info. With my incorrect change, the scopes would not be hydrated when you opened DevTools, so you needed to refresh the app with the DevTools open.
Thx for watching out for my blunders 😃
It really sucks that there are no substancial tests. Hoping to fix it some time.