# Buggy code
def __init__(
    self,
    uid,
    title,
    url,
    width,
    height,
    resizable,
    fullscreen,
    min_size,
    confirm_quit,
    background_color,
    debug,
    js_api,
    text_select,
    webview_ready,
):
    BrowserView.instances[uid] = self
    self.uid = uid

    if debug:
        BrowserView.debug = debug
        BrowserView._set_debugging()

    self.js_bridge = None
    self._file_name = None
    self._file_name_semaphore = Semaphore(0)
    self._current_url_semaphore = Semaphore(0)
    self.webview_ready = webview_ready
    self.loaded = Event()
    self.confirm_quit = confirm_quit
    self.title = title
    self.text_select = text_select

    self.is_fullscreen = False

    rect = AppKit.NSMakeRect(0.0, 0.0, width, height)
    window_mask = (
        AppKit.NSTitledWindowMask
        | AppKit.NSClosableWindowMask
        | AppKit.NSMiniaturizableWindowMask
    )

    if resizable:
        window_mask = window_mask | AppKit.NSResizableWindowMask

    # The allocated resources are retained because we would explicitly delete
    # this instance when its window is closed
    self.window = (
        AppKit.NSWindow.alloc()
        .initWithContentRect_styleMask_backing_defer_(
            rect, window_mask, AppKit.NSBackingStoreBuffered, False
        )
        .retain()
    )
    self.window.setTitle_(title)
    self.window.setBackgroundColor_(BrowserView.nscolor_from_hex(background_color))
    self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1]))
    BrowserView.cascade_loc = self.window.cascadeTopLeftFromPoint_(
        BrowserView.cascade_loc
    )
    # Set the titlebar color (so that it does not change with the window color)
    self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(
        AppKit.NSColor.windowBackgroundColor()
    )

    self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect).retain()

    self._browserDelegate = BrowserView.BrowserDelegate.alloc().init().retain()
    self._windowDelegate = BrowserView.WindowDelegate.alloc().init().retain()
    self._appDelegate = BrowserView.AppDelegate.alloc().init().retain()
    self.webkit.setUIDelegate_(self._browserDelegate)
    self.webkit.setFrameLoadDelegate_(self._browserDelegate)
    self.webkit.setPolicyDelegate_(self._browserDelegate)
    self.window.setDelegate_(self._windowDelegate)
    BrowserView.app.setDelegate_(self._appDelegate)

    if url:
        self.url = url
        self.load_url(url)
    else:
        self.loaded.set()

    if js_api:
        self.js_bridge = BrowserView.JSBridge.alloc().initWithObject_(js_api)

    if fullscreen:
        self.toggle_fullscreen()


# 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 __init__(
    self,
    uid,
    title,
    url,
    width,
    height,
    resizable,
    fullscreen,
    min_size,
    confirm_quit,
    background_color,
    debug,
    js_api,
    text_select,
    webview_ready,
):
    BrowserView.instances[uid] = self
    self.uid = uid

    if debug:
        BrowserView.debug = debug
        BrowserView._set_debugging()

    self.js_bridge = None
    self._file_name = None
    self._file_name_semaphore = Semaphore(0)
    self._current_url_semaphore = Semaphore(0)
    self.webview_ready = webview_ready
    self.loaded = Event()
    self.confirm_quit = confirm_quit
    self.title = title
    self.text_select = text_select

    self.is_fullscreen = False

    rect = AppKit.NSMakeRect(0.0, 0.0, width, height)
    window_mask = (
        AppKit.NSTitledWindowMask
        | AppKit.NSClosableWindowMask
        | AppKit.NSMiniaturizableWindowMask
    )

    if resizable:
        window_mask = window_mask | AppKit.NSResizableWindowMask

    # The allocated resources are retained because we would explicitly delete
    # this instance when its window is closed
    self.window = (
        AppKit.NSWindow.alloc()
        .initWithContentRect_styleMask_backing_defer_(
            rect, window_mask, AppKit.NSBackingStoreBuffered, False
        )
        .retain()
    )
    self.window.setTitle_(title)
    self.window.setBackgroundColor_(BrowserView.nscolor_from_hex(background_color))
    self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1]))
    self.window.setAnimationBehavior_(AppKit.NSWindowAnimationBehaviorDocumentWindow)
    BrowserView.cascade_loc = self.window.cascadeTopLeftFromPoint_(
        BrowserView.cascade_loc
    )
    # Set the titlebar color (so that it does not change with the window color)
    self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(
        AppKit.NSColor.windowBackgroundColor()
    )

    self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect).retain()

    self._browserDelegate = BrowserView.BrowserDelegate.alloc().init().retain()
    self._windowDelegate = BrowserView.WindowDelegate.alloc().init().retain()
    self._appDelegate = BrowserView.AppDelegate.alloc().init().retain()
    self.webkit.setUIDelegate_(self._browserDelegate)
    self.webkit.setFrameLoadDelegate_(self._browserDelegate)
    self.webkit.setPolicyDelegate_(self._browserDelegate)
    self.window.setDelegate_(self._windowDelegate)
    BrowserView.app.setDelegate_(self._appDelegate)

    if url:
        self.url = url
        self.load_url(url)
    else:
        self.loaded.set()

    if js_api:
        self.js_bridge = BrowserView.JSBridge.alloc().initWithObject_(js_api)

    if fullscreen:
        self.toggle_fullscreen()