mirror of
https://github.com/osnr/TabFS.git
synced 2024-05-08 08:36:33 +02:00
Switch to browser namespace so we can use Promises.
This commit is contained in:
parent
543dc7d4b2
commit
44d5a7ed3c
|
@ -24,13 +24,6 @@ function UnixError(error) {
|
||||||
}
|
}
|
||||||
UnixError.prototype = Error.prototype;
|
UnixError.prototype = Error.prototype;
|
||||||
|
|
||||||
function getTab(id) {
|
|
||||||
return new Promise((resolve, reject) => chrome.tabs.get(id, resolve));
|
|
||||||
}
|
|
||||||
function queryTabs() {
|
|
||||||
return new Promise((resolve, reject) => chrome.tabs.query({}, resolve));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function debugTab(tabId) {
|
async function debugTab(tabId) {
|
||||||
if (!debugged[tabId]) {
|
if (!debugged[tabId]) {
|
||||||
await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
|
await new Promise(resolve => chrome.debugger.attach({tabId}, "1.3", resolve));
|
||||||
|
@ -83,7 +76,7 @@ const router = {
|
||||||
*/
|
*/
|
||||||
"by-title": {
|
"by-title": {
|
||||||
async readdir() {
|
async readdir() {
|
||||||
const tabs = await queryTabs();
|
const tabs = await browser.tabs.query({});
|
||||||
return tabs.map(tab => sanitize(String(tab.title).slice(0, 200)) + "_" + String(tab.id));
|
return tabs.map(tab => sanitize(String(tab.title).slice(0, 200)) + "_" + String(tab.id));
|
||||||
},
|
},
|
||||||
"*": {
|
"*": {
|
||||||
|
@ -105,29 +98,30 @@ const router = {
|
||||||
},
|
},
|
||||||
"by-id": {
|
"by-id": {
|
||||||
async readdir() {
|
async readdir() {
|
||||||
const tabs = await queryTabs();
|
const tabs = await browser.tabs.query({});
|
||||||
return tabs.map(tab => String(tab.id));
|
return tabs.map(tab => String(tab.id));
|
||||||
},
|
},
|
||||||
|
|
||||||
"*": {
|
"*": {
|
||||||
"url": {
|
"url": {
|
||||||
async read(path, fh, size, offset) {
|
async read(path, fh, size, offset) {
|
||||||
const tab = await getTab(parseInt(pathComponent(path, -2)));
|
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
||||||
return (tab.url + "\n").substr(offset, size);
|
return (tab.url + "\n").substr(offset, size);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"title": {
|
"title": {
|
||||||
async read(path, fh, size, offset) {
|
async read(path, fh, size, offset) {
|
||||||
const tab = await getTab(parseInt(pathComponent(path, -2)));
|
const tab = await browser.tabs.get(parseInt(pathComponent(path, -2)));
|
||||||
return (tab.title + "\n").substr(offset, size);
|
return (tab.title + "\n").substr(offset, size);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"text": {
|
"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));
|
||||||
await debugTab(tabId);
|
const {result} = await chrome.tabs.executeScript(tabId, {code: "console.log('hi'); document.body.innerText;"});
|
||||||
await sendDebuggerCommand(tabId, "Runtime.enable", {});
|
/* await debugTab(tabId);
|
||||||
const {result} = await sendDebuggerCommand(tabId, "Runtime.evaluate", {expression: "document.body.innerText", returnByValue: true});
|
* await sendDebuggerCommand(tabId, "Runtime.enable", {});
|
||||||
|
* 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)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,12 +5,16 @@
|
||||||
"description": "Connects to TabFS filesystem",
|
"description": "Connects to TabFS filesystem",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
|
||||||
"permissions": ["tabs", "debugger", "nativeMessaging", "unlimitedStorage"],
|
"permissions": [
|
||||||
|
"tabs", "debugger", "nativeMessaging",
|
||||||
|
"unlimitedStorage",
|
||||||
|
"*://*/*"
|
||||||
|
],
|
||||||
|
|
||||||
"browser_action": {},
|
"browser_action": {},
|
||||||
|
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["background.js"],
|
"scripts": ["vendor/browser-polyfill.js", "background.js"],
|
||||||
"persistent": true
|
"persistent": true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
1224
extension/vendor/browser-polyfill.js
vendored
Normal file
1224
extension/vendor/browser-polyfill.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue