I want to use axios with Android build of CocosCreator

483 views Asked by At

I could use axios in the browser with Cocos Creator.
But in android build I got an error.
ERROR: Uncaught TypeError: Cannot read property 'charAt' of undefined, location: assets/main/index.c8cc9.js:0:0

Made this change.

pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
urlParsingNode.pathname :
'/' + urlParsingNode.pathname

pathname:urlParsingNode.pathname

However, no response is returned.
Only Mock returns a response.

Need to change axios source code?

1

There are 1 answers

1
tao zhang On BEST ANSWER

you can try add this code block

if (cc.sys.isNative 
    && typeof navigator !== 'undefined' 
    && typeof navigator.product !== 'undefined') {
    Object.defineProperty(navigator, "product", {value: "NativeScript"});
}