Skip to content

Debugging JSContext in safari is not enabled for iOS >= 16.4 #39488

@jefflewis

Description

@jefflewis

Description

As of iOS 16.4 Apple requires the isInspectable property of the JSContext to be set to true in order for the JSContext to be shown in the Safari inspector window, as documented as a debugging tool here.

This patch would apply this property to DEBUG builds and is what I have done to successfully get debugging working again.

If I open this as a pull request, would it be accepted?

patch:

--- a/node_modules/react-native/ReactCommon/jsc/JSCRuntime.cpp
+++ b/node_modules/react-native/ReactCommon/jsc/JSCRuntime.cpp
@@ -409,12 +409,12 @@ JSCRuntime::~JSCRuntime() {
@@ -398,6 +398,11 @@ JSCRuntime::JSCRuntime(JSGlobalContextRef ctx)
       stringCounter_(0)
 #endif
 {
+#ifndef NDEBUG
+  if (__builtin_available(iOS 16.4, *)) {
+    JSGlobalContextSetInspectable(ctx, true);
+  }
+#endif
 }

Reference:

https://webkit.org/blog/13936/enabling-the-inspection-of-web-content-in-apps/

React Native Version

0.72

Output of npx react-native info

npx react-native info
warn Package @sentry/react-native contains invalid configuration: "dependency.platforms.ios.sharedLibraries" is not allowed,"dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
warn Package rn-fetch-blob contains invalid configuration: "dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
info Fetching system and libraries information...
System:
  OS: macOS 13.4.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 78.22 MB / 16.00 GB
  Shell:
    version: 3.6.1
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 16.20.2
    path: ~/.asdf/installs/nodejs/16.20.2/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.asdf/installs/nodejs/16.20.2/bin/yarn
  npm:
    version: 8.19.4
    path: ~/.asdf/plugins/nodejs/shims/npm
  Watchman:
    version: 2023.05.08.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.0
    path: /Users/jeff/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - visionOS 1.0
      - watchOS 10.0
  Android SDK:
    API Levels:
      - "31"
      - "32"
      - "33"
    Build Tools:
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
    System Images:
      - android-31 | Google APIs ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2022.1 AI-221.6008.13.2211.9619390
  Xcode:
    version: 15.0/15A5229m
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.17
    path: /Users/jeff/.asdf/shims/javac
  Ruby:
    version: 2.7.6
    path: /Users/jeff/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 9.3.3
    wanted: ^9.0.0
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.0
    wanted: 0.72.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: false
iOS:
  hermesEnabled: false
  newArchEnabled: false

Steps to reproduce

DEBUG Build any RN iOS with a target of iOS >= 16.4 and see that it is not available for inspection per the documentation.

Snack, screenshot, or link to a repository

Any RN app will demonstrate this, so the base snack should show when configured with a DEBUG build.

https://snack.expo.dev/TRFqpEjAi

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions