Implement this interface to handle events related to Developer Tools window.
Table of contents:
| Parameter | Type |
|---|---|
| browser | Browser |
| Return | void |
Implement this callback to overwrite the Browser.ShowDevTools
method. This will also overwrite the behavior of mouse context menu option
"Developer Tools". This callback is useful to implement custom behavior
and also to fix keyboard issues in DevTools popup in the wxpython.py
example reported in Issue #381.
Example usage case is in the wxpython.py and devtools.py
examples. See parts of the code from the wxpython.py example:
# DevTools port and url. This is needed to workaround keyboard issues
# in DevTools popup on Windows (Issue #381).
DEVTOOLS_PORT = 0 # By default a random port is generated.
if WINDOWS:
DEVTOOLS_PORT = 54008
DEVTOOLS_URL = "http://127.0.0.1:{0}/".format(DEVTOOLS_PORT)
...
if DEVTOOLS_PORT:
settings["remote_debugging_port"] = DEVTOOLS_PORT
...
def ShowDevTools(self, browser, **_):
# Check if app was frozen with e.g. pyinstaller.
if getattr(sys, "frozen", None):
dir = os.path.dirname(os.path.realpath(__file__))
executable = os.path.join(dir, "devtools.exe");
if os.path.exists(executable):
# If making executable with pyinstaller then create
# executable for the devtools.py script as well.
subprocess.Popen([executable, DEVTOOLS_URL])
else:
# Another way to show DevTools is to open it in Google Chrome
# system browser.
webbrowser.open(DEVTOOLS_URL)
else:
# Use the devtools.py script to open DevTools popup.
dir = os.path.dirname(os.path.realpath(__file__))
script = os.path.join(dir, "devtools.py")
subprocess.Popen([sys.executable, script, DEVTOOLS_URL])