Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set webView.inspectable to true on iOS >= 16.4 #995

Closed
wants to merge 1 commit into from

Conversation

BBosman
Copy link

@BBosman BBosman commented Mar 21, 2023

Platforms affected

iOS

Motivation and Context

With the introduction of iOS 16.4 WKWebView instances will no longer be inspectable by default.

Details: Enabling the Inspection of Web Content in Apps

Description

This PR explicitly sets the inspectability to YES again for backwards compatibility, but offers an override option.

Preferably this new setting would be set to the default NO or wrapped in an #ifdef DEBUG, but that would be a breaking change and needs to wait till a (next) major release.

Testing

Tested the code in one of our own apps.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@NiklasMerz NiklasMerz added this to the 5.next milestone Jul 14, 2023
@peterknezek
Copy link

Hi,
the necessary change for inspectable WKWebView was also made in the apache/cordova-ios but in a little different way:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
    // With the introduction of iOS 16.4 the webview is no longer inspectable by default.
    // We'll honor that change for release builds, but will still allow inspection on debug builds by default.
    // We also introduce an override option, so consumers can influence this decision in their own build.
    if (@available(iOS 16.4, *)) {
#ifdef DEBUG
        BOOL allowWebviewInspectionDefault = YES;
#else
        BOOL allowWebviewInspectionDefault = NO;
#endif
        wkWebView.inspectable = [settings cordovaBoolSettingForKey:@"InspectableWebview" defaultValue:allowWebviewInspectionDefault];
    }
#endif

I suggest updating the PR code to match the one used in apache/cordova-ios. This will not only improve code consistency within the Cordova ecosystem but also determinate the default value for web on whether it is a debug build or not. In the PR value was always set to YES, which allowed inspection for all cases.

@breautek
Copy link
Contributor

breautek commented Aug 8, 2023

I suggest updating the PR code to match the one used in apache/cordova-ios. This will not only improve code consistency within the Cordova ecosystem but also determinate the default value for web on whether it is a debug build or not. In the PR value was always set to YES, which allowed inspection for all cases.

I agree with this. The rationale behind the way cordova-ios does it is to maintain older behaviour on older iOS devices, which xcode effectively hard-coded the web inspector as enabled for debug builds, and disabled for release builds and I think this PR should follow suite.

HazzMan2409

This comment was marked as outdated.

@HazzMan2409
Copy link

Sorry, I pushed a comment and then tried to delete it (I’m not used to GitHub…). Anyway, I tried to apply this PR but noticed that it caused my cordova build to fail. I thought it was the double semi-colon in the change that did it but it also looks like the settings object is not working correctly either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants