question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't open a new window from the JS API

See original GitHub issue

Specification

  • Platform: winforms
  • Version: 2.0.3

Description

My code looks a bit like this:

import os
import threading

import webview


class FirstWindowApi:
    def on_button(self):
        webview.destroy_window()
        t = threading.Thread(target=create_second_window)
        t.start()


class SecondWindowApi:
    pass


def create_second_window():
    second_window = webview.create_window("Window 2", os.path.abspath("web\\window2.html"), js_api=SecondWindowApi)



first_window = webview.create_window("Window 1", os.path.abspath("web\\window1.html"), js_api=FirstWindowApi)

However, when I click the button, it crashes with this exception:

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'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
r0x0rcommented, May 30, 2018

@TheInitializer as your case could be solved by switching the order of destroy_window and create_window, I see no reason in keeping application loop alive. Besides how would you terminate the application loop if a keep-alive feature would be implemented?

The threading model should be probably be documented in README.

1reaction
r0x0rcommented, May 31, 2018

QT had the same problem as Windows with restarting application loop. All the platforms should be fixed by now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't Open New Window with Javascript
I am trying to make a button that will popup a new window using a javascript button pressed by the user.
Read more >
Window.open() - Web APIs | MDN
The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a...
Read more >
Can't open more than 20 or so tabs with JS map
69 64-bit), if I open more than 20 or so browser tabs with an ArcGIS JS map, the browser tabs all crash. For...
Read more >
JavaScript Window open method
It is a pre-defined window method of JavaScript used to open the new tab or window in the browser. This will depend on...
Read more >
How to enable JavaScript in Windows
Many Internet Web sites contain JavaScript, a scripting programming language that ... When the "Internet Options" window opens, select the Security tab.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found