firefox-scripts icon indicating copy to clipboard operation
firefox-scripts copied to clipboard

Download Manager (S3) broken in Firefox v140

Open nanisise opened this issue 5 months ago • 4 comments

At Firefox 140, s3download-4.14.131.2024.09.08 is broken again, I think it is because Firefox removed .jsm importing in Firefox 136, therefore the following code needs to be rewritten:

bootstrap.js Components.utils.import("chrome://s3downbar/content/ChromeManifest.jsm"); Components.utils.import("chrome://s3downbar/content/Overlays.jsm"); Components.utils.import("resource:///modules/CustomizableUI.jsm");

action.js Components.utils.import('resource://gre/modules/History.jsm');

create_new_downloads.js Components.utils.import("resource://gre/modules/BrowserUtils.jsm");

downloads_library.js Components.utils.import("resource://gre/modules/DownloadUtils.jsm");

header.js (2 hits) Components.utils.import("resource://gre/modules/AddonManager.jsm"); Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm", PBU);

launch_on_close.js (4 hits) Components.utils.import("resource://gre/modules/Downloads.jsm"); Components.utils.import("resource://gre/modules/DownloadList.jsm"); Components.utils.import("resource://gre/modules/DownloadCore.jsm"); Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");

Overlays.jsm (4 hits) const { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm"); "resource://gre/modules/Timer.jsm" prefix: "Overlays.jsm", consoleID: "overlays-jsm",

s3downbar.js (4 hits) Components.utils.import("resource://gre/modules/Downloads.jsm"); Components.utils.import("resource://gre/modules/DownloadList.jsm"); Components.utils.import("resource://gre/modules/DownloadCore.jsm"); Components.utils.import("resource://gre/modules/DownloadUIHelper.jsm");

prefs-ce.js (2 hits) const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); ChromeUtils.import("resource://gre/modules/DeferredTask.jsm", module);

shutdown.js (1 hit) Components.utils.import("resource://gre/modules/ctypes.jsm");

utils.js (1 hit) Components.utils.import('resource://gre/modules/History.jsm');

viewer.js (4 hits) Components.utils.import("resource://gre/modules/Downloads.jsm"); Components.utils.import("resource://gre/modules/DownloadList.jsm"); Components.utils.import("resource://gre/modules/DownloadCore.jsm"); Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");

How should I rewrite it?

nanisise avatar Jul 06 '25 10:07 nanisise

I've rewirted the function Components.utils.import, ChromeUtils.import to ChromeUtils.importESModule for all .js files and rewrited all .jsm to .sys.mjs in Download Manager (S3), it seems load sys.mjs normally.

But When clicking download link, function fetchOverlay at Overlays.sys.mjs in Download Manager (S3) is not work, xhr.send(null) always get "NetworkError: A network error occurred." and can't get any data.

fetchOverlay(srcUrl) {
    if (!srcUrl.startsWith("chrome://") && !srcUrl.startsWith("resource://")) {
      throw new Error(
        "May only load overlays from chrome:// or resource:// uris"
      );
    }

    let xhr = new this.window.XMLHttpRequest();
    xhr.overrideMimeType("application/xml");
    xhr.open("GET", srcUrl, false);
    
    // Elevate the request, so DTDs will work. Should not be a security issue since we
    // only load chrome, resource and file URLs, and that is our privileged chrome package.
    try {
      xhr.channel.owner = Services.scriptSecurityManager.getSystemPrincipal();
    } catch (ex) {
      oconsole.error(
        "Failed to set system principal while fetching overlay " + srcUrl
      );
      xhr.close();
      throw new Error("Failed to set system principal");
    }
    xhr.send(null);
    return xhr;
  }

But in Firefox 128, this function works well and has responded data

Image

Any ideas?

nanisise avatar Jul 07 '25 09:07 nanisise

Any ideas?

Use the version of file from other working add-ons.

117649 avatar Jul 09 '25 14:07 117649

I fixed .sys.mjs import issue by referring to the source code of Tab Mix Plus, and also fixed the window resizing issue during launch_on_close. After testing, the Download Manager (S3) now works on Firefox 140.

s3download-4.14.140.2025.07.30-xiao.zip

nanisise avatar Jul 31 '25 02:07 nanisise

New Version Update:

  • Rewrite all inlineJS to addEventListener to fix the CSP restriction issue.
  • Fixed the "Trim the download history to" feature not work. It has been broken for a long time, but now it works properly in this version.

s3download-4.14.140.2025.08.11-xiao.zip

nanisise avatar Aug 11 '25 08:08 nanisise

New Version Update:

* Rewrite all inlineJS to addEventListener to fix the CSP restriction issue.

* Fixed the "Trim the download history to" feature not work. It has been broken for a long time, but now it works properly in this version.

s3download-4.14.140.2025.08.11-xiao.zip

Does this version actually allow you to open the settings/options page? I get no response.

Avrution avatar Dec 18 '25 19:12 Avrution