Skip to content

Commit

Permalink
Finish Release-6.0.0-20241014
Browse files Browse the repository at this point in the history
  • Loading branch information
lszzy committed Oct 14, 2024
2 parents 6bb0518 + a5d9f01 commit 8aff484
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 56 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [6.0.0] - 2024-10-14

### Added
* Added Eruda debugging function for WKWebView
* Compatible with iOS 18, fix WKWebView injection failure issue

## [5.5.0] - 2024-09-09

### Added
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## [6.0.0] - 2024-10-14

### Added
* WKWebView新增注入Eruda调试功能
* 兼容iOS 18,修复WKWebView注入失败问题

## [5.5.0] - 2024-09-09

### Added
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- FWDebug (5.4.3)
- FWDebug (6.0.0)

DEPENDENCIES:
- FWDebug (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
FWDebug: 09201e5ee86382268f0669970f96ed46cebbeefc
FWDebug: 344424b84ad33789415bd704901b3581cd50f48d

PODFILE CHECKSUM: bfd25050ff2f8ce8d3b20e2e93e52d3045df26e7

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/FWDebug.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion FWDebug.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "FWDebug"
s.version = "5.5.0"
s.version = "6.0.0"
s.summary = "ios debug library"
s.homepage = "http://wuyong.site"
s.license = "MIT"
Expand Down

Large diffs are not rendered by default.

128 changes: 94 additions & 34 deletions FWDebug/Classes/Private/FLEX/FWDebugAppConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef NS_ENUM(NSInteger, FWDebugAppConfigSectionTimeRow) {
typedef NS_ENUM(NSInteger, FWDebugAppConfigSectionWebRow) {
FWDebugAppConfigSectionWebRowNetwork = 0,
FWDebugAppConfigSectionWebRowVConsole,
FWDebugAppConfigSectionWebRowEruda,
FWDebugAppConfigSectionWebRowJavascript,
FWDebugAppConfigSectionWebRowClear,
FWDebugAppConfigSectionWebRowCount,
Expand Down Expand Up @@ -88,6 +89,10 @@ + (void)fwDebugLoad
[FWDebugAppConfig webViewInjectVConsole];
}

if ([self webViewErudaEnabled]) {
[FWDebugAppConfig webViewInjectEruda];
}

if ([self webViewJavascriptEnabled]) {
[FWDebugAppConfig webViewInjectJavascript];
}
Expand Down Expand Up @@ -227,6 +232,12 @@ + (BOOL)webViewInjectionEnabled
return value ? [value boolValue] : NO;
}

+ (BOOL)webViewErudaEnabled
{
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"FWDebugWebViewErudaEnabled"];
return value ? [value boolValue] : NO;
}

+ (BOOL)webViewJavascriptEnabled
{
BOOL value = [[NSUserDefaults standardUserDefaults] boolForKey:@"FWDebugWebViewJavascriptEnabled"];
Expand Down Expand Up @@ -274,27 +285,64 @@ + (void)unregisterURLProtocolScheme:(NSString *)scheme
}
}

+ (void)webViewInjectBlock:(void (^)(WKUserContentController *userContentController))block
{
[FWDebugManager swizzleMethod:@selector(setUserContentController:) in:[WKWebViewConfiguration class] withBlock:^id(__unsafe_unretained Class targetClass, SEL originalCMD, IMP (^originalIMP)(void)) {
return ^(__unsafe_unretained WKWebViewConfiguration *selfObject, WKUserContentController *userContentController) {
((void (*)(id, SEL, WKUserContentController *))originalIMP())(selfObject, originalCMD, userContentController);
block(userContentController);
};
}];

[FWDebugManager swizzleMethod:@selector(init) in:[WKWebViewConfiguration class] withBlock:^id(__unsafe_unretained Class targetClass, SEL originalCMD, IMP (^originalIMP)(void)) {
return ^WKWebViewConfiguration *(__unsafe_unretained WKWebViewConfiguration *selfObject) {
WKWebViewConfiguration *webViewConfiguration = ((WKWebViewConfiguration *(*)(id, SEL))originalIMP())(selfObject, originalCMD);
block(webViewConfiguration.userContentController);
return webViewConfiguration;
};
}];
}

