# Buggy code
def performKeyEquivalent_(self, theEvent):
    """
    Handle common hotkey shortcuts as copy/cut/paste/undo/select all/quit
    :param theEvent:
    :return:
    """

    if (
        theEvent.type() == AppKit.NSKeyDown
        and theEvent.modifierFlags() & AppKit.NSCommandKeyMask
    ):
        responder = self.window().firstResponder()
        keyCode = theEvent.keyCode()

        if responder != None:
            handled = False
            range_ = responder.selectedRange()
            hasSelectedText = len(range_) > 0

            if keyCode == 7 and hasSelectedText:  # cut
                responder.cut_(self)
                handled = True
            elif keyCode == 8 and hasSelectedText:  # copy
                responder.copy_(self)
                handled = True
            elif keyCode == 9:  # paste
                responder.paste_(self)
                handled = True
            elif keyCode == 0:  # select all
                responder.selectAll_(self)
                handled = True
            elif keyCode == 6:  # undo
                if responder.undoManager().canUndo():
                    responder.undoManager().undo()
                    handled = True
            elif keyCode == 12:  # quit
                BrowserView.app.terminate_(self)

            return handled


# Traceback (KeyError)
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Program Files\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "ui_pywebview.py", line 23, in create_second_window
second_window = webview.create_window("Window 2", os.path.abspath("web\\window2.html"), js_api=SecondWindowApi)
File "C:\Program Files\Python36\lib\site-packages\webview\__init__.py", line 183, in create_window
background_color, debug, js_api, text_select, _webview_ready)
File "C:\Program Files\Python36\lib\site-packages\webview\winforms.py", line 252, in create_window
BrowserView.instances['master'].Invoke(Func[Type](create))
KeyError: 'master'

# Fixed code
def performKeyEquivalent_(self, theEvent):
    """
    Handle common hotkey shortcuts as copy/cut/paste/undo/select all/quit
    :param theEvent:
    :return:
    """

    if (
        theEvent.type() == AppKit.NSKeyDown
        and theEvent.modifierFlags() & AppKit.NSCommandKeyMask
    ):
        responder = self.window().firstResponder()
        keyCode = theEvent.keyCode()

        if responder != None:
            handled = False
            range_ = responder.selectedRange()
            hasSelectedText = len(range_) > 0

            if keyCode == 7 and hasSelectedText:  # cut
                responder.cut_(self)
                handled = True
            elif keyCode == 8 and hasSelectedText:  # copy
                responder.copy_(self)
                handled = True
            elif keyCode == 9:  # paste
                responder.paste_(self)
                handled = True
            elif keyCode == 0:  # select all
                responder.selectAll_(self)
                handled = True
            elif keyCode == 6:  # undo
                if responder.undoManager().canUndo():
                    responder.undoManager().undo()
                    handled = True
            elif keyCode == 12:  # quit
                BrowserView.app.stop_(self)

            return handled