safarisafari-app-extension

Safari App Extension , How to load local html page from extension?


I have an HTML file in Safari App Extension bundle

enter image description here

I want to load this file in this method.

override func page(_ page: SFSafariPage, willNavigateTo url: URL?) {} 

Solution

  • Please use this code

    override func page(_ page: SFSafariPage, willNavigateTo url: URL?) {
           if (url?.absoluteString.hasPrefix("safari-extension://") ?? true) {
               return
           }
           DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1000)) {
               page.getContainingTab { tab in
    
                   SFSafariExtension.getBaseURI { baseURI in
                       guard let baseURI = baseURI else { return }
                       tab.navigate(to:baseURI.appendingPathComponent("testHTML.html"))
                   }
               }
           }
       }