firefox title bar contains url information

Post your working scripts, libraries and tools.
black-peak
Posts: 4
Joined: 26 Apr 2021, 08:23

firefox title bar contains url information

Post by black-peak » 28 Jan 2023, 22:59

firefox is my main browser, and I need to get the url of the current tab frequently. usually we use acc(), or send hotkeys. But both have various problems, too slow or unstable.
Actually we can modify the omni.ja file to achieve a faster and safer method.
Find "\browser\omni.ja", unzip it with unzip.exe, modify "tabbrowser.js" and compress it with zip.exe.

For example, I open YouTube and my firefox title is.


I modified two places.
1, removed " - Mozilla Firefox" from the title, if the title is blank, set the title to "null"

Code: Select all

tab_js_str := strReplace(tab_js_str, "let dataSuffix", "if (title)`nreturn  title;`nelse`nreturn `"null`";`nlet dataSuffix")
2, append the url to the title.

Code: Select all

rs := "
(
	updateTitlebar() {
		   let uri = this.selectedBrowser.documentURI;
		   if (uri)
				 document.title = this.getWindowTitleForBrowser(this.selectedBrowser) + " || " + uri.spec;
		   else
				 document.title = this.getWindowTitleForBrowser(this.selectedBrowser);
	},
)"

tab_js_str := RegExReplace(tab_js_str, "Uim)updateTitlebar\(\)\s+\{[^\}]+\},", rs)

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: firefox title bar contains url information

Post by neogna2 » 29 Jan 2023, 16:59

I didn't know this, thanks for posting it.

It isn't an AutoHotkey script though so might fit better in the "Tips and tricks" forum section or perhaps "Other programming languages".

I think v2 Acc can be both quick and stable in getting the current tab in Firefox.

black-peak
Posts: 4
Joined: 26 Apr 2021, 08:23

Re: firefox title bar contains url information

Post by black-peak » 29 Jan 2023, 21:16

If I wrap two code snippets into one library e.g. set_firefox_tab_js(), do you still think it's not appropriate to post here?

Get the window title, which will take less than 50 µs, with almost no errors, or big deviations.
acc() gets the url, and it takes 50 ms at the fastest, it doesn't have the slowest because it depends on how firefox reacts, if firefox is in the middle of a massive page load, acc() will be very slow, 1-5 seconds is common.

neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: firefox title bar contains url information

Post by neogna2 » 30 Jan 2023, 03:46

black-peak wrote:
29 Jan 2023, 21:16
If I wrap two code snippets into one library e.g. set_firefox_tab_js(), do you still think it's not appropriate to post here?
This subforum's description says "Share the finished AutoHotkey v2 Scripts and libraries you made here" so if the topic is about manual modification of some javascript files then I'd think another subforum is a better home. If on the other hand an AutoHotkey script did all the described steps (unzip, modify, re-zip) then I'd say it fits here.

I'm not a mod though! If a mod sees this and thinks it should be moved they probably will move it for you so no worries.
black-peak wrote:
29 Jan 2023, 21:16
Get the window title, which will take less than 50 µs, with almost no errors, or big deviations.
acc() gets the url, and it takes 50 ms at the fastest, it doesn't have the slowest because it depends on how firefox reacts, if firefox is in the middle of a massive page load, acc() will be very slow, 1-5 seconds is common.
Ok, I underestimated how fast you needed it to be. I assumed 50 ms would be plenty fast. I haven't encountered situations where page load slows Acc URL reading to several seconds. Maybe I'm underestimating what you mean by massive page load too?

Post Reply

Return to “Scripts and Functions (v2)”