aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/add-ons/webextensions/api/permissions/contains/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/mozilla/add-ons/webextensions/api/permissions/contains/index.html')
-rw-r--r--files/zh-cn/mozilla/add-ons/webextensions/api/permissions/contains/index.html94
1 files changed, 94 insertions, 0 deletions
diff --git a/files/zh-cn/mozilla/add-ons/webextensions/api/permissions/contains/index.html b/files/zh-cn/mozilla/add-ons/webextensions/api/permissions/contains/index.html
new file mode 100644
index 0000000000..c701942058
--- /dev/null
+++ b/files/zh-cn/mozilla/add-ons/webextensions/api/permissions/contains/index.html
@@ -0,0 +1,94 @@
+---
+title: permissions.contains()
+slug: Mozilla/Add-ons/WebExtensions/API/permissions/contains
+tags:
+ - Contains
+ - permissions.contains()
+translation_of: Mozilla/Add-ons/WebExtensions/API/permissions/contains
+---
+<div>{{AddonSidebar()}}</div>
+
+<p>检查扩展名是否具有给定 {{WebExtAPIRef("permissions.Permissions")}}  对象中列出的权限。</p>
+
+<p>The <code>Permissions</code> argument may contain either an origins property, which is an array of <a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions#Host_permissions">host permissions</a>, or a <code>permissions</code> property, which is an array of <a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions#API_permissions">API permissions</a>, or both.</p>
+
+<p>This is an asynchronous function that returns a <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>. The promise is fulfilled with true only if all the extension currently has all the given permissions. For host permissions, if the extension's permissions <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns">pattern-match</a> the permissions listed in <code>origins</code>, then they are considered to match.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox brush:js notranslate">var getContains = browser.permissions.contains(
+ permissions // Permissions object
+)
+</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><code>permissions</code></dt>
+ <dd>A {{WebExtAPIRef("permissions.Permissions")}} object.</dd>
+</dl>
+
+<h3 id="Return_value">Return value</h3>
+
+<p>A <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code> that will be fulfilled with <code>true</code> if the extension already has all the permissions listed in the <code>permissions</code> argument, or <code>false</code> otherwise.</p>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("webextensions.api.permissions.contains")}}</p>
+
+<h2 id="Examples">Examples</h2>
+
+<pre class="brush: js notranslate">// Extension permissions are:
+// "webRequest", "tabs", "*://*.mozilla.org/*"
+
+var testPermissions1 = {
+ origins: ["*://mozilla.org/"],
+ permissions: ["tabs"]
+};
+
+browser.permissions.contains(testPermissions1).then((result) =&gt; {
+ console.log(result); // true
+});
+
+var testPermissions2 = {
+  origins: ["*://mozilla.org/"],
+  permissions: ["tabs", "alarms"]
+};
+
+browser.permissions.contains(testPermissions2).then((result) =&gt; {
+ console.log(result); // false, "alarms" doesn't match
+});
+
+var testPermissions3 = {
+  origins: ["https://developer.mozilla.org/"],
+  permissions: ["tabs", "webRequest"]
+};
+
+browser.permissions.contains(testPermissions3).then((result) =&gt; {
+ console.log(result); // true: "https://developer.mozilla.org/"
+}); // matches: "*://*.mozilla.org/*"
+
+var testPermissions4 = {
+  origins: ["https://example.org/"]
+};
+
+browser.permissions.contains(testPermissions4).then((result) =&gt; {
+ console.log(result); // false, "https://example.org/"
+}); // does not match
+
+</pre>
+
+<p>{{WebExtExamples}}</p>
+
+<div class="note"><strong>Acknowledgements</strong>
+
+<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/permissions"><code>chrome.permissions</code></a> API.</p>
+
+<p>Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.</p>
+</div>
+
+<div id="gtx-trans" style="position: absolute; left: 677px; top: 46px;">
+<div class="gtx-trans-icon"></div>
+</div>