+ (void)webViewInjectVConsole
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[FWDebugManager swizzleMethod:@selector(setUserContentController:) in:[WKWebViewConfiguration class] withBlock:^id(__unsafe_unretained Class targetClass, SEL originalCMD, IMP (^originalIMP)(void)) {
return ^(__unsafe_unretained WKWebViewConfiguration *selfObject, WKUserContentController *userContentController) {
((void (*)(id, SEL, WKUserContentController *))originalIMP())(selfObject, originalCMD, userContentController);
if (![FWDebugAppConfig webViewInjectionEnabled]) return;
BOOL hasInjection = [objc_getAssociatedObject(userContentController, @selector(webViewInjectVConsole)) boolValue];
if (hasInjection) return;

NSString *vConsoleFile = [[NSBundle bundleForClass:[FWDebugAppConfig class]] pathForResource:@"GCDWebUploader.bundle/Contents/Resources/js/vconsole.min.js" ofType:nil];
if (vConsoleFile.length < 1) return;
NSString *vConsoleJs = [NSString stringWithContentsOfFile:vConsoleFile encoding:NSUTF8StringEncoding error:nil];
if (vConsoleJs.length < 1) return;

NSString *sourceJs = [vConsoleJs stringByAppendingString:@"if(typeof(VConsole)!='undefined'&&typeof(vConsole)=='undefined'){var vConsole=new VConsole();}"];
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:sourceJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userContentController addUserScript:userScript];
objc_setAssociatedObject(userContentController, @selector(webViewInjectVConsole), @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
};
[self webViewInjectBlock:^(WKUserContentController *userContentController) {
if (![FWDebugAppConfig webViewInjectionEnabled]) return;
BOOL hasInjection = [objc_getAssociatedObject(userContentController, @selector(webViewInjectVConsole)) boolValue];
if (hasInjection) return;

NSString *vConsoleFile = [[NSBundle bundleForClass:[FWDebugAppConfig class]] pathForResource:@"GCDWebUploader.bundle/Contents/Resources/js/vconsole.min.js" ofType:nil];
if (vConsoleFile.length < 1) return;
NSString *vConsoleJs = [NSString stringWithContentsOfFile:vConsoleFile encoding:NSUTF8StringEncoding error:nil];
if (vConsoleJs.length < 1) return;

NSString *sourceJs = [vConsoleJs stringByAppendingString:@"if(typeof(VConsole)!='undefined'&&typeof(vConsole)=='undefined'){var vConsole=new VConsole();}"];
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:sourceJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userContentController addUserScript:userScript];
objc_setAssociatedObject(userContentController, @selector(webViewInjectVConsole), @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}];
});
}

