diff options
author | Omar Rizwan <omar.rizwan@gmail.com> | 2020-12-02 20:24:20 -0800 |
---|---|---|
committer | Omar Rizwan <omar.rizwan@gmail.com> | 2020-12-02 20:24:20 -0800 |
commit | 22aaeaa9e139e960c7b8c819962e7ff0de95ff71 (patch) | |
tree | b3281133240666fd332fb5d21a8755e99b6d937f /extension/background.js | |
parent | 506751b3d5b2b479ffe703acdac8fb595646ab25 (diff) |
base64 reads. start working on screenshot stuff.
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/extension/background.js b/extension/background.js index 759bd0d..3132f48 100644 --- a/extension/background.js +++ b/extension/background.js @@ -138,6 +138,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/*/screenshot.png"] = { + async read({path, fh, size, offset}) { + const tabId = parseInt(pathComponent(path, -2)); + await debugTab(tabId); + await sendDebuggerCommand(tabId, "Page.enable", {}); + + const {data} = await sendDebuggerCommand(tabId, "Page.captureScreenshot"); + const arr = Uint8Array.from(atob(data), c => c.charCodeAt(0)); + const slice = arr.slice(offset, offset + size); + return { buf: String.fromCharCode(...slice) }; + } +}; router["/tabs/by-id/*/resources"] = { async opendir({path}) { const tabId = parseInt(pathComponent(path, -2)); @@ -367,6 +379,7 @@ async function onMessage(req) { try { response = await findRoute(req.path)[req.op](req); response.op = req.op; + if (response.buf) response.buf = btoa(response.buf); } catch (e) { console.error(e); |