0

Relative URL/path works in overlay XUL, instead of using the full chrome://............

I tried and failed to use it with Components.utils.import(). Is it possible?

Also noticed: Bug 628669 - Provide support for relative URLs in Components utils import (JSM, JS modules)

nmaier
  • 32,336
  • 5
  • 63
  • 78
erosman
  • 7,094
  • 7
  • 27
  • 46

1 Answers1

2

If you study the bug you linked, you'll notice that relative imports where implemented as XPCOMUtils.importRelative().

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.importRelative(this, "bar.jsm");

But this will only work from other code modules, but not overlay scripts or bootstrap.js. For those cases, I'd just write a helper function...

nmaier
  • 32,336
  • 5
  • 63
  • 78
  • I see... actually the intention was to import a `jsm` script from `bootstrap.js` ie `Components.utils.import('local.jsm');` – erosman Jun 28 '14 at 14:46
  • 1
    `bootstrap.js` isn't really relative to any `chrome:` URL anyway (or at least the loader doesn't know that)... It is loaded from some `file:` (unpacked) or `jar:` (XPI) URI and you cannot load those using `Cu.import` anyway. – nmaier Jun 28 '14 at 14:55