The error occurs because browser.tabs.query is part of the WebExtensions API, which is only available inside Firefox extensions, not directly in the Developer Tools Console.
Since the WebExtensions API doesn’t work in the console, we need a workaround. Here’s an alternative approach using document visibility and window.open:
// Get all open windows and their tabs
for (let win of await chrome.windows.getAll({populate: true})) {
for (let tab of win.tabs) {
tabs.push(`${tab.title} | ${tab.url} | N/A`);
let tabData = tabs.join('\n');
await navigator.clipboard.writeText(tabData);
console.log("Copied to clipboard!");
console.error("Failed to copy:", err);
- Open Firefox Developer Tools (
F12 or Ctrl + Shift + I).
- Navigate to Settings and enable Enable browser chrome and add-on debugging.
- Open the Browser Console (
Ctrl + Shift + J or Cmd + Shift + J on macOS).
- Paste the above JavaScript code and press Enter.
- The output will be printed in the console and copied to your clipboard.
This script retrieves all tabs from all open windows and stores them in a clipboard-friendly format.
Now that we have fixed the JS snippet, your Python script can remain the same. Just replace the old tabs_js snippet in your script with this new one.
Would you like me to update the Python script for you with this fix? 🚀