prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  WebView in MacOS not accepting keyboard input
  **Describe the bug**
  
  I am unable to type text in HTML input fields within a Toga WebView on Mac OS.
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Follow the tutorial at https://docs.beeware.org/en/latest/tutorial/tutorial-1.html until you are able to run `briefcase dev` successfully.
  2. Modify the `startup` function so that its body is:
     ```main_box = toga.Box()
          self.main_window = toga.MainWindow(title=self.formal_name)
          self.main_window.content = toga.WebView(style=Pack(flex=1))
          self.main_window.content.url = 'https://www.google.ca/'
          self.main_window.show()
     ```
  3. Attempt to search for something in the Google search input.
  4. When I try, I am unable to type characters. Nothing happens with my key presses. Note that specified command shortcuts do seem to work.
  
  **Expected behavior**
  I expect to be able to enter text into text boxes in a WebView in Toga.
  
  **Environment:**
   - Operating System: Mac OS 10.15.6
   - Python version: 3.6.5
   - Software versions:
     - Briefcase: 0.3.0
     - Toga: 0.3.0.dev26
  
  **Additional context**
  I discovered that If I just comment out the `keyDown_` method in toga_cocoa [here](https://github.com/beeware/toga/blob/master/src/cocoa/toga_cocoa/widgets/webview.py#L23-L27) then I am able to enter text in a WebView.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/cocoa/toga_cocoa/widgets/webview.py`
  Content:
  ```
  1 from asyncio import get_event_loop
  2 
  3 from travertino.size import at_least
  4 
  5 from toga_cocoa.keys import toga_key
  6 from toga_cocoa.libs import NSURL, NSURLRequest, WKWebView
  7 from rubicon.objc import objc_method, py_from_ns
  8 from rubicon.objc.runtime import objc_id
  9 
  10 from .base import Widget
  11 
  12 
  13 class TogaWebView(WKWebView):
  14     @objc_method
  15     def webView_didFinish_navigation_(self, sender, wkNavigation) -> None:
  16         if self.interface.on_webview_load:
  17             self.interface.on_webview_load(self.interface)
  18 
  19     @objc_method
  20     def acceptsFirstResponder(self) -> bool:
  21         return True
  22 
  23     @objc_method
  24     def keyDown_(self, event) -> None:
  25         if self.interface.on_key_down:
  26             self.interface.on_key_down(self.interface, **toga_key(event))
  27 
  28     @objc_method
  29     def touchBar(self):
  30         # Disable the touchbar.
  31         return None
  32 
  33 
  34 class WebView(Widget):
  35     def create(self):
  36         self.native = TogaWebView.alloc().init()
  37         self.native.interface = self.interface
  38 
  39         self.native.downloadDelegate = self.native
  40         self.native.frameLoadDelegate = self.native
  41         self.native.policyDelegate = self.native
  42         self.native.resourceLoadDelegate = self.native
  43         self.native.uIDelegate = self.native
  44 
  45         # Add the layout constraints
  46         self.add_constraints()
  47 
  48     def set_on_key_down(self, handler):
  49         pass
  50 
  51     def set_on_webview_load(self, handler):
  52         pass
  53 
  54     def get_dom(self):
  55         # Utilises Step 2) of:
  56         # https://developer.apple.com/library/content/documentation/
  57         #       Cocoa/Conceptual/DisplayWebContent/Tasks/SaveAndLoad.html
  58         html = self.native.mainframe.DOMDocument.documentElement.outerHTML
  59         return html
  60 
  61     def set_url(self, value):
  62         if value:
  63             request = NSURLRequest.requestWithURL(NSURL.URLWithString(self.interface.url))
  64             self.native.loadRequest(request)
  65 
  66     def set_content(self, root_url, content):
  67         self.native.loadHTMLString(content, baseURL=NSURL.URLWithString(root_url))
  68 
  69     def set_user_agent(self, value):
  70         user_agent = value if value else "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"  # NOQA
  71         self.native.customUserAgent = user_agent
  72 
  73     async def evaluate_javascript(self, javascript):
  74         """
  75         Evaluate a JavaScript expression.
  76 
  77         **This method is asynchronous**. It will return when the expression has been
  78         evaluated and a result is available.
  79 
  80         :param javascript: The javascript expression to evaluate
  81         :type  javascript: ``str``
  82         """
  83 
  84         loop = get_event_loop()
  85         future = loop.create_future()
  86 
  87         def completion_handler(res: objc_id, error: objc_id) -> None:
  88 
  89             if error:
  90                 error = py_from_ns(error)
  91                 exc = RuntimeError(str(error))
  92                 future.set_exception(exc)
  93             else:
  94                 future.set_result(py_from_ns(res))
  95 
  96         self.native.evaluateJavaScript(javascript, completionHandler=completion_handler)
  97 
  98         return await future
  99 
  100     def invoke_javascript(self, javascript):
  101         """
  102         Invoke a block of javascript.
  103 
  104         :param javascript: The javascript expression to invoke
  105         """
  106         self.native.evaluateJavaScript(javascript, completionHandler=None)
  107 
  108     def rehint(self):
  109         self.interface.intrinsic.width = at_least(self.interface.MIN_WIDTH)
  110         self.interface.intrinsic.height = at_least(self.interface.MIN_HEIGHT)
  111
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/cocoa/toga_cocoa/widgets/webview.py b/src/cocoa/toga_cocoa/widgets/webview.py
  --- a/src/cocoa/toga_cocoa/widgets/webview.py
  +++ b/src/cocoa/toga_cocoa/widgets/webview.py
  @@ -4,7 +4,7 @@
   
   from toga_cocoa.keys import toga_key
   from toga_cocoa.libs import NSURL, NSURLRequest, WKWebView
  -from rubicon.objc import objc_method, py_from_ns
  +from rubicon.objc import objc_method, py_from_ns, send_super
   from rubicon.objc.runtime import objc_id
   
   from .base import Widget
  @@ -24,6 +24,7 @@
       def keyDown_(self, event) -> None:
           if self.interface.on_key_down:
               self.interface.on_key_down(self.interface, **toga_key(event))
  +        send_super(__class__, self, 'keyDown:', event)
   
       @objc_method
       def touchBar(self):
  
verification_info: {"golden_diff": "diff --git a/src/cocoa/toga_cocoa/widgets/webview.py b/src/cocoa/toga_cocoa/widgets/webview.py\n--- a/src/cocoa/toga_cocoa/widgets/webview.py\n+++ b/src/cocoa/toga_cocoa/widgets/webview.py\n@@ -4,7 +4,7 @@\n \n from toga_cocoa.keys import toga_key\n from toga_cocoa.libs import NSURL, NSURLRequest, WKWebView\n-from rubicon.objc import objc_method, py_from_ns\n+from rubicon.objc import objc_method, py_from_ns, send_super\n from rubicon.objc.runtime import objc_id\n \n from .base import Widget\n@@ -24,6 +24,7 @@\n     def keyDown_(self, event) -> None:\n         if self.interface.on_key_down:\n             self.interface.on_key_down(self.interface, **toga_key(event))\n+        send_super(__class__, self, 'keyDown:', event)\n \n     @objc_method\n     def touchBar(self):\n", "issue": "WebView in MacOS not accepting keyboard input\n**Describe the bug**\r\n\r\nI am unable to type text in HTML input fields within a Toga WebView on Mac OS.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Follow the tutorial at https://docs.beeware.org/en/latest/tutorial/tutorial-1.html until you are able to run `briefcase dev` successfully.\r\n2. Modify the `startup` function so that its body is:\r\n   ```main_box = toga.Box()\r\n        self.main_window = toga.MainWindow(title=self.formal_name)\r\n        self.main_window.content = toga.WebView(style=Pack(flex=1))\r\n        self.main_window.content.url = 'https://www.google.ca/'\r\n        self.main_window.show()\r\n   ```\r\n3. Attempt to search for something in the Google search input.\r\n4. When I try, I am unable to type characters. Nothing happens with my key presses. Note that specified command shortcuts do seem to work.\r\n\r\n**Expected behavior**\r\nI expect to be able to enter text into text boxes in a WebView in Toga.\r\n\r\n**Environment:**\r\n - Operating System: Mac OS 10.15.6\r\n - Python version: 3.6.5\r\n - Software versions:\r\n   - Briefcase: 0.3.0\r\n   - Toga: 0.3.0.dev26\r\n\r\n**Additional context**\r\nI discovered that If I just comment out the `keyDown_` method in toga_cocoa [here](https://github.com/beeware/toga/blob/master/src/cocoa/toga_cocoa/widgets/webview.py#L23-L27) then I am able to enter text in a WebView.\n", "before_files": [{"content": "from asyncio import get_event_loop\n\nfrom travertino.size import at_least\n\nfrom toga_cocoa.keys import toga_key\nfrom toga_cocoa.libs import NSURL, NSURLRequest, WKWebView\nfrom rubicon.objc import objc_method, py_from_ns\nfrom rubicon.objc.runtime import objc_id\n\nfrom .base import Widget\n\n\nclass TogaWebView(WKWebView):\n    @objc_method\n    def webView_didFinish_navigation_(self, sender, wkNavigation) -> None:\n        if self.interface.on_webview_load:\n            self.interface.on_webview_load(self.interface)\n\n    @objc_method\n    def acceptsFirstResponder(self) -> bool:\n        return True\n\n    @objc_method\n    def keyDown_(self, event) -> None:\n        if self.interface.on_key_down:\n            self.interface.on_key_down(self.interface, **toga_key(event))\n\n    @objc_method\n    def touchBar(self):\n        # Disable the touchbar.\n        return None\n\n\nclass WebView(Widget):\n    def create(self):\n        self.native = TogaWebView.alloc().init()\n        self.native.interface = self.interface\n\n        self.native.downloadDelegate = self.native\n        self.native.frameLoadDelegate = self.native\n        self.native.policyDelegate = self.native\n        self.native.resourceLoadDelegate = self.native\n        self.native.uIDelegate = self.native\n\n        # Add the layout constraints\n        self.add_constraints()\n\n    def set_on_key_down(self, handler):\n        pass\n\n    def set_on_webview_load(self, handler):\n        pass\n\n    def get_dom(self):\n        # Utilises Step 2) of:\n        # https://developer.apple.com/library/content/documentation/\n        #       Cocoa/Conceptual/DisplayWebContent/Tasks/SaveAndLoad.html\n        html = self.native.mainframe.DOMDocument.documentElement.outerHTML\n        return html\n\n    def set_url(self, value):\n        if value:\n            request = NSURLRequest.requestWithURL(NSURL.URLWithString(self.interface.url))\n            self.native.loadRequest(request)\n\n    def set_content(self, root_url, content):\n        self.native.loadHTMLString(content, baseURL=NSURL.URLWithString(root_url))\n\n    def set_user_agent(self, value):\n        user_agent = value if value else \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8\"  # NOQA\n        self.native.customUserAgent = user_agent\n\n    async def evaluate_javascript(self, javascript):\n        \"\"\"\n        Evaluate a JavaScript expression.\n\n        **This method is asynchronous**. It will return when the expression has been\n        evaluated and a result is available.\n\n        :param javascript: The javascript expression to evaluate\n        :type  javascript: ``str``\n        \"\"\"\n\n        loop = get_event_loop()\n        future = loop.create_future()\n\n        def completion_handler(res: objc_id, error: objc_id) -> None:\n\n            if error:\n                error = py_from_ns(error)\n                exc = RuntimeError(str(error))\n                future.set_exception(exc)\n            else:\n                future.set_result(py_from_ns(res))\n\n        self.native.evaluateJavaScript(javascript, completionHandler=completion_handler)\n\n        return await future\n\n    def invoke_javascript(self, javascript):\n        \"\"\"\n        Invoke a block of javascript.\n\n        :param javascript: The javascript expression to invoke\n        \"\"\"\n        self.native.evaluateJavaScript(javascript, completionHandler=None)\n\n    def rehint(self):\n        self.interface.intrinsic.width = at_least(self.interface.MIN_WIDTH)\n        self.interface.intrinsic.height = at_least(self.interface.MIN_HEIGHT)\n", "path": "src/cocoa/toga_cocoa/widgets/webview.py"}], "after_files": [{"content": "from asyncio import get_event_loop\n\nfrom travertino.size import at_least\n\nfrom toga_cocoa.keys import toga_key\nfrom toga_cocoa.libs import NSURL, NSURLRequest, WKWebView\nfrom rubicon.objc import objc_method, py_from_ns, send_super\nfrom rubicon.objc.runtime import objc_id\n\nfrom .base import Widget\n\n\nclass TogaWebView(WKWebView):\n    @objc_method\n    def webView_didFinish_navigation_(self, sender, wkNavigation) -> None:\n        if self.interface.on_webview_load:\n            self.interface.on_webview_load(self.interface)\n\n    @objc_method\n    def acceptsFirstResponder(self) -> bool:\n        return True\n\n    @objc_method\n    def keyDown_(self, event) -> None:\n        if self.interface.on_key_down:\n            self.interface.on_key_down(self.interface, **toga_key(event))\n        send_super(__class__, self, 'keyDown:', event)\n\n    @objc_method\n    def touchBar(self):\n        # Disable the touchbar.\n        return None\n\n\nclass WebView(Widget):\n    def create(self):\n        self.native = TogaWebView.alloc().init()\n        self.native.interface = self.interface\n\n        self.native.downloadDelegate = self.native\n        self.native.frameLoadDelegate = self.native\n        self.native.policyDelegate = self.native\n        self.native.resourceLoadDelegate = self.native\n        self.native.uIDelegate = self.native\n\n        # Add the layout constraints\n        self.add_constraints()\n\n    def set_on_key_down(self, handler):\n        pass\n\n    def set_on_webview_load(self, handler):\n        pass\n\n    def get_dom(self):\n        # Utilises Step 2) of:\n        # https://developer.apple.com/library/content/documentation/\n        #       Cocoa/Conceptual/DisplayWebContent/Tasks/SaveAndLoad.html\n        html = self.native.mainframe.DOMDocument.documentElement.outerHTML\n        return html\n\n    def set_url(self, value):\n        if value:\n            request = NSURLRequest.requestWithURL(NSURL.URLWithString(self.interface.url))\n            self.native.loadRequest(request)\n\n    def set_content(self, root_url, content):\n        self.native.loadHTMLString(content, baseURL=NSURL.URLWithString(root_url))\n\n    def set_user_agent(self, value):\n        user_agent = value if value else \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8\"  # NOQA\n        self.native.customUserAgent = user_agent\n\n    async def evaluate_javascript(self, javascript):\n        \"\"\"\n        Evaluate a JavaScript expression.\n\n        **This method is asynchronous**. It will return when the expression has been\n        evaluated and a result is available.\n\n        :param javascript: The javascript expression to evaluate\n        :type  javascript: ``str``\n        \"\"\"\n\n        loop = get_event_loop()\n        future = loop.create_future()\n\n        def completion_handler(res: objc_id, error: objc_id) -> None:\n\n            if error:\n                error = py_from_ns(error)\n                exc = RuntimeError(str(error))\n                future.set_exception(exc)\n            else:\n                future.set_result(py_from_ns(res))\n\n        self.native.evaluateJavaScript(javascript, completionHandler=completion_handler)\n\n        return await future\n\n    def invoke_javascript(self, javascript):\n        \"\"\"\n        Invoke a block of javascript.\n\n        :param javascript: The javascript expression to invoke\n        \"\"\"\n        self.native.evaluateJavaScript(javascript, completionHandler=None)\n\n    def rehint(self):\n        self.interface.intrinsic.width = at_least(self.interface.MIN_WIDTH)\n        self.interface.intrinsic.height = at_least(self.interface.MIN_HEIGHT)\n", "path": "src/cocoa/toga_cocoa/widgets/webview.py"}]}