Skip to content

Commit 7e463ab

Browse files
authored
fix: Prototype js fix (#313)
* Add @amplitude/utils * Add prototypeJsFix
1 parent 84e1a57 commit 7e463ab

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"react-native": "amplitude.native.js",
1717
"dependencies": {
1818
"@amplitude/ua-parser-js": "0.7.24",
19+
"@amplitude/utils": "^1.0.5",
1920
"blueimp-md5": "^2.10.0",
2021
"query-string": "5"
2122
},

src/amplitude-client.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Core of SDK code
2+
import { isBrowserEnv, prototypeJsFix } from '@amplitude/utils';
23
import Constants from './constants';
34
import cookieStorage from './cookiestorage';
45
import MetadataStorage from '../src/metadata-storage';
@@ -82,6 +83,11 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
8283

8384
try {
8485
_parseConfig(this.options, opt_config);
86+
87+
if (isBrowserEnv() && window.Prototype !== undefined && Array.prototype.toJSON) {
88+
prototypeJsFix();
89+
utils.log.warn('Prototype.js injected Array.prototype.toJSON. Deleting Array.prototype.toJSON to prevent double-stringify');
90+
}
8591

8692
if (this.options.cookieName !== DEFAULT_OPTIONS.cookieName) {
8793
utils.log.warn('The cookieName option is deprecated. We will be ignoring it for newer cookies');

yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
# yarn lockfile v1
33

44

5+
"@amplitude/types@^1.0.4":
6+
version "1.0.4"
7+
resolved "https://registry.yarnpkg.com/@amplitude/types/-/types-1.0.4.tgz#21275b030c8267f9ea133a79c5c525e30c706d69"
8+
integrity sha512-iWdgTXiE0T/QCK88g2ezJEhJpYHDvDs0StVVPu1ygcl6qYzk/8xrNvbeEibiIBT8t/GJ8FtH5ZIPx3c4CMjlig==
9+
510
"@amplitude/[email protected]":
611
version "0.7.24"
712
resolved "https://registry.yarnpkg.com/@amplitude/ua-parser-js/-/ua-parser-js-0.7.24.tgz#2ce605af7d2c38d4a01313fb2385df55fbbd69aa"
813
integrity sha512-VbQuJymJ20WEw0HtI2np7EdC3NJGUWi8+Xdbc7uk8WfMIF308T0howpzkQ3JFMN7ejnrcSM/OyNGveeE3TP3TA==
914

15+
"@amplitude/utils@^1.0.5":
16+
version "1.0.5"
17+
resolved "https://registry.yarnpkg.com/@amplitude/utils/-/utils-1.0.5.tgz#843d96b7965c69213bb1896980bed2c1569fbbed"
18+
integrity sha512-leo4meeTAvp4W+UWk7EcWaJKuuJ3HqbNglRJPVAUYXaoCs2UzCnCVvjj5rUBN+Mhe0pAmkpEHHaS/1iv2prcKA==
19+
dependencies:
20+
"@amplitude/types" "^1.0.4"
21+
1022
"@babel/code-frame@^7.0.0":
1123
version "7.0.0"
1224
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"

0 commit comments

Comments
 (0)