Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get favicon image in SafariScripting in safari.swift file #21

Open
waquarahmad opened this issue Oct 1, 2020 · 2 comments
Open

Comments

@waquarahmad
Copy link

is there a way to get the favicon image of current tab in safari browsers

@jis247
Copy link

jis247 commented Oct 1, 2020

I have used this to get current tab name and url but how to get current tab FavIcon image.

let safariApplication = SBApplication(bundleIdentifier: "com.apple.Safari")! as SafariApplication
        self.windows = safariApplication.windows!().reduce([String: SafariWindow](), { (dictionary, object) -> [String: SafariWindow] in
            let window = object as! SafariWindow
            let tabName = window.name
            let safariTab = window.tabs?().object(withName: "\(tabName ?? "")")
            let url = (safariTab as AnyObject).URL
            
            urlValue = url ?? ""
            tabName1 = tabName ?? ""
            print(url ?? "")
            print(tabName ?? "")
            var dictionary = dictionary
            dictionary[window.name!] = window

            return dictionary
        })

@tingraldi
Copy link
Owner

There is no way to directly query for the favicon using the Safari scripting interface. You could conceivably retrieve the document from the Safari window and parse the link tags to find the url for the favicon. You could also use a service such as https://favicons.githubusercontent.com to retrieve the favicon for the domain associated with a given tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants