Execute content script on window after popup docked

(Casey Smith) #1

I have a background script that creates a popup window when the extension icon is clicked.

var create = browser.windows.create({

On the popup window, there is a button that, when clicked, minimizes the popup window (called in the popup javascript file):


I then execute the content script (called in the popup javascript file):

    browser.tabs.executeScript({file: "/content_scripts/recorder.js"})

But this executes the content script in the popup window. How can I execute the content script in the window that has just been focused when the popup was minimized?

(Martin Giger) #2

By passing the selected tab ID of that other window to executeScript.

(Casey Smith) #3

This is definitely something I overlooked. My only problem now would be getting the correct tab ID. I would like to get the ID of the tab that comes into focus when the popup is docked. When I try to do this, it grabs the ID for the popup window. Do you have any ideas about how I would be able to do this? Thanks!

(Martin Giger) #4

I’d save the focused window ID before opening the popup and then query for the active tab in that window when doing this action.

(jscher2000) #5

I wonder whether it would work more smoothly to drop a panel from the extension’s toolbar button for user interaction, so focus never leaves the target tab. I guess there is a reason you want a separate window.