From a2e2009ff746670036f48643129ce6fb1e5cc4b7 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Fri, 24 Feb 2023 00:28:36 -0800 Subject: [PATCH] Initial functionality commit --- icons/48.png | Bin 0 -> 1366 bytes manifest.json | 29 +++++++++++++++++++++++++ tab_provenance.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 icons/48.png create mode 100644 manifest.json create mode 100644 tab_provenance.js diff --git a/icons/48.png b/icons/48.png new file mode 100644 index 0000000000000000000000000000000000000000..01fdf18183b36436df680477578a794115e2abdd GIT binary patch literal 1366 zcmV-c1*!UpP)EX>4Tx04R}tkv&MmKpe$iQ?()$K{FI_$WWc^q9Tr3g(6f4wL+^7CYOFelZGV4 z#ZhoAIQX$xb#QUk)xlK|1V2DrU7QqMq{ROvg%+_M9QWhhy~o`bSEbM^1Vqq-L5K>o%{f_4qT~3wM}V()F`m`=+@GUg%h?PFNW`f6M;^|Gt zXA`d?Dkr z#(9ggUaqp{J^2g6Ib&s+>oiA@z#^6)LxPGbN+`oYj8=mb8!6h4ckmB;ewkb6e^ideczg}`lLQ0AaNy!FfAz3hFgat|x zQC2Mc0TRiQ$t5Wpq)8!{vT+@9Sx78ga#>(8HgcEA{rfJ?tKXa%=A9Yy_NLBLzvevW zIlpJl=bYy`=jrD~lK8>$3qM>GfC5ke3P1rU00p1`{>bYqV6lkb9|7?823%eOdwamZ z0Fa&z1O@`z+b%dE$@O&-aQ$g-=eJ~j{&T;Zo6h_A1pw32?yX>BBXE2BpX2W8N~UjU zAXit(wl=xHpn%-jAxB5am>8{pcGmqJczq>LPszMI_jdqubJ~k0lV+Hik)77mXg0H% zEGZHF<>lo2`}abrr^kH&pV3jV6H`+_Muu~{78wb2bpgA(fYAsvH36})A}J3J0Fw#W z-v`#$frJF{#K(&y4Gp#T=kG7;M@J%&O(x*@7|`p1#6%z~%YH02HptFS^65z?bF>2= zvb;==jgePZ#jLk9X z3CYaV+GS;0+s6lph>*uxERKDJgvh#HFY8lNR{lK&pwj_oXJT^q_rUnLNaXo>U}@=l zzQe*~eR2}$=m5OEJqSPohlk=sT3L~8K|un_UGepmb+Z|`yAvmx$3kdwQiRdRH8Q-yKi*@=|NRyZ|F3vOO=)rW&;ti-kNsCMzoJ&*rr? z^7fW|dz0U}xv?KxTuipKka2OJSFuAwj_-liR&sb)+#9y{fb}tK2aulr_Z#ux!2TW> z9Q=BGRn_PH8yl|O#8p+I4wGsjPbG0#84w*Ul6h@S)IUi{Ku(URlj`b(ZE+DuO$GAv zf#hU+KSm=E6(tUXtu5gC8pzHTwUAB+`1#4>z0~J*1)u;FfC5ke3P1rU00p1`6u?iF Y-?1w_u$~=~LI3~&07*qoM6N<$g329m_y7O^ literal 0 HcmV?d00001 diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..2aae6c5 --- /dev/null +++ b/manifest.json @@ -0,0 +1,29 @@ +{ + "manifest_version": 3, + "name": "Tab Provenance", + "description": "Tells you what site you opened a tab from", + "version": "0.1", + + "browser_specific_settings": { + "gecko": { + "id": "tab-provenance@example.com" + } + }, + + "icons": { + "48": "icons/48.png" + }, + + "background": { + "scripts": ["tab_provenance.js"] + }, + + "permissions": [ + "tabs", + "activeTab", + "scripting", + "sessions", + "menus", + "webNavigation" + ] +} diff --git a/tab_provenance.js b/tab_provenance.js new file mode 100644 index 0000000..638f115 --- /dev/null +++ b/tab_provenance.js @@ -0,0 +1,53 @@ +console.log("Initializing Tab Provenance"); +const MENU_ID = "get-opening-tab"; + +browser.runtime.onInstalled.addListener(() => { + browser.menus.create({ + "id": MENU_ID, + "title": "What Opened This?", + "contexts": ["all"] + }); +}); + +browser.runtime.onStartup.addListener(() => { + browser.menus.create({ + "id": MENU_ID, + "title": "What Opened This?", + "contexts": ["all"] + }); +}); + +browser.menus.onClicked.addListener(async (info, tab) => { + if (info.menuItemId === MENU_ID) { + console.log(`Tab id: ${tab.id}`); + const target = { "tabId": tab.id }; + try { + const url = await browser.sessions.getTabValue(tab.id, "provenance"); + console.log(`URL: ${url}`); + const alertMsg = (typeof url === "undefined") ? "No opening url found" : `This tab was opened by: ${url}`; + + const func = (alertMsg) => { + alert(alertMsg); + }; + const args = [alertMsg]; + const injectionResult = await browser.scripting.executeScript({target, args, func}); + + console.log(injectionResult); + + } catch (err) { + console.log(err); + await browser.scripting.executeScript({func: () => { alert("Tab not found"); }, target}); + return; + } + + } +}); +// might want to instead use async functions + +browser.webNavigation.onCreatedNavigationTarget.addListener((details) => { + browser.tabs.get(details.sourceTabId).then((source) => { + browser.sessions.setTabValue(details.tabId, + "provenance", + source.url) // TODO encode more + }); +});