Close a Firefox tab programmatically?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JJohnston2
Posts: 204
Joined: 24 Jun 2015, 23:38

Close a Firefox tab programmatically?

15 Jan 2016, 01:28

I have some Firefox tabs that quit responding to normal keystrokes when ieTab is loaded (or maybe ieTab2, presumably an IE instance either way).

Typically...
  • SendInput ^w would close a Firefox tab
And for better reliability using ieTab...
  • SendInput ^{F4} works with fewer hiccups
Sometimes when these tabs load however, Firefox will be active but the keystrokes get dropped, including anything pressed on the physical keyboard (i.e., non-scripted keystrokes get dropped also during these cases).

When this happens the keystrokes will be dropped indefinitely if the window remains active in its current state. To make the window responsive to the keyboard, the active window either has to be changed (and changed back, i.e., go to a different program and come back), or the content area of the active tab has to be clicked on and then the keystrokes will start working. Most of the time.

Wondering if anyone has any ideas for programmatically closing a Firefox tab. I could still use a keystroke for something else, so long as it triggers the tab to close 100% of the time... for example loading another Firefox extension would be fine, even if its only function was to help close the active tab. I found one that adds another button (somewhere else of your choosing on the Firefox GUI), but it doesn't support a shortcut key as far as I can tell. Also, moving the mouse probably won't work for what I need to do, so a Control-Click would work for example if I could get a control reference that would work like that, but moving the mouse to click on a set of X/Y coordinates would not.

I also found this post to get the active browser URL, but not sure if an adaptation of some of that code could possibly work or not.

Trying to come up with ideas for a way that might make an automated close happen a little more reliably besides the keystrokes that are randomly not working now.

I also haven't had much luck distinguishing between native tabs and ieTabs, although there are two possible methods that come to mind for possibly determining that information... that would be possibly helpful if there is a special function to close just the ieTab (without the requirement for that function to work on native tabs). That would still require figuring out how to close the ieTab though, even if I could detect that it was an ieTab.
AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Close a Firefox tab programmatically?

27 Jan 2016, 17:49

Just a bump. I'm also wondering if AHK can be of use in controlling Firefox tabs.

Increasingly I find that FF responds inconsistently to Ctrl+Tab and Ctrl+Shift+Tab, which let you switch forward and backward between the last two tabs. That has always been a problem with certain kinds of content (eg., YouTube and other Flash-heavy pages (or similar, eg, NetFlix) where a video window has taken control of the page. But it is increasingly common on apparently plain pages. My concern is that over the long run, keyboard tab-switching is going to fall by the wayside as Firefox and page designers focus less on keyboard compatibility and usability in favor of mobile-inspired navigation. :(
When this happens the keystrokes will be dropped indefinitely if the window remains active in its current state. To make the window responsive to the keyboard, the active window either has to be changed (and changed back, i.e., go to a different program and come back), or the content area of the active tab has to be clicked on and then the keystrokes will start working. Most of the time.
Yep. That's exactly what I'm finding with simple tab switching, though sometimes mouse-switching to a new tab will get it responsive again. FF is now telling me to update to FF 44.0, and I know that one of these updates will see the end of keyboard switching, if not by design then by simple neglect.

Doing this kind of AHK scripting is way beyond my ability, but I'd be happy to test and give operational feedback on any solutions that anyone comes up with.

BTW, FWIW, I'm not currently running the ieTab plugin, so that's not what's behind the tab-keyboard-non-responsivness I've been seeing recently.
JJohnston2
Posts: 204
Joined: 24 Jun 2015, 23:38

Re: Close a Firefox tab programmatically?

29 Jan 2016, 02:46

Yup... I have the same annoyance with YouTube.
JJohnston2
Posts: 204
Joined: 24 Jun 2015, 23:38

Re: Close a Firefox tab programmatically?

01 Feb 2016, 13:48

AHKxx wrote:Increasingly I find that FF responds inconsistently to Ctrl+Tab and Ctrl+Shift+Tab, which let you switch forward and backward between the last two tabs. That has always been a problem with certain kinds of content (eg., YouTube and other Flash-heavy pages (or similar, eg, NetFlix) where a video window has taken control of the page. But it is increasingly common on apparently plain pages. My concern is that over the long run, keyboard tab-switching is going to fall by the wayside as Firefox and page designers focus less on keyboard compatibility and usability in favor of mobile-inspired navigation. :(
It looks like I may have been able to solve the ieTab2 annoyance by setting the runinprocess option true via about:config.

You may be able to try something similar with flash by setting a similar option dom.ipc.plugins.flash.disable-protected-mode=true

https://support.mozilla.org/en-US/questions/1059974

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Draken, Rikk03 and 158 guests