From 6b54c8ec6bc329a4fd7656627dae9ab44acb7936 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sun, 22 Nov 2020 04:42:16 -0800 Subject: [PATCH] re-add (buggy) resource file support --- extension/background.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/extension/background.js b/extension/background.js index 80567dc..b467eec 100644 --- a/extension/background.js +++ b/extension/background.js @@ -137,7 +137,35 @@ router["/tabs/by-id/*/resources"] = { const {frameTree} = await sendDebuggerCommand(tabId, "Page.getResourceTree", {}); return frameTree.resources.map(r => sanitize(String(r.url).slice(0, 200))); } -} +}; +router["/tabs/by-id/*/resources/*"] = { + async read(path, fh, size, offset) { + const tabId = parseInt(pathComponent(path, -3)); + const suffix = pathComponent(path, -1); + + if (!debugging[tabId]) throw new UnixError(unix.EIO); + + await sendDebuggerCommand(tabId, "Page.enable", {}); + + const {frameTree} = await sendDebuggerCommand(tabId, "Page.getResourceTree", {}); + for (let resource of frameTree.resources) { + const resourceSuffix = sanitize(String(resource.url).slice(0, 200)); + if (resourceSuffix === suffix) { + let {base64Encoded, content} = await sendDebuggerCommand(tabId, "Page.getResourceContent", { + frameId: frameTree.frame.id, + url: resource.url + }); + if (base64Encoded) { + const buf = btoa(atob(content).substr(offset, size)); + return { buf, base64Encoded: true }; + } + return content.substr(offset, size); + } + } + throw new UnixError(unix.ENOENT); + } +}; + router["/tabs/by-id/*/control"] = { // echo remove >> mnt/tabs/by-id/1644/control async write(path, buf) {