mirror of
https://github.com/osnr/TabFS.git
synced 2024-06-01 21:42:33 +02:00
extension: Naming, factor out debugTab, add snapshot+screenshot.
This commit is contained in:
parent
bc3b35487d
commit
aa3ac637ee
|
@ -31,6 +31,13 @@ function queryTabs() {
|
||||||
return new Promise((resolve, reject) => chrome.tabs.query({}, resolve));
|
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) {
|
function sendDebuggerCommand(tabId, method, commandParams) {
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
chrome.debugger.sendCommand({tabId}, method, commandParams, result => {
|
chrome.debugger.sendCommand({tabId}, method, commandParams, result => {
|
||||||
|
@ -115,27 +122,42 @@ const router = {
|
||||||
return (tab.title + "\n").substr(offset, size);
|
return (tab.title + "\n").substr(offset, size);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"document.body.innerText.txt": {
|
"text": {
|
||||||
async read(path, fh, size, offset) {
|
async read(path, fh, size, offset) {
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
if (!debugged[tabId]) {
|
await debugTab(tabId);
|
||||||
await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
|
|
||||||
debugged[tabId] = 0;
|
|
||||||
}
|
|
||||||
debugged[tabId] += 1;
|
|
||||||
await sendDebuggerCommand(tabId, "Runtime.enable", {});
|
await sendDebuggerCommand(tabId, "Runtime.enable", {});
|
||||||
const {result} = await sendDebuggerCommand(tabId, "Runtime.evaluate", {expression: "document.body.innerText", returnByValue: true});
|
const {result} = await sendDebuggerCommand(tabId, "Runtime.evaluate", {expression: "document.body.innerText", returnByValue: true});
|
||||||
return result.value.substr(offset, size)
|
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": {
|
"resources": {
|
||||||
async opendir(path) {
|
async opendir(path) {
|
||||||
const tabId = parseInt(pathComponent(path, -2));
|
const tabId = parseInt(pathComponent(path, -2));
|
||||||
if (!debugged[tabId]) {
|
await debugTab(tabId);
|
||||||
await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
|
|
||||||
debugged[tabId] = 0;
|
|
||||||
}
|
|
||||||
debugged[tabId] += 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
async readdir(path) {
|
async readdir(path) {
|
||||||
|
|
Loading…
Reference in a new issue