Skip to content

Commit 387159d

Browse files
authored
Merge pull request #34 from Countly/new-year-branch
25.1.0 changes
2 parents b813211 + baf5505 commit 387159d

File tree

6 files changed

+106
-63
lines changed

6 files changed

+106
-63
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 25.1.0
2+
3+
* Mitigated an issue where content resizing did not work in certain orientations.
4+
* Reduced log verbosity.
5+
* Improved orientation reporting precision.
6+
* Added a new init time config option for filtering crashes:
7+
* `crash_filter_callback`
8+
19
## 24.11.4
210

311
* Mitigated an issue where `content` and `feedback` interfaces would not work with async multi instances.

Countly.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ function initAfterLoadingAPM(conf) {
9292
* @return {string} serialized value
9393
* */
9494
Countly.serialize = function (value) {
95-
// Convert object values to JSON
96-
if (typeof value === "object") {
97-
value = JSON.stringify(value);
95+
try {
96+
// Convert object values to JSON
97+
if (typeof value === "object") {
98+
value = JSON.stringify(value);
99+
}
100+
} catch (error) {
101+
// silent fail
98102
}
99103
return value;
100104
};
@@ -113,10 +117,7 @@ Countly.deserialize = function (data) {
113117
data = JSON.parse(data);
114118
}
115119
catch (e) {
116-
if (checkIfLoggingIsOn()) {
117-
// eslint-disable-next-line no-console
118-
console.warn("[WARNING] [Countly] deserialize, Could not parse the file:[" + data + "], error: " + e);
119-
}
120+
// silent fail
120121
}
121122

122123
return data;

modules/Constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var healthCheckCounterEnum = Object.freeze({
104104
errorMessage: "cly_hc_error_message",
105105
});
106106

107-
var SDK_VERSION = "24.11.4";
107+
var SDK_VERSION = "25.1.0";
108108
var SDK_NAME = "javascript_native_web";
109109

110110
// Using this on document.referrer would return an array with 17 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)

modules/CountlyClass.js

Lines changed: 86 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "countly-sdk-js",
3-
"version": "24.11.4",
3+
"version": "25.1.0",
44
"description": "Countly JavaScript SDK",
55
"type": "module",
66
"main": "Countly.js",

0 commit comments

Comments
 (0)