1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 chrome.debugger.onEvent.addListener(onEvent);
9 chrome.debugger.onDetach.addListener(onDetach);
11 chrome.browserAction.onClicked.addListener(function(tab) {
13 var debuggeeId = {tabId:tabId};
15 if (attachedTabs[tabId] == "pausing")
18 if (!attachedTabs[tabId])
19 chrome.debugger.attach(debuggeeId, version, onAttach.bind(null, debuggeeId));
20 else if (attachedTabs[tabId])
21 chrome.debugger.detach(debuggeeId, onDetach.bind(null, debuggeeId));
24 function onAttach(debuggeeId) {
25 if (chrome.runtime.lastError) {
26 alert(chrome.runtime.lastError.message);
30 var tabId = debuggeeId.tabId;
31 chrome.browserAction.setIcon({tabId: tabId, path:"debuggerPausing.png"});
32 chrome.browserAction.setTitle({tabId: tabId, title:"Pausing JavaScript"});
33 attachedTabs[tabId] = "pausing";
34 chrome.debugger.sendCommand(
35 debuggeeId, "Debugger.enable", {},
36 onDebuggerEnabled.bind(null, debuggeeId));
39 function onDebuggerEnabled(debuggeeId) {
40 chrome.debugger.sendCommand(debuggeeId, "Debugger.pause");
43 function onEvent(debuggeeId, method) {
44 var tabId = debuggeeId.tabId;
45 if (method == "Debugger.paused") {
46 attachedTabs[tabId] = "paused";
47 chrome.browserAction.setIcon({tabId:tabId, path:"debuggerContinue.png"});
48 chrome.browserAction.setTitle({tabId:tabId, title:"Resume JavaScript"});
52 function onDetach(debuggeeId) {
53 var tabId = debuggeeId.tabId;
54 delete attachedTabs[tabId];
55 chrome.browserAction.setIcon({tabId:tabId, path:"debuggerPause.png"});
56 chrome.browserAction.setTitle({tabId:tabId, title:"Pause JavaScript"});