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

Firefox Nightly remove support for JSM - All scripts not working

Open onemen opened this issue 11 months ago • 24 comments

Bug 1881888 - Remove support for JSMs landed in Firefox Nightly 136 on 2025-01-25

[userChrome.jsm](https://github.com/xiaoxiaoflood/firefox-scripts/blob/master/chrome/utils /userChrome.jsm) hookFunction.jsm xPref.jsm

stop working

Also config.js need update since ChromeUtils.import was removed

try {
  ChromeUtils.import('chrome://userchromejs/content/userChrome.jsm');
} catch (ex) {};

onemen avatar Jan 24 '25 07:01 onemen

 userChrome.jsm => userChrome.js | 12 +++++++-----
 xPref.jsm => xPref.sys.mjs      |  4 ++--
 2 files changed, 9 insertions(+), 7 deletions(-)
 rename userChrome.jsm => userChrome.js (94%)
 rename xPref.jsm => xPref.sys.mjs (94%)

diff --git a/userChrome.jsm b/userChrome.js
similarity index 94%
rename from userChrome.jsm
rename to userChrome.js
index 17a9224..759fb20 100644
--- a/userChrome.jsm
+++ b/userChrome.js
@@ -1,8 +1,10 @@
-let EXPORTED_SYMBOLS = [];
+'use strict';
 
-const { xPref } = ChromeUtils.import('chrome://userchromejs/content/xPref.jsm');
-const { Management } = ChromeUtils.import('resource://gre/modules/Extension.jsm');
-const { AppConstants } = ChromeUtils.import('resource://gre/modules/AppConstants.jsm');
+ChromeUtils.defineESModuleGetters(this, {
+  xPref: 'chrome://userchromejs/content/xPref.sys.mjs',
+  Management: 'resource://gre/modules/Extension.sys.mjs',
+  AppConstants: 'resource://gre/modules/AppConstants.sys.mjs',
+});
 
 let UC = {
   webExts: new Map(),
@@ -95,7 +97,7 @@ let _uc = {
   },
 
   everLoaded: [],
-  
+
   loadScript: function (script, win) {
     if (!script.regex.test(win.location.href) || (script.filename != this.ALWAYSEXECUTE && !script.isEnabled)) {
       return;
diff --git a/xPref.jsm b/xPref.sys.mjs
similarity index 94%
rename from xPref.jsm
rename to xPref.sys.mjs
index 836b3df..aba56db 100644
--- a/xPref.jsm
+++ b/xPref.sys.mjs
@@ -1,6 +1,6 @@
-let EXPORTED_SYMBOLS = ['xPref'];
+'use strict';
 
-var xPref = {
+export const xPref = {
   // Retorna o valor da preferência, seja qual for o tipo, mas não
   // testei com tipos complexos como nsIFile, não sei como detectar
   // uma preferência assim, na verdade nunca vi uma
--```

onemen avatar Jan 24 '25 08:01 onemen

Brasileiro?

+export const xPref = { // Retorna o valor da preferência, seja qual for o tipo, mas não // testei com tipos complexos como nsIFile, não sei como detectar // uma preferência assim, na verdade nunca vi uma --```

ozzyjr avatar Jan 24 '25 12:01 ozzyjr

  • xPref: 'chrome://userchromejs/content/xPref.sys.mjs',

@onemen .sys isn't a part of the ESM extensions name but a mark of Firefox system modules. So you should not want to use it anywhere. If you want to keep the same format .uc is a go to choice.

117649 avatar Jan 24 '25 16:01 117649

Any chance someone could upload the updated files?

marty60 avatar Jan 24 '25 19:01 marty60

@marty60

Any chance someone could upload the updated files?

I tried to update the files according to onemen's changes, but I still need to update the config.js file to make it work and I don't know how to do that. Also, even if the autoconfig is fixed, it would be necessary to refactor all the scripts since they removed several functions used by the scripts. Unless someone takes care of updating the scripts since @xiaoxiaoflood is missing, it seems to me that this is the end of the scripts and the repository.

kaos-55 avatar Jan 25 '25 20:01 kaos-55

it seems to me that this is the end of the scripts and the repository.

only when that happens.

dimdamin avatar Jan 25 '25 21:01 dimdamin

@marty60

Any chance someone could upload the updated files?

I tried to update the files according to onemen's changes, but I still need to update the config.js file to make it work and I don't know how to do that. Also, even if the autoconfig is fixed, it would be necessary to refactor all the scripts since they removed several functions used by the scripts. Unless someone takes care of updating the scripts since @xiaoxiaoflood is missing, it seems to me that this is the end of the scripts and the repository.

config.js update:

try {
-  ChromeUtils.import('chrome://userchromejs/content/userChrome.jsm');
+  Services.scriptloader.loadSubScript('chrome://userchromejs/content/userChrome.js'); 
} catch (ex) {};

I will try to create a fork to this repository after i finish to update Tab mix Plus

onemen avatar Jan 25 '25 21:01 onemen

@onemen,

try {

  • ChromeUtils.import('chrome://userchromejs/content/userChrome.jsm');
  • Services.scriptloader.loadSubScript('chrome://userchromejs/content/userChrome.js'); } catch (ex) {};

Thanks everyone for the response. The config.js was the problem but this fixed it so now I've got it working again. The files have been uploaded.

Unfortunately three of my addons: keyconfig, saved passwords, and dta are broke and will need to be updated as well so still got some work to do.

chrome-utils folder.zip

autoconfig.zip

Fixed browser.newtab.url script:

newtab-aboutconfig.uc.zip

marty60 avatar Jan 25 '25 22:01 marty60

it seems to me that this is the end of the scripts and the repository.

only when that happens.

@dimdamin

Where did you see that Mozilla plans to end support for autoconfig?

marty60 avatar Jan 25 '25 23:01 marty60

Where did you see that Mozilla plans to end support for autoconfig?

Stop twisting things around, I asked a question with the hope of getting an answer.

dimdamin avatar Jan 26 '25 17:01 dimdamin

Stop twisting things around, I asked a question with the hope of getting an answer.

My apologies if I misunderstood but your posts made it appear as though the removal of autoconfig.js was inevitable. Good to know it isn't.

marty60 avatar Jan 26 '25 18:01 marty60

I use this code to save a string into a file:

		var ostream = Cc['@mozilla.org/network/file-output-stream;1'].createInstance(Ci.nsIFileOutputStream);
		ostream.init(file, -1, -1, 0);
		var istream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
		istream.setUTF8Data(content);
		NetUtil.asyncCopy(istream, ostream, aCallback)

For "NetUtil" I use this code:

		const { NetUtil } = ChromeUtils.import('resource://gre/modules/NetUtil.jsm');

but ChromeUtils.import don't work anymore, and 'resource://gre/modules/NetUtil.jsm' don't exist in FF136.

Does anyone have any idea how to resolve this?


OK, resolved:

ChromeUtils.defineESModuleGetters(this, {
	NetUtil: 'resource://gre/modules/NetUtil.sys.mjs'
});

sdavidg avatar Jan 29 '25 10:01 sdavidg

TMP has been updated.. but it seems .css changes I made in UserStyles folder no longer work.. pretty sure that stuff worked with styloaix ...no longer the case?

XeonG avatar Feb 03 '25 21:02 XeonG

TMP has been updated.. but it seems .css changes I made in UserStyles folder no longer work.. pretty sure that stuff worked with styloaix ...no longer the case?

check in about:config that toolkit.legacyUserProfileCustomizations.stylesheets is true

onemen avatar Feb 03 '25 23:02 onemen

I got it working but it's not working how it used to be.. ie the .css files were in the 'UserStyles' folder that ones styloaix handled I think.. no idea seems a bunch of stuff on this doesn't work still

..css stuff I was using all got chucked into /chrome/userChrome.css and that works.

XeonG avatar Feb 04 '25 00:02 XeonG

In order for the legacy addons to install and work won't BootstrapLoader.jsm and other files in the utils folder have to be updated? Even when trying to fix addons I'm getting an error that the addon appears corrupt when attempting to install it.

marty60 avatar Feb 04 '25 01:02 marty60

In order for the legacy addons to install and work won't BootstrapLoader.jsm and other files in the utils folder have to be updated? Even when trying to fix addons I'm getting an error that the addon appears corrupt when attempting to install it.

They were done. BootstrapLoader.jsm isn't a module script in fact.

117649 avatar Feb 04 '25 05:02 117649

How can I fix this issue entirely? I can't run any of my scripts. Can someone develop the damn fix for all files? It's the year 2025 and not 1930. Technological sufficiency should be enough for a universal fix for all files to be developable for these simple programs/apps.

I can't find any updated files in the comments (except those in chrome-utils.folder.zip).

Firefox Scripts is constantly breaking. CustomJSforFx has not working at all since update 136.0.

By the way, what is happening to humanity? Everything has been breaking in the last decade. Even I was frustrated today because my PC is constantly suddenly shutting down, and restarting it isn't working. My laptop completely broke. My sound tuner broke.

The entire world is upside down. I apologise for speaking off-topic, but it's truth.

Aleksandra0056 avatar Mar 04 '25 18:03 Aleksandra0056

@Aleksandra0056,

If you've updated the chrome-utils.folder and config.js from here:

https://github.com/xiaoxiaoflood/firefox-scripts/issues/343

then from about:config try toggling "security.browser_xhtml_csp.enabled" to false. If the only update needed for the script is event handlers then it should work again in 136+.

As has been posted several times it's only a temporary fix as Mozilla plans to remove that pref in the future but it will buy some time until the scripts can be properly updated.

marty60 avatar Mar 04 '25 19:03 marty60

@Aleksandra0056,

If you've updated the chrome-utils.folder and config.js from here:

#343

then from about:config try toggling "security.browser_xhtml_csp.enabled" to false. If the only update needed for the script is event handlers then it should work again in 136+.

As has been posted several times it's only a temporary fix as Mozilla plans to remove that pref in the future but it will buy some time until the scripts can be properly updated.

Thank you, and I wish you all good luck with the development of fixes. It's true, that Mozilla leadership is turning authoritarian, but I believe, that Firefox is still better than Chrome.

Aleksandra0056 avatar Mar 04 '25 19:03 Aleksandra0056

setting a new tab page also seems to be broken. I used to do it minimally like so:

// Set new tab page to local startpage
let { utils:Cu } = Components;
Cu.import("resource:///modules/AboutNewTab.jsm");
AboutNewTab.newTabURL = "file:///home/faaris/.local/share/startpage/fazzi/index.html";

however this no longer seems to work as of 136

fxzzi avatar Apr 14 '25 14:04 fxzzi

@fxzzi

setting a new tab page also seems to be broken. I used to do it minimally like so:

Use this instead:

let { AboutNewTab } = ChromeUtils.importESModule("resource:///modules/AboutNewTab.sys.mjs");
AboutNewTab.newTabURL = "file:///home/faaris/.local/share/startpage/fazzi/index.html";

All old .jsm file replaced with .sys.mjs file, from now on use only ChromeUtils.importESModule or ChromeUtils.defineESModuleGetters if you want lazy import

ChromeUtils.defineESModuleGetters(lazy, {
  AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
});

onemen avatar Apr 16 '25 14:04 onemen

ty @onemen i found this solution too yesterday but forgot to share ><

https://gitlab.com/fazzi/nixohess/-/blob/main/home/modules/apps/browsers/librewolf/default.nix?ref_type=heads#L39

fxzzi avatar Apr 16 '25 14:04 fxzzi

@fxzzi

setting a new tab page also seems to be broken. I used to do it minimally like so:

Use this instead:

let { AboutNewTab } = ChromeUtils.importESModule("resource:///modules/AboutNewTab.sys.mjs"); AboutNewTab.newTabURL = "file:///home/faaris/.local/share/startpage/fazzi/index.html"; All old .jsm file replaced with .sys.mjs file, from now on use only ChromeUtils.importESModule or ChromeUtils.defineESModuleGetters if you want lazy import

ChromeUtils.defineESModuleGetters(lazy, { AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs", });

Thank you for this fix! I used to replace my homepage in Librewolf (aka Firefox fork) prior to 136 but updated to 140 and it just didn't work anymore. I couldn't be bothered to check what the hell Mozilla did change in their source code yet again, so your comment relieved me of this stress.

For anyone who may need this in the future, here is how I used to set homepage in config.js when Cu.import was still a thing:

try {
	Cu?.import('resource:///modules/AboutNewTab.jsm');
	AboutNewTab.newTabURL=getPref('browser.startup.homepage'); // custom property that points to url with my homepage html

	Cu?.import('resource:///modules/HomePage.jsm');
	HomePage?.set(AboutNewTab?.newTabURL);
}catch(e){ Cu?.reportError(e); }

And here is 136-and-later way of setting homepage:

try {
	defaultPref('browser.startup.homepage', '');

	try {
		Cu?.import('resource:///modules/AboutNewTab.jsm');
	}catch{
		var { AboutNewTab } = ChromeUtils?.importESModule('resource:///modules/AboutNewTab.sys.mjs');
	}finally{
		AboutNewTab.newTabURL=getPref('browser.startup.homepage'); // custom property that points to url with my homepage html
	}

	try {
		Cu?.import('resource:///modules/HomePage.jsm');
	}catch{
		var { HomePage } = ChromeUtils?.importESModule('resource:///modules/HomePage.sys.mjs');
	}finally{
		HomePage?.set(AboutNewTab?.newTabURL);
	}
}catch(e){ Cu?.reportError(e); }

Off topic but this is why I hate updating Firefox/Librewolf to newer versions. Custom userChrome themes, and scripts will just never work out of the box, and I always expect that they somehow will find a way to mess everything up

Edit: Cu in Cu.import is an alias, defined at the top of config.js like this:

// one empty line at the beginning
const { classes:Cc, interfaces:Ci, utils:Cu } = Components;

dazzywi avatar Jul 02 '25 17:07 dazzywi