summaryrefslogtreecommitdiff
path: root/extension/background.js
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2021-02-22 16:31:30 -0800
committerOmar Rizwan <omar@omar.website>2021-02-22 16:31:49 -0800
commit063051d80b7b160fda4cbb8e5bbcc39d455ab7d4 (patch)
tree019843322c5d966526a1ffe3faf916fac130560f /extension/background.js
parentad80383242a719192cf08af0747c4e1d8478a0cd (diff)
downloadTabFS-063051d80b7b160fda4cbb8e5bbcc39d455ab7d4.tar.gz
TabFS-063051d80b7b160fda4cbb8e5bbcc39d455ab7d4.zip
remove TAB/console and TAB/execute-script which are ugly
(and not really necessary now that we have evals, I think? like, as long as you have some way to run JS on the content script, you can build other functionality out of that)
Diffstat (limited to 'extension/background.js')
-rw-r--r--extension/background.js81
1 files changed, 0 insertions, 81 deletions
diff --git a/extension/background.js b/extension/background.js
index 8aaadbb..85adbe8 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -247,87 +247,6 @@ router["/tabs/by-id"] = {
buf => ({ active: buf.startsWith("true") }));
})();
(function() {
- let nextConsoleFh = 0; let consoleForFh = {};
- chrome.runtime.onMessage.addListener(data => {
- if (!consoleForFh[data.fh]) return;
- consoleForFh[data.fh].push(data.xs);
- });
- router["/tabs/by-id/*/console"] = {
- // this one is a bit weird. it doesn't start tracking until it's opened.
- // tail -f console
- async getattr() {
- return {
- st_mode: unix.S_IFREG | 0444,
- st_nlink: 1,
- st_size: 0 // FIXME
- };
- },
- async open({path}) {
- const tabId = parseInt(pathComponent(path, -2));
- const fh = nextConsoleFh++;
- const code = `
-// runs in 'content script' context
-var script = document.createElement('script');
-var code = \`
- // will run both here in content script context and in
- // real Web page context (so we hook console.log for both)
- (function() {
- if (!console.__logOld) console.__logOld = console.log;
- if (!console.__logFhs) console.__logFhs = new Set();
- console.__logFhs.add(${fh});
- console.log = (...xs) => {
- console.__logOld(...xs);
- try {
- // TODO: use random event for security instead of this broadcast
- for (let fh of console.__logFhs) {
- window.postMessage({fh: ${fh}, xs: xs}, '*');
- }
- // error usually if one of xs is not serializable
- } catch (e) { console.error(e); }
- };
- })()
-\`;
-eval(code);
-script.appendChild(document.createTextNode(code));
-(document.body || document.head).appendChild(script);
-
-window.addEventListener('message', function({data}) {
- if (data.fh !== ${fh}) return;
- // forward to the background script
- chrome.runtime.sendMessage(null, data);
-});
-`;
- consoleForFh[fh] = [];
- await browser.tabs.executeScript(tabId, {code});
- return {fh};
- },
- async read({path, fh, offset, size}) {
- const all = consoleForFh[fh].join('\n');
- // TODO: do this more incrementally ?
- // will probably break down if log is huge
- const buf = String.fromCharCode(...toUtf8Array(all).slice(offset, offset + size));
- return { buf };
- },
- async release({path, fh}) {
- const tabId = parseInt(pathComponent(path, -2));
- // TODO: clean up the hooks inside the contexts
- delete consoleForFh[fh];
- return {};
- }
- };
-})();
-router["/tabs/by-id/*/execute-script"] = {
- // note: runs in a content script, _not_ in the Web page context
- async write({path, buf}) {
- // FIXME: chunk this properly (like if they write a script in
- // multiple chunks) and only execute when ready?
- const tabId = parseInt(pathComponent(path, -2));
- await browser.tabs.executeScript(tabId, {code: buf});
- return {size: stringToUtf8Array(buf).length};
- },
- async truncate({path, size}) { return {}; }
-};
-(function() {
let evals = {};
router["/tabs/by-id/*/evals"] = {
async readdir({path}) {