MacKuba

Kuba Suder's blog on Mac & iOS development

Extensions

App ClipsAppKitExtensionsFoundationLocationMacMapsPhotosPrivacySafariSwiftSwiftUIUIKitWatchKitWWDC 19WWDC 20

View as index

What's New in Safari Extensions

Categories: Extensions, Safari, WWDC 19 0 comments Watch the video

Safari app extension can now be notified when something is blocked by the content blocker

  • SFSafariAssociatedContentBlockers list in Info.plist
  • contentBlocker(withIdentifier: blockedResourcesWithURLs: on page:)
  • notifications are batched, and you will only be notified about URLs listed in the access section in the plist

You can also get notified when the user navigates to a different page:

page(_: willNavigateTo url:)

Capturing a screenshot of the visible contents of a page:

page.getScreenshotOfVisibleArea { image in … }

Resources stored in the app extension bundle can be accessed by the browser and JS:

SFSafariExtension.getBaseURI { baseURI in
    tab.navigate(to: baseURI.appendingPathComponent(“index.html”))
}

Listing all browser windows and tabs:

SFSafariApplication.getAllWindows { window in
    window.getAllTabs { … }
}

page.getContainingTab()

tab.getContainingWindow()

Programatically showing popovers:

window.getToolbarItem { item in item?.showPopover() }

Dismissing popover: SFSafariExtensionViewController.dismissPopover