Code to Clone a Tab?[Solved.]

User Help for Mozilla Firefox
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Code to Clone a Tab?[Solved.]

Post by c627627 »

I would like to simply clone a current TAB every time I open a new TAB, that's all.
What is the code to accomplish that without using extensions?
EDIT: Goal is to click on + next to a TAB so that a duplicate TAB is opened.


EDIT EDIT: [RESOLVED] - thanks to morat.
c627627 wrote:
1. userChromeJS extension is installed. http://userchromejs.mozdev.org/

2. File [My Profile]\CHROME\userChrome.js is edited to contain this:

/* Firefox userChrome.js */

if (location == "chrome://browser/content/browser.xul") {
setTimeout(function () {
document.getElementById("cmd_newNavigatorTab").
setAttribute("oncommand",
"duplicateTabIn(gBrowser.selectedTab, 'tab');");
}, 3000);


3. Next I started Firefox with
firefox.exe -purgecaches
Last edited by c627627 on August 12th, 2017, 12:42 pm, edited 5 times in total.
Open the pod bay doors, Cortana.
TheVisitor
Posts: 5469
Joined: May 13th, 2012, 10:43 am

Re: Code to Clone a Tab?

Post by TheVisitor »

Ctrl + click on 'reload' will open the current page in a new tab. Not sure that's exactly what your looking for though.
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

Yes, it still does that but Fx55 has killed Clone Tab extensions, except for Tabs Mix Plus, which miraculously still clones TABs.

I actually asked for this over the years on this forum and no one knew code to have TABs cloned instead of empty when you open a new tab.
That would be an ideal solution.
Open the pod bay doors, Cortana.
User avatar
dickvl
Posts: 54145
Joined: July 18th, 2005, 3:25 am

Re: Code to Clone a Tab?

Post by dickvl »

The Reload button has this attribute:
oncommand="BrowserReloadOrDuplicate(event)"

See BrowserReloadOrDuplicate and duplicateTabIn
https://dxr.mozilla.org/mozilla-release ... er.js#8297
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

Thank you for posting, this is a question that I've been trying to figure out for years.
I am looking for a command to insert so that clicking on + next to a TAB results in its duplicate being opened instead of an empty TAB.
I don't know which of the info to copy-paste and where.
Open the pod bay doors, Cortana.
Brummelchen
Posts: 4480
Joined: March 19th, 2005, 10:51 am

Re: Code to Clone a Tab?

Post by Brummelchen »

to insert so that clicking on + next to a TAB results in its duplicate
not possible in the past, now or future, waste of time.
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

Thank you Brummelchen.
All extensions solely allowing for this have just been broken with release of Fx55.

However, Tab Mix Plus can still do it on Fx55.
I was trying to avoid installing Tab Mix Plus just to get this one little function...
Thank you for clarifying.
Open the pod bay doors, Cortana.
morat
Posts: 6403
Joined: February 3rd, 2009, 6:29 pm

Re: Code to Clone a Tab?

Post by morat »

Try this:

Code: Select all

document.getElementById("cmd_newNavigatorTab").setAttribute("oncommand",
  "duplicateTabIn(gBrowser.selectedTab, 'tab');");
view-source:chrome://browser/content/browser.xul
view-source:chrome://browser/content/browser.js
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

morat, I apologize if my knowledge is not sufficient to follow but this is what I did:

I copy pasted this:

document.getElementById("cmd_newNavigatorTab").setAttribute("oncommand",
"duplicateTabIn(gBrowser.selectedTab, 'tab');");

first into CHROME\userChrome.css and no luck
and then into CHROME\userChrome.js and no luck

Could you tell me what this means:
view-source:chrome://browser/content/browser.xul
view-source:chrome://browser/content/browser.js

Again, sorry for not understanding. Brummelchen said it was not possible through code to click on + next to a TAB and have it cloned instead of a blank TAB, but morat, I remember your user name from many years ago - you helped me actually several times with codes for userChrome.css
Open the pod bay doors, Cortana.
morat
Posts: 6403
Joined: February 3rd, 2009, 6:29 pm

Re: Code to Clone a Tab?

Post by morat »

I assume you are using the userChromeJS extension like in the following thread.

http://forums.mozillazine.org/viewtopic ... #p11242505

Try this:

Code: Select all

/* Firefox userChrome.js */

if (location == "chrome://browser/content/browser.xul") {
  setTimeout(function () {
    document.getElementById("cmd_newNavigatorTab").
      setAttribute("oncommand",
        "duplicateTabIn(gBrowser.selectedTab, 'tab');");
  }, 3000);
}
http://userchromejs.mozdev.org/
http://userchromejs.mozdev.org/faq.html

Instructions:

1. install userChromeJS extension
2. close browser
3. create or edit the userChrome.js file in the chrome folder in the profile folder
4. open browser with the -purgecaches command line option

i.e.

firefox.exe -purgecaches
FirefoxPortable.exe -purgecaches

You have to purge the caches only after creating or editing the userChrome.js file.

P.S.

You cannot change the command with the userChrome.css file.
c627627 wrote:Could you tell me what this means:
view-source:chrome://browser/content/browser.xul
view-source:chrome://browser/content/browser.js
It is just a reference.
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

morat, I am testing this on Firefox ESR 52.
I tried it on a brand new profile.

1. userChromeJS extension is installed.

2. File [My Profile]\CHROME\userChrome.js is edited to contain this:

/* Firefox userChrome.js */

if (location == "chrome://browser/content/browser.xul") {
setTimeout(function () {
document.getElementById("cmd_newNavigatorTab").
setAttribute("oncommand",
"duplicateTabIn(gBrowser.selectedTab, 'tab');");
}, 3000);


3. Next I started Firefox with
firefox.exe -purgecaches

But clicking on + still does not clone the TAB.
Open the pod bay doors, Cortana.
morat
Posts: 6403
Joined: February 3rd, 2009, 6:29 pm

Re: Code to Clone a Tab?

Post by morat »

It works for me.

userChromeJS 2.0
Firefox 54.0.1
Windows 7 SP1 32-bit
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

Brummelchen wrote:
to insert so that clicking on + next to a TAB results in its duplicate
not possible in the past, now or future, waste of time.
Well after further attempts, I can now confirm that morat's code does work!!! Even under the latest official Firefox 55.0.1.
Thank you morat, this was a big deal for me.


Since I have a multi-boot with multiple Firefox versions installed on my system, I rebooted into another OS where Old Fx53 was installed to test, did *NOT* use firefox.exe -purgecaches command but your solution immediately worked there!

I rebooted back and tried using that same profile and it also worked under ESR, then tested it under Firefox 55 to work using the same profile.

Next I used a synchronization program to determine what was making one Profile work and not the other, since both used the same extensions and I even copy-pasted the same userChrome.js, still one worked one did not. After several tries, out of the blue, they both started working. It's not really important why, but for some reason it took a while for one of the profiles for it to kick in, perhaps it has to do with firefox.exe -purgecaches - I don't know. It's not important.

Thank you morat, for coming through again.
Open the pod bay doors, Cortana.
User avatar
dickvl
Posts: 54145
Joined: July 18th, 2005, 3:25 am

Re: Code to Clone a Tab?

Post by dickvl »

Note that you can't downgrade a profile that has been used with Firefox 55 since this version makes major changes to some files that aren't compatible with older Firefox versions (e.g. favicons are stored in a separate SQLite database and no longer in places.sqlite).
User avatar
c627627
Posts: 641
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas City, Missouri
Contact:

Re: Code to Clone a Tab?

Post by c627627 »

I heard that before but when I asked in another thread about that, they told me it was only bookmark icons and browser history that were reset. I asked if there was anything else but it seems only those two things. So favicons are simply remade again as you visit sites and you get a new browser history starting point. They said that it wasn't anything other than that, so it wasn't serious.

But I do have Fx54 Profile saved separately from the upgraded Fx55 profile just in case.
Open the pod bay doors, Cortana.
Post Reply