SwiftScripting icon indicating copy to clipboard operation
SwiftScripting copied to clipboard

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

Open waquarahmad opened this issue 5 years ago • 2 comments

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

waquarahmad avatar Oct 01 '20 06:10 waquarahmad

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
        })

jis247 avatar Oct 01 '20 07:10 jis247

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.

tingraldi avatar May 20 '21 11:05 tingraldi