Skip to content

Commit bc5e6b0

Browse files
authored
🤝 Merge pull request #8 from Instabug/feature/JS_CR
Feature/js cr
2 parents 996773c + 5b9ec8e commit bc5e6b0

31 files changed

+251
-65
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ android {
2121

2222
dependencies {
2323
compile 'com.facebook.react:react-native:0.20.+'
24-
compile ('com.instabug.library:instabug:4.13.2'){
24+
compile ('com.instabug.library:instabug:4.13.3'){
2525
exclude group: 'com.android.support:appcompat-v7'
2626
}
2727

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
import com.instabug.reactlibrary.utils.ArrayUtil;
4040
import com.instabug.reactlibrary.utils.MapUtil;
4141

42+
import org.json.JSONException;
43+
import org.json.JSONObject;
44+
45+
import java.lang.reflect.InvocationTargetException;
46+
import java.lang.reflect.Method;
4247
import java.util.ArrayList;
4348
import java.util.Arrays;
4449
import java.util.HashMap;
@@ -368,6 +373,82 @@ public void setFileAttachment(String fileUri, String fileNameWithExtension) {
368373
}
369374
}
370375

376+
/**
377+
* Send unhandled JS error object
378+
*
379+
* @param exceptionObject Exception object to be sent to Instabug's servers
380+
*/
381+
@ReactMethod
382+
public void sendJSCrash(String exceptionObject) {
383+
try {
384+
sendJSCrashByReflection(exceptionObject, false);
385+
} catch (Exception e) {
386+
e.printStackTrace();
387+
}
388+
}
389+
390+
/**
391+
* Send handled JS error object
392+
*
393+
* @param exceptionObject Exception object to be sent to Instabug's servers
394+
*/
395+
@ReactMethod
396+
public void sendHandledJSCrash(String exceptionObject) {
397+
try {
398+
sendJSCrashByReflection(exceptionObject, true);
399+
} catch (Exception e) {
400+
e.printStackTrace();
401+
}
402+
}
403+
404+
/**
405+
* Sets whether crash reporting feature is Enabled or Disabled
406+
*
407+
* @param isEnabled Exception object to be sent to Instabug's servers
408+
*/
409+
@ReactMethod
410+
public void setCrashReportingEnabled(boolean isEnabled) {
411+
try {
412+
if(isEnabled) {
413+
Instabug.setCrashReportingState(Feature.State.ENABLED);
414+
} else {
415+
Instabug.setCrashReportingState(Feature.State.DISABLED);
416+
}
417+
} catch (Exception e) {
418+
e.printStackTrace();
419+
}
420+
}
421+
422+
private void sendJSCrashByReflection(String exceptionObject, boolean isHandled) {
423+
try {
424+
JSONObject newJSONObject = new JSONObject(exceptionObject);
425+
Method method = getMethod(Class.forName("com.instabug.crash.InstabugCrash"), "reportException");
426+
if (method != null) {
427+
method.invoke(null, newJSONObject, isHandled);
428+
}
429+
} catch (ClassNotFoundException e) {
430+
e.printStackTrace();
431+
} catch (InvocationTargetException e) {
432+
e.printStackTrace();
433+
} catch (IllegalAccessException e) {
434+
e.printStackTrace();
435+
} catch (JSONException e) {
436+
e.printStackTrace();
437+
}
438+
439+
}
440+
441+
public static Method getMethod(Class clazz, String methodName) {
442+
final Method[] methods = clazz.getDeclaredMethods();
443+
for (Method method : methods) {
444+
if (method.getName().equals(methodName)) {
445+
method.setAccessible(true);
446+
return method;
447+
}
448+
}
449+
return null;
450+
}
451+
371452
/**
372453
* If your app already acquires the user's email address and you provide it to this method,
373454
* Instabug will pre-fill the user email in reports.

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativePackage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public RNInstabugReactnativePackage(String androidApplicationToken, Application
5656

5757
mInstabug = new Instabug.Builder(this.androidApplication, this.mAndroidApplicationToken)
5858
.setInvocationEvent(this.invocationEvent)
59-
.setCrashReportingState(Feature.State.DISABLED)
59+
.setCrashReportingState(Feature.State.ENABLED)
6060
.setReproStepsState(State.DISABLED)
6161
.build();
6262

index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import {NativeModules, NativeAppEventEmitter, DeviceEventEmitter, Platform} from "react-native";
22
let {Instabug} = NativeModules;
3+
import InstabugUtils from './utils/InstabugUtils.js';
4+
5+
InstabugUtils.captureJsErrors();
36

47
/**
58
* Instabug
@@ -101,6 +104,14 @@ module.exports = {
101104
Instabug.setUserStepsEnabled(isUserStepsEnabled);
102105
},
103106

107+
/**
108+
* Report un-caught exceptions to Instabug dashboard
109+
* We don't send exceptions from __DEV__, since it's way too noisy!
110+
*/
111+
setCrashReportingEnabled: function(enableCrashReporter){
112+
Instabug.setCrashReportingEnabled(enableCrashReporter);
113+
},
114+
104115
/**
105116
* Sets a block of code to be executed before sending each report.
106117
* This block is executed in the background before sending each report. Could
@@ -899,6 +910,26 @@ module.exports = {
899910
}
900911
},
901912

913+
/**
914+
* Send handled JS error object
915+
*
916+
* @param errorObject Error object to be sent to Instabug's servers
917+
*/
918+
reportJSException: function(errorObject) {
919+
let jsStackTrace = InstabugUtils.parseErrorStack(errorObject);
920+
var jsonObject = {
921+
message: errorObject.name + " - " + errorObject.message,
922+
os: Platform.OS,
923+
platform: 'react_native',
924+
exception: jsStackTrace
925+
}
926+
if(Platform.OS === 'android') {
927+
Instabug.sendHandledJSCrash(JSON.stringify(jsonObject));
928+
} else {
929+
Instabug.sendHandledJSCrash(jsonObject);
930+
}
931+
},
932+
902933
/**
903934
* Sets the default position at which the Instabug screen recording button will be shown.
904935
* Different orientations are already handled.

ios/Instabug.framework/Headers/Instabug.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2018 by Instabug, Inc., all rights reserved.
77
8-
Version: 7.12.3
8+
Version: 7.12.5
99
*/
1010

1111
#import <Foundation/Foundation.h>
@@ -378,7 +378,7 @@ typedef void (^NetworkObfuscationCompletionBlock)(NSData *data, NSURLResponse *r
378378
/**
379379
@brief Shows/Hides email field.
380380
381-
@discussion Defaults to show email field.
381+
@discussion Defaults to show email field. If set to NO the email field will not be required regardless of previous or future calls to setEmailFieldRequired:.
382382
383383
@param isShowingEmailField YES to show the email field, NO to hide it.
384384
*/
@@ -463,7 +463,8 @@ typedef void (^NetworkObfuscationCompletionBlock)(NSData *data, NSURLResponse *r
463463
464464
@deprecated Use setEmailFieldRequired:forAction: instead.
465465
466-
@discussion Defaults to YES.
466+
@discussion Defaults to YES. If email field is set to be hidden using + [Instabug setShowEmailField:NO], email field
467+
will always be optional regardless of the whether this method was called or not.
467468
468469
@param isEmailFieldRequired A boolean to indicate whether email field is required or not.
469470
*/

ios/Instabug.framework/Info.plist

0 Bytes
Binary file not shown.

ios/Instabug.framework/Instabug

176 Bytes
Binary file not shown.

ios/Instabug.framework/_CodeSignature/CodeResources

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<dict>
77
<key>Headers/Instabug.h</key>
88
<data>
9-
x58V5/AZd4q5E7jPVi0tdhKez70=
9+
wwOLwWc4iG8u5RCEgnEbViLJru4=
1010
</data>
1111
<key>Info.plist</key>
1212
<data>
13-
4Jy8Yn1EuGKXqRymL6Sgk907mK8=
13+
HPAveR0c+whbq5mPNp5qMyz1TnU=
1414
</data>
1515
<key>Modules/module.modulemap</key>
1616
<data>
@@ -23,11 +23,11 @@
2323
<dict>
2424
<key>hash</key>
2525
<data>
26-
x58V5/AZd4q5E7jPVi0tdhKez70=
26+
wwOLwWc4iG8u5RCEgnEbViLJru4=
2727
</data>
2828
<key>hash2</key>
2929
<data>
30-
tI8SWLNyo50BAffKMVwvBPCeHSEZm+G7wutFUvhnBRU=
30+
S/NXH4SJqkK91PzzkM9R0MiqjfoJgQeFjfAb7YuTmps=
3131
</data>
3232
</dict>
3333
<key>Modules/module.modulemap</key>

ios/InstabugCore.framework/Headers/IBGTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2018 by Instabug, Inc., all rights reserved.
77
8-
Version: 7.12.3
8+
Version: 7.12.5
99
*/
1010

1111
#import <UIKit/UIKit.h>

ios/InstabugCore.framework/Headers/InstabugCore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Copyright: (c) 2013-2018 by Instabug, Inc., all rights reserved.
77
8-
Version: 7.12.3
8+
Version: 7.12.5
99
*/
1010

1111
#import <Foundation/Foundation.h>
Binary file not shown.
Binary file not shown.
-3 Bytes
Binary file not shown.
-2 Bytes
Binary file not shown.
Binary file not shown.
5 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
-7 Bytes
Binary file not shown.
-4 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

ios/InstabugCore.framework/Info.plist

0 Bytes
Binary file not shown.
17 KB
Binary file not shown.

0 commit comments

Comments
 (0)