Reputation: 1053
I'm trying to create a Dev Tools panel to inspect the origin private file system, as it's apparently missing from the Storage panel in the latest version (115) of Firefox LTS.
However, when using browser.tabs.executeScript
, this code prints "dir.keys() result has 0 entries" to the tab's dev tools console:
/* my_devtools_panel.js */
async function executeScript() {
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools#running_code_in_the_target_window
return await browser.runtime.sendMessage({ command: 'executeScript', arguments: Array.from(arguments) });
}
let dir_ls = await executeScript(
browser.devtools.inspectedWindow.tabId, // TODO is there any way to do this short of "<all_urls>"?
{ code: `(async () => {
// TRY PASTING THIS BLOCK OF CODE DIRECTLY INTO THE DEV TOOLS CONSOLE INSTEAD:
let dir = await navigator.storage.getDirectory();
console.debug("Browser directory: %o", dir);
let dir_ls = await Array.fromAsync(dir.keys());
console.debug("dir.keys() result has %d entries: %o", dir_ls.length, dir_ls);
return dir_ls;
})()`, runAt: 'document_start' }
).then((result) => result[0]);
debugger;
document.body.appendChild(document.createTextNode(`[${dir_ls.join()}] (length: ${dir_ls.length})`));
/* background.js */
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Extending_the_developer_tools#running_code_in_the_target_window
switch (sender.id) {
case browser.runtime.id:
switch (message.command) {
case 'executeScript':
return browser.tabs.executeScript(...message.arguments);
}
}
});
I do in fact have an entry in that folder, and if I paste that "code" script into the tab's dev tools console directly it's found.
What am I doing wrong?
Upvotes: 2
Views: 110