Skip to content

Instantly share code, notes, and snippets.

@dobreandl
Last active June 13, 2018 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobreandl/fbe1bf4d06ae7a020d9f1deef9c7e12d to your computer and use it in GitHub Desktop.
Save dobreandl/fbe1bf4d06ae7a020d9f1deef9c7e12d to your computer and use it in GitHub Desktop.
private func addPageHasChangedDelegateScript(wkWebController: WKUserContentController) {
// load the script from the file and create a WKUserScript object
let scriptURL = Bundle.main.path(forResource: Constants.detectPageChangeScript, ofType: "js")
let scriptContent = try! String.init(contentsOfFile: scriptURL!)
let script = WKUserScript(source: scriptContent, injectionTime: .atDocumentStart, forMainFrameOnly: false)
// Add the script to the WKUserContentController
wkWebController.addUserScript(script)
// Register for receiving callbacks from javascript for a notification name
wkWebController.add(self, name: ”notification_name”)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment