Guest User

Untitled

a guest
Oct 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import WebKit
  2.  
  3. // This swizzle allows JavaScript to set the focus on an input, not just when a user is interacting.
  4. //
  5. extension WKWebView {
  6.  
  7. private typealias StartAssistingNodeMethodType = @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Any) -> Void
  8. private typealias StartAssistingNodeClosureType = @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Any) -> Void
  9.  
  10. func focusInputsWithoutUserInteraction() {
  11. let selector: Selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:")
  12. guard let wkContentViewClass: AnyClass = NSClassFromString("WKContentView") else { return }
  13. guard let method = class_getInstanceMethod(wkContentViewClass, selector) else { return }
  14. let original: StartAssistingNodeMethodType = unsafeBitCast(method_getImplementation(method), to: StartAssistingNodeMethodType.self)
  15. let replacement: StartAssistingNodeClosureType = { (me, arg0, arg1, arg2, arg3) in
  16. original(me, selector, arg0, true, arg2, arg3)
  17. }
  18. method_setImplementation(method, imp_implementationWithBlock(replacement))
  19. }
  20.  
  21. }
Add Comment
Please, Sign In to add comment