DevTools/Hacking: Difference between revisions

Update import section for resource://devtools
(→‎Enabling DevTools Assertions: describe when assertions are not enabled)
(Update import section for resource://devtools)
Line 143: Line 143:
Some older DevTools JS modules use the Gecko [https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Using "JavaScript code module"] format with the file extension <tt>.jsm</tt>.  We are trying to move away from this format, so it's unlikely you would add a new one, but you might need to import an existing one in your code.
Some older DevTools JS modules use the Gecko [https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Using "JavaScript code module"] format with the file extension <tt>.jsm</tt>.  We are trying to move away from this format, so it's unlikely you would add a new one, but you might need to import an existing one in your code.


These modules are loaded using <tt>Cu.import()</tt>.  To <tt>import()</tt> a file, you provide a <tt>resource://</tt> URL, which is derived directly from the source tree path.  There is a slight difference between client and server URLs because the non-client files have extra <tt>gre</tt> segment. In more detail:
These modules are loaded using <tt>Cu.import()</tt>.  To <tt>import()</tt> a file, you provide a <tt>resource://</tt> URL, which is exactly the source tree path.   


* <tt>/devtools/client/<X></tt>: <tt>resource:///modules/devtools/client/<X></tt>
In more detail:
* <tt>/devtools/server/<X></tt>: <tt>resource://gre/modules/devtools/server/<X></tt>
 
* <tt>/devtools/shared/<X></tt>: <tt>resource://gre/modules/devtools/shared/<X></tt>
* <tt>/devtools/client/<X></tt>: <tt>resource://devtools/client/<X></tt>
* <tt>/devtools/server/<X></tt>: <tt>resource://devtools/server/<X></tt>
* <tt>/devtools/shared/<X></tt>: <tt>resource://devtools/shared/<X></tt>


Example:
Example:
Line 153: Line 155:
* File: <tt>/devtools/shared/Loader.jsm</tt>
* File: <tt>/devtools/shared/Loader.jsm</tt>
* Usage:
* Usage:
** <tt>Cu.import("resource://gre/modules/devtools/shared/Loader.jsm")</tt>
** <tt>Cu.import("resource://devtools/shared/Loader.jsm")</tt>


Example:
Example:
Line 159: Line 161:
* File: <tt>/devtools/client/framework/gDevTools.jsm</tt>
* File: <tt>/devtools/client/framework/gDevTools.jsm</tt>
* Usage (prefer lazy in most cases):
* Usage (prefer lazy in most cases):
** <tt>loader.lazyImporter(this, "gDevTools", "resource:///modules/devtools/client/framework/gDevTools.jsm")</tt>
** <tt>loader.lazyImporter(this, "gDevTools", "resource://devtools/client/framework/gDevTools.jsm")</tt>
** <tt>Cu.import("resource:///modules/devtools/client/framework/gDevTools.jsm")</tt>
** <tt>Cu.import("resource://devtools/client/framework/gDevTools.jsm")</tt>


== Chrome Content ==
== Chrome Content ==
Confirmed users
177

edits