Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import WebKit
- // This swizzle allows JavaScript to set the focus on an input, not just when a user is interacting.
- //
- extension WKWebView {
- private typealias StartAssistingNodeMethodType = @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Any) -> Void
- private typealias StartAssistingNodeClosureType = @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Any) -> Void
- func focusInputsWithoutUserInteraction() {
- let selector: Selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:")
- guard let wkContentViewClass: AnyClass = NSClassFromString("WKContentView") else { return }
- guard let method = class_getInstanceMethod(wkContentViewClass, selector) else { return }
- let original: StartAssistingNodeMethodType = unsafeBitCast(method_getImplementation(method), to: StartAssistingNodeMethodType.self)
- let replacement: StartAssistingNodeClosureType = { (me, arg0, arg1, arg2, arg3) in
- original(me, selector, arg0, true, arg2, arg3)
- }
- method_setImplementation(method, imp_implementationWithBlock(replacement))
- }
- }
Add Comment
Please, Sign In to add comment