Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix for a script that attaches a listener to tab/window focus #108

Closed
iax9123 opened this issue Jan 11, 2025 · 7 comments
Closed

Quick fix for a script that attaches a listener to tab/window focus #108

iax9123 opened this issue Jan 11, 2025 · 7 comments
Assignees
Labels
discussion If you just want to discuss something you can use this like a message board thread

Comments

@iax9123
Copy link

iax9123 commented Jan 11, 2025

Hi aminomancer,

I was wondering if you had time to resolve something for my script which was working in Firefox 133.4 but since Firefox 134.0, I seemingly can't reference win.gBrowser anymore..

Usually when something simple like this comes up, I manage to eventually solve it, this time no luck.

Thanks for the help and time.

myprog1.txt

@iax9123 iax9123 added the discussion If you just want to discuss something you can use this like a message board thread label Jan 11, 2025
@aminomancer
Copy link
Owner

Why are all the functions empty?

@aminomancer
Copy link
Owner

If you're using the latest version of fx-autoconfig and you've enabled the startup hack, and it still throws an error, you can try this:

  function init() {
    win.gBrowser.addProgressListener(tabProgressListener);
  }

  if (gBrowserInit.delayedStartupFinished) {
    init();
  } else {
    let delayedListener = (subject, topic) => {
      if (topic == "browser-delayed-startup-finished" && subject == window) {
        Services.obs.removeObserver(delayedListener, topic);
        init();
      }
    };
    Services.obs.addObserver(
      delayedListener,
      "browser-delayed-startup-finished"
    );
  }

@iax9123
Copy link
Author

iax9123 commented Jan 11, 2025

That code did the trick!

Re: empty functions --> I removed the code in the functions to make it easy to read, it was just to test if the eventlistener could be attached.

Thanks for the help- I was at wits end, but knew it was something that should be relatively elementary.

@iax9123 iax9123 closed this as completed Jan 11, 2025
@aminomancer
Copy link
Owner

I wouldn't call it elementary, but it comes up a lot. The gBrowser property doesn't exist on the window at first, it's defined during startup. So there's a chance it's still undefined when your script is executing. It could possibly be referenced at window._gBrowser. IIRC the fx-autoconfig startup hack works like that, but recently I had some scripts stop working for a similar reason. It's probably the same thing you encountered. Those scripts were dependent on the startup hack, which I guess stopped working due to some recent changes to browser startup (CC @MrOtherGuy)

But for those scripts, it was fine and probably ideal to just delay execution until startup is finished. That's why I asked about the empty functions, since I can't say whether delaying would cause problems for your script. If you do run into issues, there are also some alternative ways to add a progress listener without reference to gBrowser... depending on what you're trying to do.

@MrOtherGuy
Copy link

MrOtherGuy commented Jan 11, 2025

Yeah, window._gBrowser was removed a while ago in bug 1930654 when tabbrowser was converted to modern js class. And with that, the "gBrowser hack" stopped working.

There could be some way to make the hack work again, but to be honest I think it would be much better for script authors to delay the execution of functions that actually do depend on gBrowser. In the loader script I could still catch the broken startup and show info banner like currently, but I don't think I want to define some workaround for it anymore.

@iax9123
Copy link
Author

iax9123 commented Jan 11, 2025

I was assuming that the win.gBrowser way of calling things was suddenly removed from the codebase after being deprecated for a while.. but that was my guess. I wasn't expecting that the win.gBrowser was needing to be delayed -- without seeing the code in the function, taking a stab in the dark that it could have been just a matter of delaying it was a good call.

If you are curious, the code reintroduces being able to change the background color and text color of the urlbar based on the url scheme and connection security type. I know you can do some basic styling using only css, but this way allows more effects that closer match what Opera 8-11 had.

@aminomancer
Copy link
Owner

aminomancer commented Jan 12, 2025

without seeing the code in the function, taking a stab in the dark that it could have been just a matter of delaying it was a good call.

You can search all the Firefox source code at https://searchfox.org - here is gBrowser for example. (refresh this, I pasted the wrong link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion If you just want to discuss something you can use this like a message board thread
Projects
None yet
Development

No branches or pull requests

3 participants