+ (void)webViewInjectEruda
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self webViewInjectBlock:^(WKUserContentController *userContentController) {
if (![FWDebugAppConfig webViewErudaEnabled]) return;
BOOL hasInjection = [objc_getAssociatedObject(userContentController, @selector(webViewInjectEruda)) boolValue];
if (hasInjection) return;

NSString *erudaFile = [[NSBundle bundleForClass:[FWDebugAppConfig class]] pathForResource:@"GCDWebUploader.bundle/Contents/Resources/js/eruda.min.js" ofType:nil];
if (erudaFile.length < 1) return;
NSString *erudaJs = [NSString stringWithContentsOfFile:erudaFile encoding:NSUTF8StringEncoding error:nil];
if (erudaJs.length < 1) return;

NSString *sourceJs = [erudaJs stringByAppendingString:@"if(typeof(eruda)!='undefined'&&typeof(erudaFWDebug)=='undefined'){var erudaFWDebug=true;eruda.init();}"];
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:sourceJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userContentController addUserScript:userScript];
objc_setAssociatedObject(userContentController, @selector(webViewInjectEruda), @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}];
});
}
Expand All @@ -303,23 +351,20 @@ + (void)webViewInjectJavascript
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[FWDebugManager swizzleMethod:@selector(setUserContentController:) in:[WKWebViewConfiguration class] withBlock:^id(__unsafe_unretained Class targetClass, SEL originalCMD, IMP (^originalIMP)(void)) {
return ^(__unsafe_unretained WKWebViewConfiguration *selfObject, WKUserContentController *userContentController) {
((void (*)(id, SEL, WKUserContentController *))originalIMP())(selfObject, originalCMD, userContentController);
if (![FWDebugAppConfig webViewJavascriptEnabled]) return;
BOOL hasInjection = [objc_getAssociatedObject(userContentController, @selector(webViewInjectJavascript)) boolValue];
if (hasInjection) return;

NSString *sourceJs = [FWDebugAppConfig webViewJavascriptString];
if (sourceJs.length < 1) return;
if ([sourceJs hasPrefix:@"http"]) {
sourceJs = [NSString stringWithFormat:@"(function(){var script=document.createElement('script');script.src='%@';document.body.appendChild(script);})();", sourceJs];
}

WKUserScript *userScript = [[WKUserScript alloc] initWithSource:sourceJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userContentController addUserScript:userScript];
objc_setAssociatedObject(userContentController, @selector(webViewInjectJavascript), @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
};
[self webViewInjectBlock:^(WKUserContentController *userContentController) {
if (![FWDebugAppConfig webViewJavascriptEnabled]) return;
BOOL hasInjection = [objc_getAssociatedObject(userContentController, @selector(webViewInjectJavascript)) boolValue];
if (hasInjection) return;

NSString *sourceJs = [FWDebugAppConfig webViewJavascriptString];
if (sourceJs.length < 1) return;
if ([sourceJs hasPrefix:@"http"]) {
sourceJs = [NSString stringWithFormat:@"(function(){var script=document.createElement('script');script.src='%@';document.body.appendChild(script);})();", sourceJs];
}

WKUserScript *userScript = [[WKUserScript alloc] initWithSource:sourceJs injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
[userContentController addUserScript:userScript];
objc_setAssociatedObject(userContentController, @selector(webViewInjectJavascript), @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}];
});
}
Expand Down Expand Up @@ -529,6 +574,10 @@ - (void)configSwitch:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath
cell.textLabel.text = @"Inject vConsole";
cell.detailTextLabel.text = nil;
cellSwitch.on = [self.class webViewInjectionEnabled];
} else if (indexPath.section == FWDebugAppConfigSectionWeb && indexPath.row == FWDebugAppConfigSectionWebRowEruda) {
cell.textLabel.text = @"Inject Eruda";
cell.detailTextLabel.text = nil;
cellSwitch.on = [self.class webViewErudaEnabled];
} else if (indexPath.section == FWDebugAppConfigSectionWeb && indexPath.row == FWDebugAppConfigSectionWebRowJavascript) {
cell.textLabel.text = @"Inject Javascript";
NSString *detail = [self.class webViewJavascriptString];
Expand Down Expand Up @@ -633,6 +682,17 @@ - (void)actionSwitch:(NSIndexPath *)indexPath {
[[NSUserDefaults standardUserDefaults] synchronize];
[self configSwitch:cell indexPath:indexPath];
}
} else if (indexPath.section == FWDebugAppConfigSectionWeb && indexPath.row == FWDebugAppConfigSectionWebRowEruda) {
if (!cellSwitch.on) {
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"FWDebugWebViewErudaEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self configSwitch:cell indexPath:indexPath];
[FWDebugAppConfig webViewInjectEruda];
} else {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"FWDebugWebViewErudaEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self configSwitch:cell indexPath:indexPath];
}
} else if (indexPath.section == FWDebugAppConfigSectionWeb && indexPath.row == FWDebugAppConfigSectionWebRowJavascript) {
if (!cellSwitch.on) {
typeof(self) __weak weakSelf = self;
Expand Down
10 changes: 5 additions & 5 deletions Framework/FWDebug.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>FWDebug.framework/FWDebug</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>FWDebug.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>FWDebug.framework/FWDebug</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>FWDebug.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
<data>
q8+XGLTNkXlzO3jy+O1wSnqvxDQ=
</data>
<key>GCDWebUploader.bundle/Contents/Resources/js/eruda.min.js</key>
<data>
MhLTPkebTOv+vojHtS01c4P900k=
</data>
<key>GCDWebUploader.bundle/Contents/Resources/js/html5shiv.min.js</key>
<data>
PHs2lIXK3VhdJL5EcB5FnIqlTWA=
Expand Down Expand Up @@ -267,7 +271,7 @@
</data>
<key>Info.plist</key>
<data>
c66nXoh4q7CwsmJxqg1/+6YO2/A=
joBOf5k2s/kfP0LtI44nDKy6KKg=
</data>
<key>Modules/FWDebug.swiftmodule/arm64-apple-ios-simulator.abi.json</key>
<data>
Expand All @@ -287,7 +291,7 @@
</data>
<key>Modules/FWDebug.swiftmodule/arm64-apple-ios-simulator.swiftmodule</key>
<data>
BOG/4aKkHBB8gQT0tvDvk2h3opY=
nMWjOJv1IUHuKu9qLAgtaS2AM6o=
</data>
<key>Modules/FWDebug.swiftmodule/x86_64-apple-ios-simulator.abi.json</key>
<data>
Expand All @@ -307,7 +311,7 @@
</data>
<key>Modules/FWDebug.swiftmodule/x86_64-apple-ios-simulator.swiftmodule</key>
<data>
9jBN/k7RFliUy2oUzzsAL8tqXyA=
j8sB65X1xTULMVHarrqgwEtp3zQ=
</data>
<key>Modules/module.modulemap</key>
<data>
Expand Down Expand Up @@ -451,6 +455,13 @@
P5wgmKbS8kXoGy/aWJUhFO2EIcg6IkJ9eNlArfoMLWg=
</data>
</dict>
<key>GCDWebUploader.bundle/Contents/Resources/js/eruda.min.js</key>
<dict>
<key>hash2</key>
<data>
mGTnxu5oOutn/k2Cs9vbHi0YCXEFLGFWmsKoaHhkcLE=
</data>
</dict>
<key>GCDWebUploader.bundle/Contents/Resources/js/html5shiv.min.js</key>
<dict>
<key>hash2</key>
Expand Down Expand Up @@ -798,7 +809,7 @@
<dict>
<key>hash2</key>
<data>
LEnwlZmwa4SnxlzhAHT3pDvglIC2j+p62G7CTQv1NQw=
2MBb6uNw56c828RDALpREKqzkIFLHLoSyP5htuufccM=
</data>
</dict>
<key>Modules/FWDebug.swiftmodule/x86_64-apple-ios-simulator.abi.json</key>
Expand Down Expand Up @@ -833,7 +844,7 @@
<dict>
<key>hash2</key>
<data>
w1p2FH3Ci0WCQs9umRo7yd7xAojS+M+d9JQ7slDn7OU=
wb878Cv4TRRq+uBXEeNXyCWDhE9AzdsAw70YWzU/uEY=
</data>
</dict>
<key>Modules/module.modulemap</key>
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "FWDebug",
url: "https://github.com/lszzy/FWDebug/releases/download/5.5.0/FWDebug.xcframework.zip",
checksum: "9e5b06907e54adf494754cb61f334e52029555bab8dc938a29521acf2293faa2"
url: "https://github.com/lszzy/FWDebug/releases/download/6.0.0/FWDebug.xcframework.zip",
checksum: "30da5a8a975e2d865a34b771e445aa34ee3e2adebdf5877286ea91294db879a4"
)
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Real machine or simulator shaking within 5 seconds twice to appear debug menu. F
* APNs remote push sending function ("Fake Notification" entrance "APNS Client" configuration)
* View the startup time, controller loading and network request time ("Time Profiler" entry or click the frame rate icon to quickly view the current controller time)
* WKWebView request packet capture function (just check "Network History" after turning on the "App Config" switch)
* WKWebView automatically injects the vConsole function (just turn on WKWebView after turning on the "App Config" switch)
* WKWebView automatically injects the vConsole or Eruda function (just turn on WKWebView after turning on the "App Config" switch)
* WebSite static web server ("Web Server" entrance, the web file can be placed in Documents/website)
* WKWebView cleanup cache ("App Config" entry)

Expand Down
Loading

0 comments on commit 8aff484

Please sign in to comment.