xiaoxiaoflood / firefox-scripts

userChromeJS / autoconfig.js and extensions
Mozilla Public License 2.0
941 stars 83 forks source link

ucjsDownloadsManager.uc.js won't open window in Firefox 120 #289

Open LummoxJR opened 8 months ago

LummoxJR commented 8 months ago

So I know these reports are mostly just for the community to act on at this point, but it appears Firefox 120 has broken the part of the download manager script that opens the window. The offending line is here:

XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");

Apparently XPCOMUtils.defineLazyModuleGetter() has been removed, and this is the problem.

According to the same document I found that in, they're "ESMifying" the browser which is slowly removing more .jsm support in favor of new .esm scripts. I don't know what this entails for the future. There's more information here:

https://groups.google.com/a/mozilla.org/g/firefox-dev/c/od7Bd1QpCuU

This suggests that when Downloads is ESMified in the future, ChromeUtils.defineESModuleGetters() will be needed. For now, however, there's a simple change.

- XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");
+ // disabled for now because XPCOMUtils.defineLazyModuleGetter() has been removed; revisit when lazy getters for ESM are in place
+ //XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");
+ this.Downloads = ChromeUtils.import('resource://gre/modules/Downloads.jsm').Downloads;
LummoxJR commented 8 months ago

There appear to be further issues with lacking a Clear Downloads button, so I'll keep investigating. The font has gone wonky too. It looks like window.ucjs_downloadManagerMain() is failing with an error, which causes the init not to complete successfully. The download box does open however.

benzBrake commented 8 months ago

Where did you download ucjsDownloadsManager.uc.js?4 months ago The XPCOMUtils.defineLazyModuleGetter line was changed to ChromeUtils.defineESModuleGetters。https://github.com/alice0775/userChrome.js/blob/824ae9ae02a91a21ad6e8703f9f8cdf8941bd0a8/117/ucjsDownloadsManager.uc.js#L105C7-L107

LummoxJR commented 8 months ago

Ah, my script might be out of date then. I'll take a look and compare to see what else I need to change.

LummoxJR commented 8 months ago

So I updated to Alice's newest version for 117 and it didn't fix the issue, as of its current build. Looks like I'll need to report a bug there at some point. The remaining error I had was in ucjs_downloadManagerMain.init():

            // xxx remove in-content css
-           var elements = document.childNodes;
-           for (var i = 0; i <= elements.length; i++) {
-               var element = elements[i];
-               if (element.nodeValue && element.nodeValue.indexOf("chrome://browser/skin/downloads/contentAreaDownloadsView.css") > -1) {
-                   document.removeChild(element);
-                   break;
-               }
-           }
+           let element = document.querySelector('link[href$="skin/downloads/contentAreaDownloadsView.css"]');
+           if(element) element.parentNode.removeChild(element);

There are two problems with the old code. The first is that the <= in that loop was wrong all along, but it never triggered because of the fact that the loop was finding the right element before and breaking out before it got beyond the length of the array. The second problem is because this search for the CSS link was brittle, when the structure of the download manager changed in Firefox 120 it no longer found the old CSS link to remove.