MozillaZine

Code to Clone a Tab?[Solved.]

User Help for Mozilla Firefox
c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 10th, 2017, 3:29 pm

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: 4250
Joined: May 13th, 2012, 10:43 am

Post Posted August 10th, 2017, 4:28 pm

Ctrl + click on 'reload' will open the current page in a new tab. Not sure that's exactly what your looking for though.

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 10th, 2017, 6:05 pm

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.

dickvl

User avatar
 
Posts: 52128
Joined: July 18th, 2005, 3:25 am

Post Posted August 11th, 2017, 10:10 am

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

See BrowserReloadOrDuplicate and duplicateTabIn
https://dxr.mozilla.org/mozilla-release ... er.js#8297

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 11th, 2017, 10:17 am

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: 1794
Joined: March 19th, 2005, 10:51 am

Post Posted August 11th, 2017, 12:42 pm

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.

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 11th, 2017, 12:49 pm

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: 2287
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 11th, 2017, 1:51 pm

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

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 11th, 2017, 4:02 pm

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: 2287
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 11th, 2017, 5:48 pm

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

viewtopic.php?p=11242505#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.

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 11th, 2017, 11:36 pm

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: 2287
Joined: February 3rd, 2009, 6:29 pm

Post Posted August 12th, 2017, 3:37 am

It works for me.

userChromeJS 2.0
Firefox 54.0.1
Windows 7 SP1 32-bit

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 12th, 2017, 8:27 am

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.

dickvl

User avatar
 
Posts: 52128
Joined: July 18th, 2005, 3:25 am

Post Posted August 12th, 2017, 11:26 am

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).

c627627

User avatar
 
Posts: 371
Joined: April 3rd, 2005, 12:58 pm
Location: Kansas

Post Posted August 12th, 2017, 12:36 pm

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.

Return to Firefox Support


Who is online

Users browsing this forum: Google [Bot] and 15 guests