@@ -93,6 +93,7 @@ class CountlyClass {
9393 #contentZoneTimer;
9494 #contentZoneTimerInterval;
9595 #contentIframeID;
96+ #crashFilterCallback;
9697 constructor ( ob ) {
9798 this . #self = this ;
9899 this . #global = ! Countly . i ;
@@ -147,6 +148,7 @@ class CountlyClass {
147148 this . #inContentZone = false ;
148149 this . #contentZoneTimer = null ;
149150 this . #contentIframeID = "cly-content-iframe" ;
151+ this . #crashFilterCallback = null ;
150152
151153 try {
152154 localStorage . setItem ( "cly_testLocal" , true ) ;
@@ -218,6 +220,7 @@ class CountlyClass {
218220 this . hcStatusCode = this . #getValueFromStorage( healthCheckCounterEnum . statusCode ) || - 1 ;
219221 this . hcErrorMessage = this . #getValueFromStorage( healthCheckCounterEnum . errorMessage ) || "" ;
220222 this . #contentZoneTimerInterval = getConfig ( "content_zone_timer_interval" , ob , null ) ;
223+ this . #crashFilterCallback = getConfig ( "crash_filter_callback" , ob , null ) ;
221224
222225 if ( this . #contentZoneTimerInterval) {
223226 this . #contentTimeInterval = Math . max ( this . #contentZoneTimerInterval, 15 ) * 1000 ;
@@ -1027,8 +1030,12 @@ class CountlyClass {
10271030 if ( this . enableOrientationTracking ) {
10281031 // report orientation
10291032 this . #report_orientation( ) ;
1033+ let orientationTimeout ;
10301034 add_event_listener ( window , "resize" , ( ) => {
1031- this . #report_orientation( ) ;
1035+ clearTimeout ( orientationTimeout ) ;
1036+ orientationTimeout = setTimeout ( ( ) => {
1037+ this . #report_orientation( ) ;
1038+ } , 200 ) ;
10321039 } ) ;
10331040 }
10341041 this . #lastBeat = getTimestamp ( ) ;
@@ -3647,8 +3654,21 @@ class CountlyClass {
36473654
36483655 // send userAgent string with the crash object incase it gets removed by a gateway
36493656 var req = { } ;
3650- req . crash = JSON . stringify ( obj ) ;
36513657 req . metrics = JSON . stringify ( { _ua : metrics . _ua } ) ;
3658+
3659+ if ( this . #crashFilterCallback && typeof this . #crashFilterCallback === "function" ) {
3660+ this . #log( logLevelEnums . VERBOSE , "recordError, Applying crash filter to:[" + JSON . stringify ( obj ) + "]" ) ;
3661+ obj = this . #crashFilterCallback( obj ) ;
3662+ this . #log( logLevelEnums . VERBOSE , "recordError, Filtered crash object:[" + JSON . stringify ( obj ) + "]" ) ;
3663+ }
3664+
3665+ if ( ! obj ) {
3666+ this . #log( logLevelEnums . DEBUG , "recordError, Crash object was filtered out" ) ;
3667+ return ;
3668+ }
3669+
3670+ // error should be re-truncated incase it was modified by the filter
3671+ req . crash = JSON . stringify ( obj ) ;
36523672
36533673 this . #toRequestQueue( req ) ;
36543674 }
@@ -3783,6 +3803,8 @@ class CountlyClass {
37833803 try {
37843804 var iframe = document . createElement ( "iframe" ) ;
37853805 iframe . id = this . #contentIframeID;
3806+ // always https in the future
3807+ // response.html = response.html.replace(/http:\/\//g, "https://");
37863808 iframe . src = response . html ;
37873809 iframe . style . position = "absolute" ;
37883810 var dimensionToUse = response . geo . p ;
@@ -3843,7 +3865,7 @@ class CountlyClass {
38433865 if ( resize_me ) {
38443866 this . #log( logLevelEnums . DEBUG , "interpretContentMessage, Resizing iframe" ) ;
38453867 const resInfo = this . #getResolution( true ) ;
3846- if ( ! resize_me . l || ! resize_me . p || ! resize_me . l . x || ! resize_me . l . y || ! resize_me . l . w || ! resize_me . l . h || ! resize_me . p . x || ! resize_me . p . y || ! resize_me . p . w || ! resize_me . p . h ) {
3868+ if ( ! resize_me . l || ! resize_me . p ) {
38473869 this . #log( logLevelEnums . ERROR , "interpretContentMessage, Invalid resize object" ) ;
38483870 return ;
38493871 }
@@ -4728,7 +4750,7 @@ class CountlyClass {
47284750 try {
47294751 var parsedResponse = JSON . parse ( str ) ;
47304752 // check if parsed response is a JSON object or JSON array, if not it is not valid
4731- if ( ( Object . prototype . toString . call ( parsedResponse ) !== "[object Object]" ) && ( ! Array . isArray ( parsedResponse ) ) ) {
4753+ if ( ( Object . prototype . toString . call ( parsedResponse ) !== "[object Object]" ) && ( ! Array . isArray ( parsedResponse ) ) && parsedResponse !== "No content block found!" ) {
47324754 this . #log( logLevelEnums . ERROR , "Http response is not JSON Object nor JSON Array" ) ;
47334755 return false ;
47344756 }
@@ -4913,20 +4935,24 @@ class CountlyClass {
49134935 useLocalStorage = this . #lsSupport;
49144936 }
49154937
4916- // Get value
4917- if ( useLocalStorage ) { // Native support
4918- data = localStorage . getItem ( key ) ;
4919- }
4920- else if ( this . storage !== "localstorage" ) { // Use cookie
4921- data = this . #readCookie( key ) ;
4922- }
4923-
4924- // we return early without parsing if we are trying to get the device ID. This way we are keeping it as a string incase it was numerical.
4925- if ( key . endsWith ( "cly_id" ) ) {
4926- return data ;
4938+ try {
4939+ // Get value
4940+ if ( useLocalStorage ) { // Native support
4941+ data = localStorage . getItem ( key ) ;
4942+ }
4943+ else if ( this . storage !== "localstorage" ) { // Use cookie
4944+ data = this . #readCookie( key ) ;
4945+ }
4946+
4947+ // we return early without parsing if we are trying to get the device ID. This way we are keeping it as a string incase it was numerical.
4948+ if ( key . endsWith ( "cly_id" ) ) {
4949+ return data ;
4950+ }
4951+
4952+ return this . deserialize ( data ) ;
4953+ } catch ( error ) {
4954+
49274955 }
4928-
4929- return this . deserialize ( data ) ;
49304956 }
49314957
49324958 /**
@@ -4952,26 +4978,30 @@ class CountlyClass {
49524978 }
49534979 }
49544980
4955- if ( typeof value !== "undefined" && value !== null ) {
4956- // use dev provided storage if available
4957- if ( typeof this . storage === "object" && typeof this . storage . setItem === "function" ) {
4958- this . storage . setItem ( key , value ) ;
4959- return ;
4960- }
4961-
4962- // developer set values takes priority
4963- if ( useLocalStorage === undefined ) {
4964- useLocalStorage = this . #lsSupport;
4965- }
4966-
4967- value = this . serialize ( value ) ;
4968- // Set the store
4969- if ( useLocalStorage ) { // Native support
4970- localStorage . setItem ( key , value ) ;
4971- }
4972- else if ( this . storage !== "localstorage" ) { // Use Cookie
4973- this . #createCookie( key , value , 30 ) ;
4981+ try {
4982+ if ( typeof value !== "undefined" && value !== null ) {
4983+ // use dev provided storage if available
4984+ if ( typeof this . storage === "object" && typeof this . storage . setItem === "function" ) {
4985+ this . storage . setItem ( key , value ) ;
4986+ return ;
4987+ }
4988+
4989+ // developer set values takes priority
4990+ if ( useLocalStorage === undefined ) {
4991+ useLocalStorage = this . #lsSupport;
4992+ }
4993+
4994+ value = this . serialize ( value ) ;
4995+ // Set the store
4996+ if ( useLocalStorage ) { // Native support
4997+ localStorage . setItem ( key , value ) ;
4998+ }
4999+ else if ( this . storage !== "localstorage" ) { // Use Cookie
5000+ this . #createCookie( key , value , 30 ) ;
5001+ }
49745002 }
5003+ } catch ( error ) {
5004+ // silent fail
49755005 }
49765006 }
49775007
@@ -4997,22 +5027,26 @@ class CountlyClass {
49975027 }
49985028 }
49995029
5000- // use dev provided storage if available
5001- if ( typeof this . storage === "object" && typeof this . storage . removeItem === "function" ) {
5002- this . storage . removeItem ( key ) ;
5003- return ;
5004- }
5005-
5006- // developer set values takes priority
5007- if ( useLocalStorage === undefined ) {
5008- useLocalStorage = this . #lsSupport;
5009- }
5010-
5011- if ( useLocalStorage ) { // Native support
5012- localStorage . removeItem ( key ) ;
5013- }
5014- else if ( this . storage !== "localstorage" ) { // Use cookie
5015- this . #createCookie( key , "" , - 1 ) ;
5030+ try {
5031+ // use dev provided storage if available
5032+ if ( typeof this . storage === "object" && typeof this . storage . removeItem === "function" ) {
5033+ this . storage . removeItem ( key ) ;
5034+ return ;
5035+ }
5036+
5037+ // developer set values takes priority
5038+ if ( useLocalStorage === undefined ) {
5039+ useLocalStorage = this . #lsSupport;
5040+ }
5041+
5042+ if ( useLocalStorage ) { // Native support
5043+ localStorage . removeItem ( key ) ;
5044+ }
5045+ else if ( this . storage !== "localstorage" ) { // Use cookie
5046+ this . #createCookie( key , "" , - 1 ) ;
5047+ }
5048+ } catch ( error ) {
5049+ // silent fail
50165050 }
50175051 }
50185052
0 commit comments