Skip to content

Commit

Permalink
Merge pull request beeware#2109 from freakboy3742/webkit-inspector
Browse files Browse the repository at this point in the history
Enable webkit inspector for iOS and Cocoa.
  • Loading branch information
mhsmith authored Sep 4, 2023
2 parents 237ccee + fefaddd commit 037084b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/2109.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The WebKit inspector is automatically enabled on all webviews, provided you're using macOS 13.3 (Ventura) or iOS 16.4, or later.
8 changes: 8 additions & 0 deletions cocoa/src/toga_cocoa/widgets/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def create(self):
self.native.interface = self.interface
self.native.impl = self

# Enable the content inspector. This was added in macOS 13.3 (Ventura). It will
# be a no-op on newer versions of macOS; you need to package the app, then run:
#
# defaults write com.example.appname WebKitDeveloperExtras -bool true
#
# from the command line.
self.native.inspectable = True

self.native.navigationDelegate = self.native
self.native.uIDelegate = self.native

Expand Down
14 changes: 9 additions & 5 deletions docs/reference/api/widgets/webview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ Notes
* Using WebView on Linux requires that the user has installed the system packages
for WebKit2, plus the GObject Introspection bindings for WebKit2.

* On macOS, the "inspect element" feature is not enabled by default. WebView
debugging is only available when your code is packaged as a full macOS app
(e.g., with Briefcase). To enable debugging, run:
* On macOS 13.3 (Ventura) and later, the content inspector for your app can be opened by
running Safari, `enabling the developer tools
<https://support.apple.com/en-au/guide/safari/sfri20948/mac>`__, and selecting your
app's window from the "Develop" menu.

On macOS versions prior to Ventura, the content inspector is not enabled by default,
and is only available when your code is packaged as a full macOS app (e.g., with
Briefcase). To enable debugging, run:

.. code-block:: console
$ defaults write com.example.appname WebKitDeveloperExtras -bool true
Substituting ``com.example.appname`` with the bundle ID for your packaged
app.
Substituting ``com.example.appname`` with the bundle ID for your packaged app.

Reference
---------
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ tvOS
Ubuntu
validator
validators
Ventura
verbing
viewport
watchOS
Expand Down
4 changes: 4 additions & 0 deletions iOS/src/toga_iOS/widgets/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def create(self):
self.native.interface = self.interface
self.native.impl = self

# Enable the content inspector. This was added in iOS 16.4.
# It is a no-op on earlier versions.
self.native.inspectable = True

self.native.navigationDelegate = self.native
self.native.uIDelegate = self.native

Expand Down

0 comments on commit 037084b

Please sign in to comment.