Skip to content

Commit

Permalink
fix: Prototype js fix (#313)
Browse files Browse the repository at this point in the history
* Add @amplitude/utils

* Add prototypeJsFix
  • Loading branch information
jooohhn authored Nov 5, 2020
1 parent 84e1a57 commit 7e463ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react-native": "amplitude.native.js",
"dependencies": {
"@amplitude/ua-parser-js": "0.7.24",
"@amplitude/utils": "^1.0.5",
"blueimp-md5": "^2.10.0",
"query-string": "5"
},
Expand Down
6 changes: 6 additions & 0 deletions src/amplitude-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Core of SDK code
import { isBrowserEnv, prototypeJsFix } from '@amplitude/utils';
import Constants from './constants';
import cookieStorage from './cookiestorage';
import MetadataStorage from '../src/metadata-storage';
Expand Down Expand Up @@ -82,6 +83,11 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o

try {
_parseConfig(this.options, opt_config);

if (isBrowserEnv() && window.Prototype !== undefined && Array.prototype.toJSON) {
prototypeJsFix();
utils.log.warn('Prototype.js injected Array.prototype.toJSON. Deleting Array.prototype.toJSON to prevent double-stringify');
}

if (this.options.cookieName !== DEFAULT_OPTIONS.cookieName) {
utils.log.warn('The cookieName option is deprecated. We will be ignoring it for newer cookies');
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
# yarn lockfile v1


"@amplitude/types@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@amplitude/types/-/types-1.0.4.tgz#21275b030c8267f9ea133a79c5c525e30c706d69"
integrity sha512-iWdgTXiE0T/QCK88g2ezJEhJpYHDvDs0StVVPu1ygcl6qYzk/8xrNvbeEibiIBT8t/GJ8FtH5ZIPx3c4CMjlig==

"@amplitude/ua-parser-js@0.7.24":
version "0.7.24"
resolved "https://registry.yarnpkg.com/@amplitude/ua-parser-js/-/ua-parser-js-0.7.24.tgz#2ce605af7d2c38d4a01313fb2385df55fbbd69aa"
integrity sha512-VbQuJymJ20WEw0HtI2np7EdC3NJGUWi8+Xdbc7uk8WfMIF308T0howpzkQ3JFMN7ejnrcSM/OyNGveeE3TP3TA==

"@amplitude/utils@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@amplitude/utils/-/utils-1.0.5.tgz#843d96b7965c69213bb1896980bed2c1569fbbed"
integrity sha512-leo4meeTAvp4W+UWk7EcWaJKuuJ3HqbNglRJPVAUYXaoCs2UzCnCVvjj5rUBN+Mhe0pAmkpEHHaS/1iv2prcKA==
dependencies:
"@amplitude/types" "^1.0.4"

"@babel/code-frame@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0.tgz#06e2ab19bdb535385559aabb5ba59729482800f8"
Expand Down

0 comments on commit 7e463ab

Please sign in to comment.