aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2019-02-28 01:38:22 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2019-02-28 01:38:22 -0800
commitaa3ac637ee3749f4d0fcdd3a39b861b0d969fce7 (patch)
treef0785bc88e3dcfbe1897ce4bb306852e82ecbb69 /extension
parentbc3b35487dbc6353887cb6ede278a0a3eb33612b (diff)
extension: Naming, factor out debugTab, add snapshot+screenshot.
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js44
1 files changed, 33 insertions, 11 deletions
diff --git a/extension/background.js b/extension/background.js
index 750e8a9..7be7aa4 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -31,6 +31,13 @@ function queryTabs() {
return new Promise((resolve, reject) => chrome.tabs.query({}, resolve));
}
+async function debugTab(tabId) {
+ if (!debugged[tabId]) {
+ await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
+ debugged[tabId] = 0;
+ }
+ debugged[tabId] += 1;
+}
function sendDebuggerCommand(tabId, method, commandParams) {
return new Promise((resolve, reject) =>
chrome.debugger.sendCommand({tabId}, method, commandParams, result => {
@@ -115,27 +122,42 @@ const router = {
return (tab.title + "\n").substr(offset, size);
}
},
- "document.body.innerText.txt": {
+ "text": {
async read(path, fh, size, offset) {
const tabId = parseInt(pathComponent(path, -2));
- if (!debugged[tabId]) {
- await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
- debugged[tabId] = 0;
- }
- debugged[tabId] += 1;
+ await debugTab(tabId);
await sendDebuggerCommand(tabId, "Runtime.enable", {});
const {result} = await sendDebuggerCommand(tabId, "Runtime.evaluate", {expression: "document.body.innerText", returnByValue: true});
return result.value.substr(offset, size)
}
},
+ "snapshot.mhtml": {
+ 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.captureSnapshot");
+ return data.substr(offset, size)
+ }
+ },
+ "screenshot.png": {
+ // Broken. Filesystem hangs (? in JS?) and needs to be killed if you read this.
+ 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 buf = btoa(atob(data).substr(offset, size));
+ return { buf, base64Encoded: true };
+ }
+ },
+
"resources": {
async opendir(path) {
const tabId = parseInt(pathComponent(path, -2));
- if (!debugged[tabId]) {
- await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
- debugged[tabId] = 0;
- }
- debugged[tabId] += 1;
+ await debugTab(tabId);
return 0;
},
async readdir(path) {