Services.jsm

  • Revision slug: Mozilla/JavaScript_code_modules/Services.jsm
  • Revision title: Services.jsm
  • Revision id: 470465
  • Created:
  • Creator: LouCypher
  • Is current revision? No
  • Comment Added blocklist service

Revision Content

{{ gecko_minversion_header("2") }}

The Services.jsm JavaScript code module offers a wide assortment of lazy getters that simplify the process of obtaining references to commonly used services.

To use it, you first need to import the code module into your JavaScript scope:

Components.utils.import("resource://gre/modules/Services.jsm");

Then you can obtain references to services by simply accessing them from the Services object exported by the code module. For example, to obtain a reference to the preferences service:

var prefsService = Services.prefs;

Provided service getters

Service accessor Service interface Service name
appinfo {{ interface("nsIXULAppInfo") }}
{{ interface("nsIXULRuntime") }}
Application information service
appShell {{ interface("nsIAppShellService") }} Application shell service
blocklist {{ interface("nsIBlocklistService") }} Blocklist service
cache {{ interface("nsICacheService") }} Cache service
clipboard {{ interface("nsIClipboard") }} Clipboard
console {{ interface("nsIConsoleService") }} Error console service
contentPrefs {{ interface("nsIContentPrefService") }} Content Preferences service
cookies {{ interface("nsICookieManager2") }} Cookie Manager 2 service
cpmm {{ interface("nsIFrameMessageManager") }} Child Process Message Manager
dirsvc {{ interface("nsIDirectoryService") }}
{{ interface("nsIProperties") }}
Directory service
domStorageManager {{ interface("nsIDOMStorageManager") }} DOM Storage Manager
DOMRequest {{ interface("nsIDOMRequestService") }} DOMRequest service
downloads {{ interface("nsIDownloadManager") }} Download manager
droppedLinkHandler {{ interface("nsIDroppedLinkHandler") }} Dropped link handler service
eTLD {{ interface("nsIEffectiveTLDService") }} EffectiveTLD service
focus {{ interface("nsIFocusManager") }} Focus manager
io {{ interface("nsIIOService") }}
{{ interface("nsIIOService2") }}
I/O Service
locale {{ interface("nsILocaleService") }} Locale service
logins {{ interface("nsILoginManager") }} Password Manager service
obs {{ interface("nsIObserverService") }} Observer service
perms {{ interface("nsIPermissionManager") }} Permission manager service
ppmm {{ interface("nsIFrameMessageManager") }} Parent Process Message Manager
prefs {{ interface("nsIPrefBranch") }}
{{ interface("nsIPrefBranch2") }}
{{ interface("nsIPrefService") }}
Preferences service
prompt {{ interface("nsIPromptService") }} Prompt service
scriptloader {{ interface("mozIJSSubScriptLoader") }} JavaScript subscript loader service
scriptSecurityManager {{ interface("nsIScriptSecurityManager") }} Script security manager
search {{ interface("nsIBrowserSearchService") }} Browser search service¹
startup {{ interface("nsIAppStartup") }} Application startup service
storage {{ interface("mozIStorageService") }} Storage API service
strings {{ interface("nsIStringBundleService") }} String bundle service
sysinfo {{ interface("nsIPropertyBag2") }} System info service
telemetry {{ interface("nsITelemetry") }} Telemetry service
tm {{ interface("nsIThreadManager") }} Thread Manager service
uriFixup {{ interface("nsIURIFixup") }} URI Fixup service
urlFormatter {{ interface("nsIURLFormatter") }} URL Formatter service
vc {{ interface("nsIVersionComparator") }} Version comparator service
wm {{ interface("nsIWindowMediator") }} Window mediator service
ww {{ interface("nsIWindowWatcher") }} Window watcher service

¹Not present in Thunderbird

See also

Revision Source

