Skip to content

Instantly share code, notes, and snippets.

@felixr
Last active January 1, 2021 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixr/dec17c245e2c1611f6163d04a25caa19 to your computer and use it in GitHub Desktop.
Save felixr/dec17c245e2c1611f6163d04a25caa19 to your computer and use it in GitHub Desktop.
Proof of concept chrome extension to listen to all tab events
function handleEvent(name, payload) {
fetch('http://localhost:8118/report?'+JSON.stringify({name, payload}));
}
chrome.tabs.onActivated.addListener(
(tabId, windowId) => handleEvent("activated", {tabId, windowId}));
chrome.tabs.onActiveChanged.addListener(
(tabId, selectInfo) => handleEvent("activeChanged", {tabId, selectInfo}));
chrome.tabs.onAttached.addListener(
(tabId, attachInfo) => handleEvent("attached", {tabId, attachInfo}));
chrome.tabs.onDetached.addListener(
(tabId, detachInfo) => handleEvent("detached", {tabId, detachInfo}));
chrome.tabs.onCreated.addListener((tab) => handleEvent("created", {tab}));
chrome.tabs.onHighlightChanged.addListener(
(selectInfo) => handleEvent("highlightChanged", {selectInfo}));
chrome.tabs.onHighlighted.addListener(
(hightlighInfo) => handleEvent("hightlighted", {hightlighInfo}));
chrome.tabs.onMoved.addListener(
(tabId, moveInfo) => handleEvent("moved", {tabId, moveInfo}));
chrome.tabs.onRemoved.addListener(
(tabId, removeInfo) => handleEvent("removed", {tabId, removeInfo}));
chrome.tabs.onReplaced.addListener(
(addedTabId, removedTabId) => handleEvent("replaced", {addedTabId, removedTabId}));
chrome.tabs.onReplaced.addListener(
(addedTabId, removedTabId) => handleEvent("replaced", {addedTabId, removedTabId}));
chrome.tabs.onSelectionChanged.addListener(
(tabId, selectInfo) => handleEvent("selectionChanged", {tabId, selectInfo}));
chrome.tabs.onUpdated.addListener(
(tabId, changeInfo, tab) => handleEvent("updated", {tabId, changeInfo, tab}));
{
"name": "Tab reporter",
"description": "reports tab events",
"version": "0.1",
"permissions": ["tabs", "http://localhost:8118/*"],
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"manifest_version": 2
}
# listen to events
janet -e '(import json) (net/server "0.0.0.0" 8118 (fn [conn] (as-> (net/read conn 4096) _ (string/split " " _) (_ 1) (string/slice _ 8) (string/replace-all "%22" "\"" _) (json/decode _) (pp _)) (net/close conn)))'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment