Skip to content

Commit

Permalink
#7 - triggering clean up when the devtools panel is closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Joseph committed May 14, 2015
1 parent 19b8a49 commit e7a1dad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ chrome.runtime.onConnect.addListener(function(port){
port.onMessage.removeListener(panelListener);

var tabs = Object.keys(panelConnections);
for (var i=0, len=tabs.length; i < len; i++) {
for (var i = 0, len = tabs.length; i < len ; i++) {
if (panelConnections[tabs[i]] == port) {
delete panelConnections[tabs[i]];
// On panel closing, clean up the tab from all wrapped functions and removes the injector.js
contentScriptConnections[tabs[i]].postMessage({
task: 'cleanUpInspectedApp',
source: 'angular-performance'
});
break;
}
}
Expand Down
8 changes: 8 additions & 0 deletions extension/src/injected/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ window.addEventListener('message', function(event) {
return;
}

if (message.task === 'removeInspector'){
// removes the inspector from the DOM
var inspector = document.getElementById("angular-performance-inspector");
inspector.parentNode.removeChild(inspector);
return;
}

backgroundPageConnection.postMessage(message);
}, false);

Expand All @@ -129,6 +136,7 @@ USER_EVENTS.forEach(function(eventType){
// Add injected script to the page
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'angular-performance-inspector';
script.src = chrome.extension.getURL('src/injected/inspector.js');
document.head.appendChild(script);

Expand Down
4 changes: 3 additions & 1 deletion extension/src/injected/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
case 'cleanUpInspectedApp':
_isMonitoringActive = false;
cleanUpInspectedApp();
// Once everything is cleaned up, we can remove this script from the DOM
sendTask('removeInspector');
break;
}
});
Expand Down Expand Up @@ -451,7 +453,7 @@
* Reports a metric
*
* @param {String} task - task to do
* @param {Object} value - data that can be sent along with the task
* @param {Object} [value] - data that can be sent along with the task
*/
function sendTask(task, value){
window.postMessage({
Expand Down

0 comments on commit e7a1dad

Please sign in to comment.