Beispiel #1
0
        /// <summary>
        /// Lets web sites register their ability to open or handle particular URL schemes (aka protocols).
        ///
        /// For example, this API lets webmail sites open mailto: URLs, or VoIP sites open tel: URLs.
        /// </summary>
        /// <param name="protocol">A string containing the protocol the site wishes to handle. For example, you can register to handle SMS text message links by passing the "sms" scheme.</param>
        /// <param name="urlPattern">A string containing the URL of the handler. This URL must include %s, as a placeholder that will be replaced with the escaped URL to be handled.</param>
        /// <param name="title">A human-readable title string for the handler. This will be displayed to the user, such as prompting “Allow this site to handle [scheme] links?” or listing registered handlers in the browser’s settings.</param>
        /// <returns></returns>
#pragma warning disable CA1054
        public async ValueTask RegisterProtocolHandler(string protocol, string urlPattern, string title)
#pragma warning restore CA1054
        {
            if (string.IsNullOrEmpty(protocol))
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            if (string.IsNullOrEmpty(urlPattern))
            {
                throw new ArgumentNullException(nameof(urlPattern));
            }

            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException(nameof(title));
            }

            if (await JsRuntime.HasProperty(JsObjectRef, "registerProtocolHandler").ConfigureAwait(false))
            {
                await JsRuntime.InvokeInstanceMethod(JsObjectRef, "registerProtocolHandler", protocol, urlPattern,
                                                     title).ConfigureAwait(false);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Sends a small amount of data over HTTP to a web server. Returns true if the method is supported and succeeds
 ///
 /// This method is for analytics and diagnostics that send data to a server before the document is unloaded, where sending the data any sooner may miss some possible data collection. For example, which link the user clicked before navigating away and unloading the page.
 /// Ensuring that data has been sent during the unloading of a document has traditionally been difficult, because user agents typically ignore asynchronous XMLHttpRequests made in an unload handler.
 /// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
 /// </summary>
 /// <param name="url"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public async ValueTask <bool> SendBeacon(Uri url, object data)
 {
     return(await JsRuntime.HasProperty(JsObjectRef, "sendBeacon").ConfigureAwait(false) &&
            await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "sendBeacon", url, data).ConfigureAwait(false));
 }
Beispiel #3
0
 /// <summary>
 /// Returns true if a call to Share() would succeed.
 /// Returns false if it would fail or sharing is not supported
 /// </summary>
 /// <returns></returns>
 public async ValueTask <bool> CanShare(ShareData shareData)
 {
     return(await JsRuntime.HasProperty(JsObjectRef, "canShare").ConfigureAwait(false) &&
            await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "canShare", shareData).ConfigureAwait(false));
 }