OLD | NEW |
(Empty) | |
| 1 <script> |
| 2 |
| 3 var receivedEvents = []; |
| 4 var devtoolsTabEvents = undefined; |
| 5 |
| 6 function tabUrlChangeListener() { |
| 7 receivedEvents.push("onTabUrlChange"); |
| 8 } |
| 9 |
| 10 function pageEventListener() { |
| 11 receivedEvents.push("onPageEvent"); |
| 12 } |
| 13 |
| 14 function tabCloseListener() { |
| 15 receivedEvents.push("onTabClose"); |
| 16 } |
| 17 |
| 18 function setListenersOnTab(tabId) { |
| 19 try { |
| 20 devtoolsTabEvents = chrome.devtools.getTabEvents(tabId); |
| 21 devtoolsTabEvents.onPageEvent.addListener(pageEventListener); |
| 22 devtoolsTabEvents.onTabUrlChange.addListener(tabUrlChangeListener); |
| 23 devtoolsTabEvents.onTabClose.addListener(tabCloseListener); |
| 24 window.domAutomationController.send(true); |
| 25 } catch(e) { |
| 26 window.domAutomationController.send(false); |
| 27 } |
| 28 } |
| 29 |
| 30 function testReceiveTabUrlChangeEvent() { |
| 31 if (receivedEvents.length == 1) { |
| 32 var eventName = receivedEvents.pop(); |
| 33 window.domAutomationController.send(eventName === "onTabUrlChange"); |
| 34 } else { |
| 35 receivedEvents = []; |
| 36 window.domAutomationController.send(false); |
| 37 } |
| 38 } |
| 39 |
| 40 function testReceivePageEvent() { |
| 41 if (receivedEvents.length == 1) { |
| 42 var eventName = receivedEvents.pop(); |
| 43 window.domAutomationController.send(eventName === "onPageEvent"); |
| 44 } else { |
| 45 receivedEvents = []; |
| 46 window.domAutomationController.send(false); |
| 47 } |
| 48 } |
| 49 |
| 50 function testReceiveTabCloseEvent() { |
| 51 if (receivedEvents.length == 1) { |
| 52 var eventName = receivedEvents.pop(); |
| 53 window.domAutomationController.send(eventName === "onTabClose"); |
| 54 } else { |
| 55 receivedEvents = []; |
| 56 window.domAutomationController.send(false); |
| 57 } |
| 58 } |
| 59 |
| 60 function unregisterListeners() { |
| 61 devtoolsTabEvents.onPageEvent.removeListener(pageEventListener); |
| 62 devtoolsTabEvents.onTabUrlChange.removeListener(tabUrlChangeListener); |
| 63 devtoolsTabEvents.onTabClose.removeListener(tabCloseListener); |
| 64 window.domAutomationController.send(true); |
| 65 } |
| 66 |
| 67 </script> |
OLD | NEW |