aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-04 17:40:03 -0800
committerOmar Rizwan <omar@omar.website>2020-12-04 17:40:03 -0800
commit34c16fec0d045902052c1e3b2572f19f53b8a06f (patch)
tree403dd250e4d3046cfad1038fda27ddc7ecf0e7bb /extension
parente4c92ac4e988ca8fd9d5063d5288cb5f6b261b9c (diff)
extension: improve debug attach reliability
(by forcing detach first for tabs that already have an attached debugger -- this crops up a lot if I reload the extension, the old extension ver stays hanging -- and by attaching before we open/getattr files too, not just when we open the dir) (it seems pretty solid now)
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js25
1 files changed, 14 insertions, 11 deletions
diff --git a/extension/background.js b/extension/background.js
index 16e127c..e44fb9d 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -85,9 +85,13 @@ async function debugTab(tabId) {
debugging[tabId] += 1;
} else {
- await new Promise((resolve, reject) => chrome.debugger.attach({tabId}, "1.3", () => {
+ await new Promise((resolve, reject) => chrome.debugger.attach({tabId}, "1.3", function callback() {
if (chrome.runtime.lastError) {
- reject(chrome.runtime.lastError);
+ if (chrome.runtime.lastError.message.indexOf('Another debugger is already attached') !== -1) {
+ chrome.debugger.detach({tabId}, callback);
+ } else {
+ reject(chrome.runtime.lastError);
+ }
} else {
debugging[tabId] = 1;
resolve();
@@ -99,11 +103,7 @@ function sendDebuggerCommand(tabId, method, commandParams) {
return new Promise((resolve, reject) =>
chrome.debugger.sendCommand({tabId}, method, commandParams, result => {
console.log(method, result);
- if (result) {
- resolve(result);
- } else {
- reject(chrome.runtime.lastError);
- }
+ if (result) { resolve(result); } else { reject(chrome.runtime.lastError); }
})
);
}
@@ -194,7 +194,7 @@ router["/tabs/by-id/*/resources/*"] = {
const tabId = parseInt(pathComponent(path, -3));
const suffix = pathComponent(path, -1);
- if (!debugging[tabId]) throw new UnixError(unix.EIO);
+ await debugTab(tabId);
await sendDebuggerCommand(tabId, "Page.enable", {});
@@ -219,6 +219,8 @@ router["/tabs/by-id/*/resources/*"] = {
},
async open({path}) {
// FIXME: cache the file
+ const tabId = parseInt(pathComponent(path, -3));
+ await debugTab(tabId);
return {fh: 3};
},
async read({path, fh, size, offset}) {
@@ -238,7 +240,7 @@ router["/tabs/by-id/*/resources/*"] = {
url: resource.url
});
if (base64Encoded) {
- const arr = Uint8Array.from(atob(data), c => c.charCodeAt(0));
+ const arr = Uint8Array.from(atob(content), c => c.charCodeAt(0));
const slice = arr.slice(offset, offset + size);
return { buf: String.fromCharCode(...slice) };
} else {
@@ -249,6 +251,7 @@ router["/tabs/by-id/*/resources/*"] = {
throw new UnixError(unix.ENOENT);
},
async release({path, fh}) {
+ // FIXME: free the debug?
return {};
}
};
@@ -400,7 +403,7 @@ function findRoute(path) {
let port;
async function onMessage(req) {
if (req.buf) req.buf = atob(req.buf);
- console.log('req', req);
+ /* console.log('req', req);*/
let response = { op: req.op, error: unix.EIO };
/* console.time(req.op + ':' + req.path);*/
@@ -418,7 +421,7 @@ async function onMessage(req) {
}
/* console.timeEnd(req.op + ':' + req.path);*/
- console.log('resp', response);
+ /* console.log('resp', response);*/
port.postMessage(response);
};