aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2020-11-22 04:30:57 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2020-11-22 04:30:57 -0800
commit9517494cd5ca186c78c3e2908b8f81251da4c44d (patch)
tree8412c04ece51cc08d651658492b6df06d943a440 /extension
parent2befcb8db655431865cd07afbdb4e3171f840b12 (diff)
bring back debugging, resources dir
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/extension/background.js b/extension/background.js
index 6406eb4..80567dc 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -56,6 +56,27 @@ function stringSize(str) {
return s + 1;
}
+const debugging = {};
+async function debugTab(tabId) {
+ if (!debugging[tabId]) {
+ await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
+ debugging[tabId] = 0;
+ }
+ debugging[tabId] += 1;
+}
+function sendDebuggerCommand(tabId, method, commandParams) {
+ return new Promise((resolve, reject) =>
+ chrome.debugger.sendCommand({tabId}, method, commandParams, result => {
+ console.log(method, result);
+ if (result) {
+ resolve(result);
+ } else {
+ reject(chrome.runtime.lastError);
+ }
+ })
+ );
+}
+
/* if I could specify a custom editor interface for all the routing
below ... I would highlight the route names in blocks of some color
that sticks out, and let you collapse them. then you could get a
@@ -105,6 +126,18 @@ router["/tabs/by-id"] = {
router["/tabs/by-id/*/url"] = withTab(tab => tab.url + "\n");
router["/tabs/by-id/*/title"] = withTab(tab => tab.title + "\n");
router["/tabs/by-id/*/text"] = fromScript(`document.body.innerText`);
+router["/tabs/by-id/*/resources"] = {
+ async opendir(path) {
+ const tabId = parseInt(pathComponent(path, -2));
+ await debugTab(tabId);
+ return 0;
+ },
+ async entries(path) {
+ const tabId = parseInt(pathComponent(path, -2));
+ const {frameTree} = await sendDebuggerCommand(tabId, "Page.getResourceTree", {});
+ return frameTree.resources.map(r => sanitize(String(r.url).slice(0, 200)));
+ }
+}
router["/tabs/by-id/*/control"] = {
// echo remove >> mnt/tabs/by-id/1644/control
async write(path, buf) {