Disable same-origin policy on iOS WKWebView with private API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Allows disabling Same-Origin Policy on iOS WKWebView. | |
| // Tested on iOS 12.4. | |
| // Uses private API; obviously can't be used on app store. | |
| @import WebKit; | |
| @import ObjectiveC; | |
| void WKPreferencesSetWebSecurityEnabled(id, bool); | |
| @interface WDBFakeWebKitPointer: NSObject | |
| @property (nonatomic) void* _apiObject; | |
| @end | |
| @implementation WDBFakeWebKitPointer | |
| @end | |
| void WDBSetWebSecurityEnabled(WKPreferences* prefs, bool enabled) { | |
| Ivar ivar = class_getInstanceVariable([WKPreferences class], "_preferences"); | |
| void* realPreferences = (void*)(((uintptr_t)prefs) + ivar_getOffset(ivar)); | |
| WDBFakeWebKitPointer* fake = [WDBFakeWebKitPointer new]; | |
| fake._apiObject = realPreferences; | |
| WKPreferencesSetWebSecurityEnabled(fake, enabled); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment