xiaoxiaoflood / firefox-scripts

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

config.js stop working on Firefox Nightly 101.0a1 #127

Closed onemen closed 2 years ago

onemen commented 2 years ago

config.js stop working on Firefox Nightly 101.0a1 build 20220407092959

Cu.import(Services.io.newFileURI(Services.dirsvc.get('ProfD', Ci.nsIFile)).spec + 'chrome/utils/boot.jsm');

the line above throw the error: Uncaught DOMException: Component returned failure code: 0x80530012 [nsIXPCComponents_Utils.import]

this error code is for DOMException: The operation is insecure

ghcsd commented 2 years ago

https://hg.mozilla.org/mozilla-central/rev/fafb7b2268f385506c5c650c819ac89f8a5b1648

onemen commented 2 years ago

@xiaoxiaoflood ,

This change fix this issue, can you test it.

config.js

// skip 1st line
lockPref('xpinstall.signatures.required', false);

Object = Cu.getGlobalForObject(Cu).Object;
const { freeze } = Object;
Object.freeze = obj => {
  if (Components.stack.caller.filename != 'resource://gre/modules/AppConstants.jsm')
    return freeze(obj);

  obj.MOZ_REQUIRE_SIGNING = false;
  Object.freeze = freeze;
  return freeze(obj);
}

try {
  const { Services } = Cu.import('resource://gre/modules/Services.jsm');
- Cu.import(Services.io.newFileURI(Services.dirsvc.get('ProfD', Ci.nsIFile)).spec + 'chrome/utils/boot.jsm');
+ const url = Services.io.newFileURI(Services.dirsvc.get('ProfD', Ci.nsIFile)).spec + 'chrome/utils/boot.jsm';
+ Services.scriptloader.loadSubScript(url, {});
} catch (ex) { };

boot.jsm

    let EXPORTED_SYMBOLS = [];

    let cmanifest = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties).get('UChrm', Ci.nsIFile);
    cmanifest.append('utils');
    cmanifest.append('chrome.manifest');
    Components.manager.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(cmanifest);

-   ChromeUtils.import('chrome://userchromejs/content/BootstrapLoader.jsm');
+   Cu.import('chrome://userchromejs/content/BootstrapLoader.jsm');

-   ChromeUtils.import('chrome://userchromejs/content/userChrome.jsm');
+   Cu.import('chrome://userchromejs/content/userChrome.jsm');
onemen commented 2 years ago

Better option

config.js

// skip 1st line
lockPref('xpinstall.signatures.required', false);

Object = Cu.getGlobalForObject(Cu).Object;
const { freeze } = Object;
Object.freeze = obj => {
  if (Components.stack.caller.filename != 'resource://gre/modules/AppConstants.jsm')
    return freeze(obj);

  obj.MOZ_REQUIRE_SIGNING = false;
  Object.freeze = freeze;
  return freeze(obj);
}

try {
- const { Services } = Cu.import('resource://gre/modules/Services.jsm');
- Cu.import(Services.io.newFileURI(Services.dirsvc.get('ProfD', Ci.nsIFile)).spec + 'chrome/utils/boot.jsm');
+  let cmanifest = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties).get('UChrm', Ci.nsIFile);
+  cmanifest.append('utils');
+  cmanifest.append('chrome.manifest');
+  Components.manager.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(cmanifest);

+  Cu.import('chrome://userchromejs/content/boot.jsm');
} catch (ex) { };

boot.jsm

    let EXPORTED_SYMBOLS = [];

-   let cmanifest = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties).get('UChrm', Ci.nsIFile);
-   cmanifest.append('utils');
-   cmanifest.append('chrome.manifest');
-   Components.manager.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(cmanifest);

    ChromeUtils.import('chrome://userchromejs/content/BootstrapLoader.jsm');

    ChromeUtils.import('chrome://userchromejs/content/userChrome.jsm');
xiaoxiaoflood commented 2 years ago

Thanks.