Beispiel #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);
Beispiel #2
0
        /// <summary>
        /// Tries to build an instance of Opera browser from the user agent passed in and
        /// returns a value that indicates whether the parsing succeeded.
        /// </summary>
        /// <param name="userAgent">The user agent value.</param>
        /// <param name="result">An instance of Opera browser.</param>
        /// <returns>A boolean value that indicates whether the parsing succeeded.</returns>
        public static bool TryParse(ReadOnlySpan <char> userAgent, out Opera result)
        {
            var operaVersion      = GetVersionIfKeyPresent(userAgent, "OPR/");
            var operaTouchVersion = GetVersionIfKeyPresent(userAgent, " OPT/");

            if (operaVersion != null)
            {
                result = new Opera(userAgent, operaVersion);
                return(true);
            }

            if (operaTouchVersion != null)
            {
                result = new Opera(userAgent, operaVersion);
                return(true);
            }

            result = null;
            return(false);
        }