Detecting current tab URL

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Detecting current tab URL

Unread post by moonbat » 2020-01-10, 10:28

I'm trying to make an overlay extension to play Youtube videos in a separate window.
I want my overlay extension's toolbar button and menu item to only be enabled on the Youtube website. This can happen either when the user manually loads Youtube in the current tab, or switches to another one that already has it open. To this end, it has to monitor both when the current tab loads and when the user switches the active tab and then read the URL. I've added a listener for TabSelect for the latter, how do I detect the former?

If I only listen to TabSelect and switch to an inactive tab (say from my previous session, one that hasn't been loaded yet), then the URL returned is 'about:blank'. Only if I switch away and back to it after it's loaded does it show the URL. How do I also listen for load events on the tab? Just adding "load" doesn't work, that seems to apply only to top level windows.

I'm doing it like so:

Code: Select all

        var container = gBrowser.tabContainer;

        container.addEventListener("TabSelect",PMPlayer.Launch.checkVideoURL,false);
checkVideoURL looks like this -

Code: Select all

    checkVideoURL:function(event){
        var browser=gBrowser.selectedBrowser;
        URI = browser.currentURI;
        PMPlayer.Debug.log("Event type = "+event.type+"\nCurrent URI is "+URI.spec);
    }
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2183
Joined: 2018-05-05, 13:29

Re: Detecting current tab URL

Unread post by vannilla » 2020-01-10, 12:15

I can't help with actual experience, but I found these resources:
https://developer.mozilla.org/en-US/doc ... ed_browser
and
https://developer.mozilla.org/en-US/doc ... n_all_tabs

Maybe you already know them, but I suppose it's better than nothing.

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Detecting current tab URL

Unread post by moonbat » 2020-01-10, 12:34

vannilla wrote:
2020-01-10, 12:15
I can't help with actual experience, but I found these resources:
https://developer.mozilla.org/en-US/doc ... ed_browser
and
https://developer.mozilla.org/en-US/doc ... n_all_tabs

Maybe you already know them, but I suppose it's better than nothing.
I know, I used those snippet to get started. Thanks anyhow.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Isengrim
Board Warrior
Board Warrior
Posts: 1325
Joined: 2015-09-08, 22:54
Location: 127.0.0.1
Contact:

Re: Detecting current tab URL

Unread post by Isengrim » 2020-01-10, 12:52

Reader View does something similar, updating its button in several cases:

Code: Select all

gBrowser.addProgressListener(this.browserWindowListener);
gBrowser.addTabsProgressListener(this.tabsProgressListener);
window.addEventListener("aftercustomization", this.onCustomizeEnd, false);

// Update the button on actual change of the URL.
browserWindowListener: {
  onLocationChange(aWebProgress, aRequest, aLocationURI, aFlags) {
    // Do things
  }
}

// Update the button on anchor navigation and history change.
tabsProgressListener: {
  onLocationChange(aBrowser, aWebProgress, aRequest, aLocationURI, aFlags) {
    // Do things
  }
}

// Update the button after customization.
onCustomizeEnd(aEvent) {
  // Do things
}
So instead of trying to listen to events on the tabcontainer, just use the Progress Listeners on the gbrowser object. I guess it's the same thing, but the code is a little simpler.
a.k.a. Ascrod
Linux Mint 19.3 Cinnamon (64-bit), Debian Bullseye (64-bit), Windows 7 (64-bit)
"As long as there is someone who will appreciate the work involved in the creation, the effort is time well spent." ~ Tetsuzou Kamadani, Cave Story


User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Detecting current tab URL

Unread post by moonbat » 2020-01-10, 13:12

Thanks to both of you, just landed on this page. I'll take a look. One other thing - is it possible to make an icon look greyed out for being disabled using CSS tricks - or do I need a separate greyed out icon image for it?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Isengrim
Board Warrior
Board Warrior
Posts: 1325
Joined: 2015-09-08, 22:54
Location: 127.0.0.1
Contact:

Re: Detecting current tab URL

Unread post by Isengrim » 2020-01-10, 13:26

You might be able to use CSS tricks if your image is an SVG, I'm not sure. I usually use two icons - a colored one and a grayscale one. If you already have a colored icon, you can use any number of free graphics editing programs to create a grayscale one.
a.k.a. Ascrod
Linux Mint 19.3 Cinnamon (64-bit), Debian Bullseye (64-bit), Windows 7 (64-bit)
"As long as there is someone who will appreciate the work involved in the creation, the effort is time well spent." ~ Tetsuzou Kamadani, Cave Story

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Detecting current tab URL

Unread post by moonbat » 2020-01-10, 13:30

Isengrim wrote:
2020-01-10, 13:26
You might be able to use CSS tricks if your image is an SVG, I'm not sure. I usually use two icons - a colored one and a grayscale one. If you already have a colored icon, you can use any number of free graphics editing programs to create a grayscale one.
Thanks. I'll play around with GIMP in that case.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35481
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Detecting current tab URL

Unread post by Moonchild » 2020-01-10, 13:46

There is also css filter to do it on the fly
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4942
Joined: 2015-12-09, 15:45
Contact:

Re: Detecting current tab URL

Unread post by moonbat » 2020-01-16, 01:03

Moonchild wrote:
2020-01-10, 13:46
There is also css filter to do it on the fly
Figured a better way - hiding the button and menu option on pages where they aren't applicable. So they will only show up if the current tab is on Youtube.

I had a couple of other questions for stuff I couldn't figure out from the XUL documentation - should I post them here or start separate threads?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

Locked