partial interface Navigator {
+ boolean canShare(optional ShareData data = {});
[SecureContext] Promise<undefined> share(optional ShareData data = {});
};
@@ -136,6 +137,23 @@
+
+
+ canShare() method
+
+
+ When the {{Navigator/canShare()}} method is called with argument
+ |data:ShareData|, run the following steps:
+
+
+
Let |base| be [=this=]'s [=relevant settings object=]'s
+ [=environment settings object/API base URL=].
+
+
Return the result of [=validate share data=] with |data| and
+ |base|.
+
+
+
share() method
@@ -165,25 +183,19 @@
{{ShareData/text}}, or {{ShareData/url}} or {{ShareData/file}} are
present, return a promise rejected with a {{TypeError}}.
-
If |data|'s {{ShareData/files}} member is present:
-
-
If |data|'s {{ShareData/files}} member is empty, or if the
- implementation does not support file sharing, return a
- promise rejected with a {{TypeError}}, and abort these
- steps.
-
-
+
Let |base:URL| be the [=this=] value's relevant settings
+ object's [=environment settings object/api base URL=].
+
+
If running the steps to [=validate share data=] with |data| and
+ |base| return false, then return a promise rejected with a
+ {{TypeError}}.
If |data|'s {{ShareData/url}} member is present:
-
Let |base:URL| be the [=this=] value's relevant settings
- object's [=environment settings object/api base URL=].
-
Let |url:URL| be the result of running the URL
parser on |data|'s {{ShareData/url}} with |base|.
This specification defines an API for sharing text, links and other
@@ -295,10 +295,23 @@
{{ShareData/text}}, or {{ShareData/url}} or {{ShareData/files}} are
present, return false.
+
Let |titleTextOrUrl:boolean| be true if any of
+ {{ShareData/title}}, or {{ShareData/text}}, or {{ShareData/url}} is
+ present.
+
If |data|'s {{ShareData/files}} member is present:
-
If |data|'s {{ShareData/files}} member is empty, or if the
- implementation does not support file sharing, return false.
+
If |titleTextOrUrl| is false, and if |data|'s
+ {{ShareData/files}} member is empty, or return false.
+
+ This causes a `{ files: [] }` dictionary to be treated as
+ an empty dictionary. However, passing a dictionary like
+ `{text: "text" files: []}` is fine, as `files` is just
+ ignored.
+
+
+
If the implementation does not support file sharing, return
+ false.
- When the {{Navigator/canShare()}} method is called with argument
- |data:ShareData|, run the following steps:
-
-
-
If the current settings object's responsible document is not
- allowed to use the "[=web-share-feature|web-share=]"
- permission, return false.
-
-
Let |base| be [=this=]'s [=relevant settings object=]'s
- [=environment settings object/API base URL=].
-
-
Return the result of [=validate share data=] with |data| and
- |base|.
-
-
-
share() method
@@ -189,10 +152,10 @@
|data:ShareData|, run the following steps:
-
If the current settings object's responsible document is not
- allowed to use the "[=web-share-feature|web-share=]"
- permission, return [=a promise rejected with=] with a
- {{"NotAllowedError"}} {{DOMException}}.
+
If the [=current settings object=]'s [=environment settings
+ object/responsible document=] is not allowed to use the
+ "[=web-share-feature|web-share=]" permission, return [=a promise
+ rejected with=] with a {{"NotAllowedError"}} {{DOMException}}.
If {{[[sharePromise]]}} is not `null`, return a promise
rejected with {{InvalidStateError}}.
@@ -306,50 +269,105 @@
- Validate share data
+ `canShare(data)` method
+
- To validate share data with |data:ShareData| and
- |base:URL|, run the following steps:
+ When the canShare(data) method is
+ called with argument {{ShareData}} |data:ShareData|, run the
+ following steps:
-
If none of |data|'s members {{ShareData/title}},
- {{ShareData/text}}, or {{ShareData/url}} or {{ShareData/files}} are
- present, return false.
+
If the [=current settings object=]'s [=environment settings
+ object/responsible document=] is not allowed to use the
+ "[=web-share-feature|web-share=]" permission, return false.
-
Let |titleTextOrUrl:boolean| be true if any of
- {{ShareData/title}}, or {{ShareData/text}}, or {{ShareData/url}} is
- present.
+
Let |base| be [=this=]'s [=relevant settings object=]'s
+ [=environment settings object/API base URL=].
+
+
Return the result of [=validate share data=] with |data| and
+ |base|.
-
If |data|'s {{ShareData/files}} member is present:
+
+
+
+
+ `canShare(name, options)` method
+
+
+
+ When the canShare(name,
+ options) method is called with arguments {{DOMString}}
+ |name:DOMString| and {{CanShareQuery}} |options:CanShareQuery|, run
+ the following steps:
+
+
+
If the [=current settings object=]'s [=environment settings
+ object/responsible document=] is not allowed to use the
+ "[=web-share-feature|web-share=]" permission, return false.
+
+
If |name| is "url", return either `true` or `false` depending
+ on if sharing URLs is [=supported=].
+
+
If |name| is "text", return either `true` or `false` depending
+ on if sharing text is [=supported=].
+
+
If |name| is "files":
-
If |titleTextOrUrl| is false, and if |data|'s
- {{ShareData/files}} member is empty, or return false.
-
- This causes a `{ files: [] }` dictionary to be treated as
- an empty dictionary. However, passing a dictionary like
- `{text: "text" files: []}` is fine, as `files` is just
- ignored.
-
+
If sharing files is not [=supported=], return `false`.
-
If the implementation does not support file sharing, return
- false.
+
If |options| is doesn't have a {{CanShareQuery/type}}
+ member, return `true`.
-
-
-
If |data|'s url member is present:
-
-
Let |url:URL| be the result of running the [=URL parser]=
- on |data|'s url, with |base|, and no encoding override.
+
Let |type| be the result of [=parse a MIME type=] with
+ {{CanShareQuery/type}} as input.
-
If |url| is failure, return false.
+
If |type| is failure, throw a {{TypeError}}.
-
If |url|'s [=URL/scheme=] is not "http" or "https", return
- false.
+
Return either `true` or `false` depending on if the user
+ agent supports sharing the [=MIME type/essence=] of |type|.
-
Return true.
+
|name| is not a [=supported share member=], return `false`.
@@ -365,7 +383,7 @@
USVString text;
USVString url;
};
-
+
The ShareData dictionary consists of several optional
members:
@@ -397,6 +415,10 @@
A URL string referring to a resource being shared.
+
+ A member is supported if the use agent supports sharing
+ the value of a {{ShareData}} member with [=share targets=].
+
These members are {{USVString}} (as opposed to {{DOMString}}) because
they are not allowed to contain surrogate code points. Among other
@@ -412,6 +434,114 @@
an [^a^] element, before being given to the share target.
+
+
+ Validate share data
+
+
+ To validate share data with |data:ShareData| and
+ |base:URL|, run the following steps:
+
+
+
If none of |data|'s members {{ShareData/title}},
+ {{ShareData/text}}, or {{ShareData/url}} or {{ShareData/files}} are
+ present, return false.
+
+
Let |titleTextOrUrl:boolean| be true if any of
+ {{ShareData/title}}, or {{ShareData/text}}, or {{ShareData/url}} is
+ present.
+
+
If |data|'s {{ShareData/files}} member is present:
+
+
If |titleTextOrUrl| is false and |data|'s {{ShareData/files}}
+ member is empty, return false.
+
+ This causes a `{ files: [] }` dictionary to be treated as an
+ empty dictionary. However, passing a dictionary like `{text:
+ "text", files: []}` is fine, as `files` is just ignored.
+
+
+
If the implementation does not support file sharing, return
+ false.
+
+
If the user agent believes sharing any of the files in
+ `files` would result in a potentially hostile share, return
+ false.
+
+
+
+
+
If |data|'s url member is present:
+
+
Let |url:URL| be the result of running the [=URL parser=] on
+ |data|'s url, with |base|, and no encoding override.
+
+
If |url| is failure, return false.
+
+
If |url|'s [=URL/scheme=] is not "http" or "https", return
+ false.
+
+ The type member is a [=MIME Type=] that the developer
+ would like to check support for.
+
+
+
+
+
+ Supported share members
+
+
+ The supported share members provide a means for developers
+ to check if particular sharing capabilities are supported by the user
+ agent. They are represented by the following string literals:
+
+
+
+ "files"
+
+
+ Represents support for the {{ShareData/files}} member.
+
+
+ "url"
+
+
+ Represents support for the {{ShareData/url}} member.
+
+
+ "text"
+
+
+ Represents support for the {{ShareData/text}} member.
+
+
+
+ The choice to use string literals instead of an [=enumeration=] is
+ deliberate. Doing so allows implementers to gracefully support future
+ {{ShareData}} member values, while also giving the user agent the
+ ability to disable sharing those members if needed.
+
This specification defines an API for sharing text, links and other
@@ -92,25 +92,39 @@
display a picker or chooser dialog, allowing the user to select a
target to share this title and the page URL to.
+
+ Calling {{Navigator/canShare()}} method with a {{ShareData}} dictionary
+ [=validate share data|validates=] the shared data. unlike
+ {{Navigator/share()}}, it can be called without [=transient
+ activation=].
+
+
+ const file = new File([], "some.png", { type: "image/png" });
+
+ // Check if files are supported
+ if (navigates.canShare({files: [file]})) {
+ // Sharing a png file would probably be ok...
+ }
+
+ // Check if a URL is ok to share...
+ if (navigates.canShare({ url: someURL })) {
+ // The URL is valid and can probably be shared...
+ }
+
- When the canShare(data) method is
- called with argument {{ShareData}} |data:ShareData|, run the
- following steps:
+ When the canShare(data) method is called with argument
+ {{ShareData}} |data:ShareData|, run the following steps:
If the [=current settings object=]'s [=environment settings
- object/responsible document=] is not allowed to use the
- "[=web-share-feature|web-share=]" permission, return false.
-
-
Let |base| be [=this=]'s [=relevant settings object=]'s
- [=environment settings object/API base URL=].
+ object/responsible document=] is not allowed to use
+ "web-share", return false.
Return the result of [=validate share data=] with |data| and
- |base|.
-
-
-
-
-
- `canShare(name, options)` method
-
-
-
- When the canShare(name,
- options) method is called with arguments {{DOMString}}
- |name:DOMString| and {{CanShareQuery}} |options:CanShareQuery|, run
- the following steps:
-
-
-
If the [=current settings object=]'s [=environment settings
- object/responsible document=] is not allowed to use the
- "[=web-share-feature|web-share=]" permission, return false.
-
-
If |name| is "url", return either `true` or `false` depending
- on if sharing URLs is [=supported=].
-
-
If |name| is "text", return either `true` or `false` depending
- on if sharing text is [=supported=].
-
-
If |name| is "files":
-
-
If sharing files is not [=supported=], return `false`.
-
-
If |options| is doesn't have a {{CanShareQuery/type}}
- member, return `true`.
-
-
Let |type| be the result of [=parse a MIME type=] with
- {{CanShareQuery/type}} as input.
-
-
If |type| is failure, throw a {{TypeError}}.
-
-
Return either `true` or `false` depending on if the user
- agent supports sharing the [=MIME type/essence=] of |type|.
-
-
-
-
|name| is not a [=supported share member=], return `false`.
+ [=this=]'s [=relevant settings object=]'s [=environment settings
+ object/API base URL=].
@@ -439,7 +368,7 @@
USVString text;
USVString url;
};
-
+
The ShareData dictionary consists of several optional
members:
@@ -471,10 +400,6 @@
A URL string referring to a resource being shared.
-
- A member is supported if the use agent supports sharing
- the value of a {{ShareData}} member with [=share targets=].
-
These members are {{USVString}} (as opposed to {{DOMString}}) because
they are not allowed to contain surrogate code points. Among other
@@ -490,114 +415,6 @@
an [^a^] element, before being given to the share target.
-
-
- Validate share data
-
-
- To validate share data with |data:ShareData| and
- |base:URL|, run the following steps:
-
-
-
If none of |data|'s members {{ShareData/title}},
- {{ShareData/text}}, or {{ShareData/url}} or {{ShareData/files}} are
- present, return false.
-
-
Let |titleTextOrUrl:boolean| be true if any of
- {{ShareData/title}}, or {{ShareData/text}}, or {{ShareData/url}} is
- present.
-
-
If |data|'s {{ShareData/files}} member is present:
-
-
If |titleTextOrUrl| is false and |data|'s {{ShareData/files}}
- member is empty, return false.
-
- This causes a `{ files: [] }` dictionary to be treated as an
- empty dictionary. However, passing a dictionary like `{text:
- "text", files: []}` is fine, as `files` is just ignored.
-
-
-
If the implementation does not support file sharing, return
- false.
-
-
If the user agent believes sharing any of the files in
- `files` would result in a potentially hostile share, return
- false.
-
-
-
-
-
If |data|'s url member is present:
-
-
Let |url:URL| be the result of running the [=URL parser=] on
- |data|'s url, with |base|, and no encoding override.
-
-
If |url| is failure, return false.
-
-
If |url|'s [=URL/scheme=] is not "http" or "https", return
- false.
-
- The type member is a [=MIME Type=] that the developer
- would like to check support for.
-
-
-
-
-
- Supported share members
-
-
- The supported share members provide a means for developers
- to check if particular sharing capabilities are supported by the user
- agent. They are represented by the following string literals:
-
-
-
- "files"
-
-
- Represents support for the {{ShareData/files}} member.
-
-
- "url"
-
-
- Represents support for the {{ShareData/url}} member.
-
-
- "text"
-
-
- Represents support for the {{ShareData/text}} member.
-
-
-
- The choice to use string literals instead of an [=enumeration=] is
- deliberate. Doing so allows implementers to gracefully support future
- {{ShareData}} member values, while also giving the user agent the
- ability to disable sharing those members if needed.
-