Example #1
0
        /// <summary>
        /// Gets an IBrowser instance from the user agent string passed in.
        /// </summary>
        /// <param name="userAgentString">The user agent string.</param>
        /// <returns>An instance of IBrowser.</returns>
        internal static IBrowser GetBrowser(ReadOnlySpan <char> userAgentString)
        {
            // Order is important, Go from most specific to generic
            // For example, The string "Chrome" is present in both Chrome and Edge,
            // So we will first check if it is Edge because Edge has something more specific we can check.
            if (Firefox.TryParse(userAgentString, out var firefox))
            {
                return(firefox);
            }

            if (EdgeChromium.TryParse(userAgentString, out var edgeChromium))
            {
                return(edgeChromium);
            }

            if (InternetExplorer.TryParse(userAgentString, out var ie))
            {
                return(ie);
            }

            if (Opera.TryParse(userAgentString, out var opera))
            {
                return(opera);
            }

            if (Edge.TryParse(userAgentString, out var edge))
            {
                return(edge);
            }

            if (Chrome.TryParse(userAgentString, out var chrome))
            {
                return(chrome);
            }

            if (Safari.TryParse(userAgentString, out var safari))
            {
                return(safari);
            }

            if (Instagram.TryParse(userAgentString, out var instagram))
            {
                return(instagram);
            }

            return(default);
Example #2
0
        /// <summary>
        /// Populates a Instagram browser object from the userAgent value passed in. A return value indicates the parsing and populating the browser instance succeeded.
        /// </summary>
        /// <param name="userAgent">User agent value.</param>
        /// <param name="result">When this method returns True, the result will contain a Instagram object populated.</param>
        /// <returns>True if parsing succeeded, else False.</returns>
        public static bool TryParse(ReadOnlySpan <char> userAgent, out Instagram result)
        {
            var instagramIndex = userAgent.IndexOf("Instagram ".AsSpan());

            // Instagram should have "Instagram" words in it.
            if (instagramIndex > -1)
            {
                var instagramVersion = GetVersionIfKeyPresent(userAgent, "Instagram ");
                if (instagramVersion != null)
                {
                    result = new Instagram(userAgent, instagramVersion);
                    return(true);
                }
            }

            result = null;
            return(false);
        }