SwiftScripting
SwiftScripting copied to clipboard
How to get favicon image in SafariScripting in safari.swift file
is there a way to get the favicon image of current tab in safari browsers
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
})
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.