<p>{{ gecko_minversion_header("2") }}</p>
<p>The <code>Services.jsm</code> JavaScript code module offers a wide assortment of lazy getters that simplify the process of obtaining references to commonly used services.</p>
<p>To use it, you first need to import the code module into your JavaScript scope:</p>
<pre class="eval">
<span class="nowiki">Components.utils.import("resource://gre/modules/Services.jsm");</span>
</pre>
<p>Then you can obtain references to services by simply accessing them from the <code>Services</code> object exported by the code module. For example, to obtain a reference to the preferences service:</p>
<pre class="brush: js">
var prefsService = Services.prefs;
</pre>
<h2 id="Provided_service_getters">Provided service getters</h2>
<table class="standard-table" style="width: auto;">
  <tbody>
    <tr>
      <td class="header">Service accessor</td>
      <td class="header">Service interface</td>
      <td class="header">Service name</td>
    </tr>
    <tr>
      <td><code>appinfo</code></td>
      <td>{{ interface("nsIXULAppInfo") }}<br />
        {{ interface("nsIXULRuntime") }}</td>
      <td>Application information service</td>
    </tr>
    <tr>
      <td><code>appShell</code></td>
      <td>{{ interface("nsIAppShellService") }}</td>
      <td>Application shell service</td>
    </tr>
    <!--    <tr>
      <td><code>bookmarks</code></td>
      <td>{{interface("nsINavBookmarksService")}}</td>
      <td>Bookmarks service</td>
    </tr> -->
    <tr>
      <td><code>blocklist</code></td>
      <td>{{ interface("nsIBlocklistService") }}</td>
      <td>Blocklist service</td>
    </tr>
    <tr>
      <td><code>cache</code></td>
      <td>{{ interface("nsICacheService") }}</td>
      <td>Cache service</td>
    </tr>
    <tr>
      <td><code>clipboard</code></td>
      <td>{{ interface("nsIClipboard") }}</td>
      <td>Clipboard</td>
    </tr>
    <tr>
      <td><code>console</code></td>
      <td>{{ interface("nsIConsoleService") }}</td>
      <td>Error console service</td>
    </tr>
    <tr>
      <td><code>contentPrefs</code></td>
      <td>{{ interface("nsIContentPrefService") }}</td>
      <td>Content Preferences service</td>
    </tr>
    <tr>
      <td><code>cookies</code></td>
      <td>{{ interface("nsICookieManager2") }}</td>
      <td>Cookie Manager 2 service</td>
    </tr>
    <tr>
      <td><code>cpmm</code></td>
      <td>{{ interface("nsIFrameMessageManager") }}</td>
      <td>Child Process Message Manager</td>
    </tr>
    <tr>
      <td><code>dirsvc</code></td>
      <td>{{ interface("nsIDirectoryService") }}<br />
        {{ interface("nsIProperties") }}</td>
      <td>Directory service</td>
    </tr>
    <tr>
      <td><code>domStorageManager</code></td>
      <td>{{ interface("nsIDOMStorageManager") }}</td>
      <td>DOM Storage Manager</td>
    </tr>
    <tr>
      <td><code>DOMRequest</code></td>
      <td>{{ interface("nsIDOMRequestService") }}</td>
      <td>DOMRequest service</td>
    </tr>
    <tr>
      <td><code>downloads</code></td>
      <td>{{ interface("nsIDownloadManager") }}</td>
      <td>Download manager</td>
    </tr>
    <tr>
      <td><code>droppedLinkHandler</code></td>
      <td>{{ interface("nsIDroppedLinkHandler") }}</td>
      <td>Dropped link handler service</td>
    </tr>
    <tr>
      <td><code>eTLD</code></td>
      <td>{{ interface("nsIEffectiveTLDService") }}</td>
      <td>EffectiveTLD service</td>
    </tr>
    <tr>
      <td><code>focus</code></td>
      <td>{{ interface("nsIFocusManager") }}</td>
      <td>Focus manager</td>
    </tr>
    <tr>
      <td><code>io</code></td>
      <td>{{ interface("nsIIOService") }}<br />
        {{ interface("nsIIOService2") }}</td>
      <td>I/O Service</td>
    </tr>
    <tr>
      <td><code>locale</code></td>
      <td>{{ interface("nsILocaleService") }}</td>
      <td>Locale service</td>
    </tr>
    <tr>
      <td><code>logins</code></td>
      <td>{{ interface("nsILoginManager") }}</td>
      <td>Password Manager service</td>
    </tr>
    <tr>
      <td><code>obs</code></td>
      <td>{{ interface("nsIObserverService") }}</td>
      <td>Observer service</td>
    </tr>
    <tr>
      <td><code>perms</code></td>
      <td>{{ interface("nsIPermissionManager") }}</td>
      <td>Permission manager service</td>
    </tr>
    <tr>
      <td><code>ppmm</code></td>
      <td>{{ interface("nsIFrameMessageManager") }}</td>
      <td>Parent Process Message Manager</td>
    </tr>
    <tr>
      <td><code>prefs</code></td>
      <td>{{ interface("nsIPrefBranch") }}<br />
        {{ interface("nsIPrefBranch2") }}<br />
        {{ interface("nsIPrefService") }}</td>
      <td>Preferences service</td>
    </tr>
    <tr>
      <td><code>prompt</code></td>
      <td>{{ interface("nsIPromptService") }}</td>
      <td>Prompt service</td>
    </tr>
    <tr>
      <td><code>scriptloader</code></td>
      <td>{{ interface("mozIJSSubScriptLoader") }}</td>
      <td>JavaScript subscript loader service</td>
    </tr>
    <tr>
      <td><code>scriptSecurityManager</code></td>
      <td>{{ interface("nsIScriptSecurityManager") }}</td>
      <td>Script security manager</td>
    </tr>
    <tr>
      <td><code>search</code></td>
      <td>{{ interface("nsIBrowserSearchService") }}</td>
      <td>Browser search service¹</td>
    </tr>
    <tr>
      <td><code>startup</code></td>
      <td>{{ interface("nsIAppStartup") }}</td>
      <td>Application startup service</td>
    </tr>
    <tr>
      <td><code>storage</code></td>
      <td>{{ interface("mozIStorageService") }}</td>
      <td><a href="/en-US/Storage" title="en-US/Storage">Storage API</a> service</td>
    </tr>
    <tr>
      <td><code>strings</code></td>
      <td>{{ interface("nsIStringBundleService") }}</td>
      <td>String bundle service</td>
    </tr>
    <tr>
      <td><code>sysinfo</code></td>
      <td>{{ interface("nsIPropertyBag2") }}</td>
      <td>System info service</td>
    </tr>
    <tr>
      <td><code>telemetry</code></td>
      <td>{{ interface("nsITelemetry") }}</td>
      <td>Telemetry service</td>
    </tr>
    <tr>
      <td><code>tm</code></td>
      <td>{{ interface("nsIThreadManager") }}</td>
      <td><a href="/en-US/The_Thread_Manager" title="en-US/The Thread Manager">Thread Manager</a> service</td>
    </tr>
    <tr>
      <td><code>uriFixup</code></td>
      <td>{{ interface("nsIURIFixup") }}</td>
      <td>URI Fixup service</td>
    </tr>
    <tr>
      <td><code>urlFormatter</code></td>
      <td>{{ interface("nsIURLFormatter") }}</td>
      <td>URL Formatter service</td>
    </tr>
    <tr>
      <td><code>vc</code></td>
      <td>{{ interface("nsIVersionComparator") }}</td>
      <td>Version comparator service</td>
    </tr>
    <tr>
      <td><code>wm</code></td>
      <td>{{ interface("nsIWindowMediator") }}</td>
      <td>Window mediator service</td>
    </tr>
    <tr>
      <td><code>ww</code></td>
      <td>{{ interface("nsIWindowWatcher") }}</td>
      <td>Window watcher service</td>
    </tr>
  </tbody>
</table>
<p>¹Not present in Thunderbird</p>
<h2 id="See_also">See also</h2>
<ul>
  <li><a class="internal" href="/en-US/JavaScript_code_modules/Using" title="en-US/JavaScript code modules/Using
    JavaScript code
    modules">Using JavaScript code modules</a></li>
  <li><a class="internal" href="/en-US/JavaScript_code_modules" title="en-US/JavaScript code
    modules">JavaScript code modules</a></li>
  <li><a class="internal" href="/en-US/XPCOM/mozilla::services_namespace" title="mozilla::services C++ namespace">mozilla::services C++ namespace</a></li>
</ul>
Revert to this revision