Need help 🙏 #75
-
I'm trying to write my own first little script, but got stuck with this question — and it seems really hard to find proper documentation on gBrowser and all that stuff these days... Could you please tell me, is it possible to add a listener to execute code whenever new "browser" element is about to be added to the browser DOM? I would like to modify some of it's attributes. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 15 replies
-
What attributes are you trying to modify? Some attributes may need to be set before the element connects, others could be set at any point. |
Beta Was this translation helpful? Give feedback.
-
Maybe you should override gBrowser.createBrowser? |
Beta Was this translation helpful? Give feedback.
-
Yes, it's possible to override it from a user script. Why wouldn't it be? There is no event that fires precisely when a browser element is created, and even if there was, that wouldn't let you modify it before it connects to the document. It's much better to change how the element is created than to try to hook into its creation from outside. |
Beta Was this translation helpful? Give feedback.
-
Check the scripts in my repo, most of them override methods gBrowser.createBrowser = function (...) {
...
} |
Beta Was this translation helpful? Give feedback.
-
Well you gotta make sure you're overriding the method with a method that actually works. It needs to have all the existing behavior plus the behavior you want to add. |
Beta Was this translation helpful? Give feedback.
-
Yeah TabOpen doesn't seem like a good option for your use case, it represents the creation of a tab element (the actual visual tab) and not the linked browser. If you wanna get this happening as early as possible, you can probably do something like this. // ==UserScript==
// @name Make Browsers Transparent
// @version 1.0.0
// @author emvaized
// ==/UserScript==
let gBrowser = window.gBrowser ?? window._gBrowser;
if (gBrowser.createBrowser.name !== "customCreateBrowser") {
eval(
`gBrowser.createBrowser = function customCreateBrowser` +
gBrowser.createBrowser
.toSource()
.replace(/^createBrowser/, "")
.replace(/(\s*)(type: \"content\",)/, `$1$2$1transparent: "true",`)
);
} However, I'm not sure this gets called for the first browser tab at startup. The first tab in a window is special in a lot of ways. You'll have to do some trial and error probably. The later parts in the readme on my repo has a lot of useful links on learning how to do these kinds of mods. The best advice is to get familiar with searching for stuff on searchfox :P |
Beta Was this translation helpful? Give feedback.
-
I just tested the script you provided, and it works just perfect! Even for the first browser tab at startup. Huge thanks👍 However, now a new task arose in my head — it seems sidebar's |
Beta Was this translation helpful? Give feedback.
Check the scripts in my repo, most of them override methods