Skip to content

feat: enable/disable stop capturing network body #1362

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

Merged
merged 10 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...dev)

### Added

- Add support for enable/disable capturing network body. ([#1362](https://github.com/Instabug/Instabug-React-Native/pull/1362))

# Changelog

## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...dev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1294,4 +1294,21 @@ public void run() {

});
}
/**
* Enables or disables capturing network body.
* @param isEnabled A boolean to enable/disable capturing network body.
*/
@ReactMethod
public void setNetworkLogBodyEnabled(final boolean isEnabled) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
Instabug.setNetworkLogBodyEnabled(isEnabled);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,18 @@ public void testEnableAutoMasking(){

mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
}

@Test
public void testSetNetworkLogBodyEnabled() {
rnModule.setNetworkLogBodyEnabled(true);

mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(true));
}

@Test
public void testSetNetworkLogBodyDisabled() {
rnModule.setNetworkLogBodyEnabled(false);

mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(false));
}
}
9 changes: 9 additions & 0 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,13 @@ - (void)testEnableAutoMasking {
OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
}

- (void)testSetNetworkLogBodyEnabled {
id mock = OCMClassMock([IBGNetworkLogger class]);
BOOL isEnabled = YES;

OCMStub([mock setLogBodyEnabled:isEnabled]);
[self.instabugBridge setNetworkLogBodyEnabled:isEnabled];
OCMVerify([mock setLogBodyEnabled:isEnabled]);
}

@end
1 change: 1 addition & 0 deletions ios/RNInstabug/InstabugReactBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes;
- (void)removeFeatureFlags:(NSArray *)featureFlags;
- (void)removeAllFeatureFlags;
- (void)enableAutoMasking:(NSArray *)autoMaskingTypes;
- (void)setNetworkLogBodyEnabled:(BOOL)isEnabled;

@end
3 changes: 3 additions & 0 deletions ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,7 @@ + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion {
[Instabug setAutoMaskScreenshots: autoMaskingOptions];

};
RCT_EXPORT_METHOD(setNetworkLogBodyEnabled:(BOOL)isEnabled) {
IBGNetworkLogger.logBodyEnabled = isEnabled;
}
@end
9 changes: 9 additions & 0 deletions src/modules/NetworkLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import xhr, { NetworkData, ProgressCallback } from '../utils/XhrNetworkIntercept
import { isContentTypeNotAllowed, reportNetworkLog } from '../utils/InstabugUtils';
import { InstabugRNConfig } from '../utils/config';
import { Logger } from '../utils/logger';
import { NativeInstabug } from '../native/NativeInstabug';

export type { NetworkData };

Expand Down Expand Up @@ -114,3 +115,11 @@ export const apolloLinkRequestHandler: RequestHandler = (operation, forward) =>

return forward(operation);
};

/**
* Sets whether network body logs will be captured or not.
* @param isEnabled
*/
export const setNetworkLogBodyEnabled = (isEnabled: boolean) => {
NativeInstabug.setNetworkLogBodyEnabled(isEnabled);
};
1 change: 1 addition & 0 deletions src/native/NativeInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface InstabugNativeModule extends NativeModule {
): void;

setNetworkLoggingEnabled(isEnabled: boolean): void;
setNetworkLogBodyEnabled(isEnabled: boolean): void;

// Repro Steps APIs //
setReproStepsConfig(
Expand Down
1 change: 1 addition & 0 deletions test/mocks/mockInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const mockInstabug: InstabugNativeModule = {
isW3CaughtHeaderEnabled: jest.fn(),
registerW3CFlagsChangeListener: jest.fn(),
enableAutoMasking: jest.fn(),
setNetworkLogBodyEnabled: jest.fn(),
};

export default mockInstabug;
8 changes: 8 additions & 0 deletions test/modules/NetworkLogger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Interceptor from '../../src/utils/XhrNetworkInterceptor';
import { isContentTypeNotAllowed, reportNetworkLog } from '../../src/utils/InstabugUtils';
import InstabugConstants from '../../src/utils/InstabugConstants';
import { Logger } from '../../src/utils/logger';
import { NativeInstabug } from '../../src/native/NativeInstabug';

const clone = <T>(obj: T): T => {
return JSON.parse(JSON.stringify(obj));
Expand Down Expand Up @@ -282,4 +283,11 @@ describe('NetworkLogger Module', () => {

expect(reportNetworkLog).toHaveBeenCalledWith(networkData);
});

it('should call the native method setNetworkLogBodyEnabled', () => {
NetworkLogger.setNetworkLogBodyEnabled(true);

expect(NativeInstabug.setNetworkLogBodyEnabled).toBeCalledTimes(1);
expect(NativeInstabug.setNetworkLogBodyEnabled).toBeCalledWith(true);
});
});