aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2020-12-29 14:16:25 -0800
committerOmar Rizwan <omar@omar.website>2020-12-29 14:16:25 -0800
commit1185e6885c1dc935592ad14cb0955a9d57dc20e7 (patch)
treebdc1be74c35c0a16d7aac8ca3e733d8f4527c1a4 /extension
parent6c56c525f22ae97977c466c25e3726a23fa04887 (diff)
ability to read scripts/file with path filtering
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/extension/background.js b/extension/background.js
index 5cb3a8c..51a2bbd 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -296,16 +296,21 @@ router["/tabs/by-id/*/control"] = {
return { entries: [".", "..", ...scriptFileNames] };
}
};
+ function pathScriptInfo(tabId, path) {
+ const [scriptId, ...rest] = pathComponent(path, -1).split("_");
+ const scriptInfo = TabManager.scriptsForTab[tabId][scriptId];
+ if (!scriptInfo || sanitize(scriptInfo.url).slice(0, 200) !== rest.join("_")) {
+ throw new UnixError(unix.ENOENT);
+ }
+ return scriptInfo;
+ }
router["/tabs/by-id/*/debugger/scripts/*"] = defineFile(async path => {
const [tabId, suffix] = [parseInt(pathComponent(path, -4)), pathComponent(path, -1)];
await TabManager.debugTab(tabId);
await TabManager.enableDomainForTab(tabId, "Page");
await TabManager.enableDomainForTab(tabId, "Debugger");
- const parts = pathComponent(path, -1).split("_"); const scriptId = parts[0];
- // TODO: check the script title in path vs the actual script title
- if (!TabManager.scriptsForTab[tabId][scriptId]) { throw new UnixError(unix.ENOENT); }
-
+ const {scriptId} = pathScriptInfo(tabId, path);
const {scriptSource} = await sendDebuggerCommand(tabId, "Debugger.getScriptSource", {scriptId});
return scriptSource;
@@ -313,10 +318,7 @@ router["/tabs/by-id/*/control"] = {
const [tabId, suffix] = [parseInt(pathComponent(path, -4)), pathComponent(path, -1)];
await TabManager.debugTab(tabId); await TabManager.enableDomainForTab(tabId, "Debugger");
- const parts = path.split("_"); const scriptId = parts[0];
- // TODO: check the script title in path vs the actual script title
- if (!TabManager.scriptsForTab[tabId][scriptId]) { throw new UnixError(unix.ENOENT); }
-
+ const {scriptId} = pathScriptInfo(tabId, path);
await sendDebuggerCommand(tabId, "Debugger.setScriptSource", {scriptId, scriptSource: buf});
});
})();