title: swift osx webview input type = text not working
body: <p>I created window and webview programmatically.</p>
  
  <p><a href="https://i.stack.imgur.com/A13qW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A13qW.jpg" alt="enter image description here"></a></p>
  
  <p>All buttons, radiobuttons are clicked normaly. 
  But if I click to input and want to type text it is not clicking. Cursor changes, but focus isn't in input. Keyboard not typing. 
  Right button on input works fine and i can paste text in it.</p>
  
  <pre><code>//
  //  WindowCommand.swift
  //  DeskAlerts
  //
  //  Created by mihail on 26/04/2017.
  //  Copyright © 2017 Toolbarstudio Inc. All rights reserved.
  //
  
  import Foundation
  import Cocoa
  import SINQ
  import WebKit
  extension NSCoder {
      class func empty() -&gt; NSCoder {
          let data = NSMutableData()
          let archiver = NSKeyedArchiver(forWritingWith: data)
          archiver.finishEncoding()
          return NSKeyedUnarchiver(forReadingWith: data as Data)
      }
  }
  
  
  
  class WindowCommand:NSViewController, WebFrameLoadDelegate, WebUIDelegate, WebEditingDelegate, WebPolicyDelegate, WebDownloadDelegate, WebResourceLoadDelegate
  {
      var Coder: NSCoder?
  
      var Window: NSWindow?
  
      init() {
          Coder = NSCoder.empty()
          super.init(coder: Coder!)!
          InitParentWindow()
      }
  
      required init?(coder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      func InitParentWindow()
      {
          let rect = NSRect.init(x: 0.0, y: 0.0, width: 500.0 , height: 500.0)
          Window = NSWindow(contentRect: rect , styleMask: NSWindowStyleMask.borderless, backing: NSBackingStoreType.retained, defer: false, screen: MainScreen)
  
  
          Window?.isOpaque = true
          Window?.backgroundColor = NSColor.clear
          Window?.hasShadow = false
          Window?.isReleasedWhenClosed = true
          Window?.acceptsMouseMovedEvents = true
          Window?.allowsConcurrentViewDrawing = true
          Window?.ignoresMouseEvents = false
          Window?.isDocumentEdited = true
          Window?.level = Int(CGWindowLevelForKey(.maximumWindow))
          Window?.makeKeyAndOrderFront(self)
          Window?.contentViewController = self
      }
  
      func Close()
      {
          Window?.close()
      }
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  
          let preferences = WebPreferences()
          preferences.allowsAirPlayForMediaPlayback = true
          preferences.allowsAnimatedImageLooping = true
          preferences.allowsAnimatedImages = true
          preferences.arePlugInsEnabled = true
          preferences.autosaves = true
          preferences.cacheModel = WebCacheModel.documentBrowser
          preferences.isJavaEnabled = true
          preferences.isJavaScriptEnabled = true
          preferences.javaScriptCanOpenWindowsAutomatically = true
          preferences.loadsImagesAutomatically = true
          preferences.privateBrowsingEnabled = false
          preferences.shouldPrintBackgrounds = false
          preferences.tabsToLinks = false
          preferences.usesPageCache = false
          preferences.suppressesIncrementalRendering = true
  
          self.view.frame = NSRect.init(x: 0, y: 0, width: 500, height: 500)
          CaptionBrowser = WebView.init(frame: NSRect.init(x: 0, y: 0, width: 500, height: 500)
          let nillvalue:WebView? = nil
          if (CaptionBrowser != nillvalue)
          {
              CaptionBrowser?.uiDelegate = self
              CaptionBrowser?.frameLoadDelegate = self
              CaptionBrowser?.editingDelegate = self
              CaptionBrowser?.policyDelegate = self
              CaptionBrowser?.resourceLoadDelegate = self
              CaptionBrowser?.downloadDelegate = self
              CaptionBrowser?.windowScriptObject.setValue(HtmlInteropClass(data: Alert!, owner: self), forKey: "external")
              CaptionBrowser?.preferences = preferences
              self.view.addSubview(CaptionBrowser!, positioned: NSWindowOrderingMode.above, relativeTo: nil)
  
  
              var url = NSURL(string: (ParentWindowParams?.captionhref)!)
              CaptionBrowser?.mainFrame.load(URLRequest.init(url: (url! as URL) as URL))
  
  
  
              let mainbrowserwidth = 480
  
              let mainbrowserheight = 150
  
  
  
  
  
  
              MainBrowser = WebView.init(frame: CGRect(x:10 ,y:150, width:480 ,height:150))
              MainBrowser?.uiDelegate = self
              MainBrowser?.frameLoadDelegate = self
              MainBrowser?.editingDelegate = self
              MainBrowser?.policyDelegate = self
              MainBrowser?.resourceLoadDelegate = self
              MainBrowser?.downloadDelegate = self
              MainBrowser?.preferences = preferences
              MainBrowser?.windowScriptObject.setValue(HtmlInteropClass(data: Alert!, owner: self), forKey: "external")
  
              self.view.addSubview(MainBrowser!, positioned: NSWindowOrderingMode.above, relativeTo: CaptionBrowser)
  
              let filePath = Bundle.main.path(forResource: "test", ofType: "html", inDirectory: "Resources")
              url = NSURL(string: filePath!)
              MainBrowser?.mainFrame.load(URLRequest.init(url: url! as URL))
  
  
              //url = NSURL(string: Alerthref!)
              //MainBrowser?.mainFrame.load(URLRequest.init(url: url! as URL))
          }
      }
  
      func webView(_ sender: WebView!, createWebViewWith request: URLRequest!) -&gt; WebView! {
          return sender
      }
  
      func webView(_ webView: WebView!, decidePolicyForNavigationAction actionInformation: [AnyHashable : Any]!, request: URLRequest!, frame: WebFrame!, decisionListener listener: WebPolicyDecisionListener!)
      {
  
              listener.use()
  
  
      }
  
      func webView(_ webView: WebView!, decidePolicyForNewWindowAction actionInformation: [AnyHashable : Any]!, request: URLRequest!, newFrameName frameName: String!, decisionListener listener: WebPolicyDecisionListener!) {
  
              listener.use()
  
      }
  
      func webView(_ sender: WebView!, runJavaScriptAlertPanelWithMessage message: String!, initiatedBy frame: WebFrame!) {
          print(message)
      }
      func webView(_ sender: WebView!, runJavaScriptTextInputPanelWithPrompt prompt: String!, defaultText: String!, initiatedBy frame: WebFrame!) -&gt; String! {
  
  
          return ""
      }
  
      override func loadView() {
        super.loadView()
      }
  
      override var representedObject: Any? {
          didSet {
              // Update the view, if already loaded.
          }
      }
  
  
  }
  </code></pre>