fx140: Add ChromeUtils.import() shim for plugins

We can decide if we want to keep this, but it's an easy change that
seems useful for dev builds.
This commit is contained in:
Abe Jellinek 2025-07-01 17:04:22 -04:00 • committed by Dan Stillman
parent f0ac59f3dc
commit 9d6669eb1e

View file

@ -174,6 +174,22 @@ Zotero.Plugins = new function () {
}
);
// fx140: Shim ChromeUtils.import() in the plugin scope
// TODO: Do we want this?
scope.ChromeUtils = new Proxy(scope.ChromeUtils, {
get(target, property, receiver) {
if (property === 'import') {
return function (uri) {
let esmURI = uri.replace('.jsm', uri.includes('/zotero/') ? '.mjs' : '.sys.mjs');
Zotero.warn('ChromeUtils.import() has been removed. Use importESModule():\n'
+ ` ChromeUtils.importESModule("${esmURI}");`);
return receiver.importESModule(esmURI);
};
}
return Reflect.get(target, property, receiver);
}
});
scopes.set(addon.id, scope);
try {