aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2020-11-22 11:52:08 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2020-11-22 11:52:08 -0800
commit374d794f73f5b81cc18275603ee3b5be44b7c23e (patch)
treec186e7039bd835b74c1d3f7e9f37b0b146558046 /extension
parent6b54c8ec6bc329a4fd7656627dae9ab44acb7936 (diff)
add last-focused to make testing easier
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/extension/background.js b/extension/background.js
index b467eec..5201080 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -139,6 +139,33 @@ router["/tabs/by-id/*/resources"] = {
}
};
router["/tabs/by-id/*/resources/*"] = {
+ async getattr(path) {
+ 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) {
+ content = atob(content);
+ }
+ return {
+ st_mode: unix.S_IFREG | 0444,
+ st_nlink: 1,
+ st_size: stringSize(content) // FIXME
+ };
+ }
+ }
+ },
async read(path, fh, size, offset) {
const tabId = parseInt(pathComponent(path, -3));
const suffix = pathComponent(path, -1);
@@ -163,6 +190,9 @@ router["/tabs/by-id/*/resources/*"] = {
}
}
throw new UnixError(unix.ENOENT);
+ },
+ async release(path, fh) {
+ return {};
}
};
@@ -201,6 +231,24 @@ router["/tabs/by-title/*"] = {
}
};
+router["/tabs/last-focused"] = {
+ // a symbolic link to /tabs/by-id/[id for this tab]
+ async getattr(path) {
+ const st_size = (await this.readlink(path)).length + 1;
+ return {
+ st_mode: unix.S_IFLNK | 0444,
+ st_nlink: 1,
+ // You _must_ return correct linkee path length from getattr!
+ st_size
+ };
+ },
+ async readlink(path) {
+ const windowId = (await browser.windows.getLastFocused()).id;
+ const id = (await browser.tabs.query({ active: true, windowId }))[0].id;
+ return "by-id/" + id;
+ }
+}
+
/* "last-focused": {
* // FIXME: symlink to tab by id.
* async readlink() {