Uncaught TypeError: undefined is not a function Android Browser - android-browser

I am getting a strange error on Android Browser that it constantly says
Uncaught TypeError: undefined is not a function
On a function that is working perfectly on all other browsers even Safari. The website loads everything perfectly on all the browsers, on computer as well as mobiles but when it is viewed on Android browser it throws off that error. I have checked it over all and jquery is included only once. I can post the code here but I dont think it would be of much help because at the start it was giving above mentioned error on a function which i tried to resolve. After that it started giving the same error on another function and it is carrying on like this.
Here is a reference
$.ajax({
type: "POST",
url: XXXXXXXXXXX,
data: dataObj,
cache: false,
success: function (resp) {
if (resp.startsWith("Error:")) {
console.log(resp)
}
else
{
clusters.clearLayers();
// common.clearLayers();
var result = JSON.parse(resp)
console.log(result.user);
if (result.user == 'free')
{
makeFreePokemon(result[0]['hits']['hits'])
}
else
{
makePokemon(result[0]['hits']['hits'])
}
// if (result[0]['hits']['total'] > 1000) {
// window.setTimeout(search(),500)
// }
}
}
})
In the above code it gives the undefined error ON
if (resp.startsWith("Error:")) {
When I solve this, it starts giving the same error another location.
Anyhelp would be really great.
Thanks

Related

I am having problem with webRTC video call, with nodejs

So i am using webRTC for video call application, it works fine locally, but while I host my react app and node backend in Ip. Chat works fine, but there is an error in the following function
const constraints = { audio: true, video: audioOnly ? false : true };
console.log(navigator)
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
console.log(stream)
store.dispatch(setLocalStream(stream) as any);
if (callback) {
callback();
}
}).catch((err) => {
console.log(err);
console.log("Error getting local stream");
})
There is an error that shows:
Uncaught TypeError: Cannot read properties of undefined (reading 'getUserMedia')
at getLocalStreamPreview
Can anyone help me how can I solve this issue ?
getUserMedia is a part of the Browser API. It will not be available if you have some kind of SSR/server-processing enabled. Just make sure the component is mounted already before you call getUserMedia and it should work fine.

Discord.js, JSDOM Invalid URL

So I'm trying to get the HTML of a website. I use 'JSDOM' to "Load" the website due to a majority of the site being created using scripts. My code is as follows:
(async () => {
try {
const dom = new JSDOM(``, {
url: "https://www.google.com/",
referrer: "",
contentType: "text/html",
includeNodeLocations: true,
storageQuota: 10000000,
runScripts: "dangerously",
resources: "usable",
pretendToBeVisual: true
});
} catch(error) {
console.log(error)
}
})();
When I run the command I get the error
TypeError: Invalid URL:
at new URLImpl (C:\Users\jonco\Desktop\Nakada Manami\node_modules\whatwg-url\lib\URL-impl.js:21:13)
at Object.setup (C:\Users\jonco\Desktop\Nakada Manami\node_modules\whatwg-url\lib\URL.js:73:14)
at new URL (C:\Users\jonco\Desktop\Nakada Manami\node_modules\whatwg-url\lib\URL.js:105:22)
at transformOptions (C:\Users\jonco\Desktop\Nakada Manami\node_modules\jsdom\lib\api.js:239:43)
at new JSDOM (C:\Users\jonco\Desktop\Nakada Manami\node_modules\jsdom\lib\api.js:34:15)
at C:\Users\jonco\Desktop\Nakada Manami\index.js:109:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
What am I doing wrong? I've spend the last 3 hours trying to figure this out.
The referer has to be undefined or a valid URL.
As we see that in the source.

AngularJS Nondescript Error at "return logFn.apply(console, args);"

I'm using AngularJS v1.5.0. I'm on Chrome Version 55.0.2883.95. The error I'm seeing shows similar failure behavior to this SO post, although the error description for my situation just states Object.
I've created a plunker to demonstrate the error. Open the developer console at the plunker to see the resulting error.
Given the following service,
this.test = function() {
return $q(function(resolve, reject) {
var errorObject = {
httpStatusCode: 503,
error: {
code: 5030,
message: 'Oh no! Something went wrong, please try again'
}
};
reject(errorObject);
}).then(function successCallback(response) {
return response;
}).catch(function errorCallback(response) {
throw response;
});
};
AngularJS code generates the following error:
angular.js:13550 Object {httpStatusCode: 503, error: Object}
The AngularJS code in play is:
function consoleLog(type) {
var console = $window.console || {},
logFn = console[type] || console.log || noop,
hasApply = false;
// Note: reading logFn.apply throws an error in IE11 in IE8 document mode.
// The reason behind this is that console.log has type "object" in IE8...
try {
hasApply = !!logFn.apply;
} catch (e) {}
if (hasApply) {
return function() {
var args = [];
forEach(arguments, function(arg) {
args.push(formatError(arg));
});
return logFn.apply(console, args); // Error thrown on this line
};
}
// we are IE which either doesn't have window.console => this is noop and we do nothing,
// or we are IE where console.log doesn't have apply so we log at least first 2 args
return function(arg1, arg2) {
logFn(arg1, arg2 == null ? '' : arg2);
};
Here's how I call the service:
var test = function() {
userService.test()
.then(function successCallback(responseObject) {
console.log('Beginning of then');
})
.catch(function errorCallback(errorResponseObject) {
console.log('Beginning of catch');
});
}
The error seems to be caused by the fact that I am handling the promise rejection, and then re-throwing it. If I don't catch and rethrow, I don't get the error. Why do I receive the error when catching and re-throwing?
Update: It appears that using the $q service to reject the caught promise rejection avoids the AngularJS error I was seeing. I'll use that approach for now, but would still be interested to know why throwing out of the promise catch generates the error.
Example code without the error:
this.test = function() {
return $q(function(resolve, reject) {
var errorObject = {
httpStatusCode: 503,
error: {
code: 5030,
message: 'Oh no! Something went wrong, please try again'
}
};
reject(errorObject);
}).then(function successCallback(response) {
return response;
}).catch(function errorCallback(response) {
return $q.reject(response);
});
};
This question has nothing to do with AngularJS and much more on how promises work (including AngularJS's $q).
Throwing in a .catch is bound to have issues. Axel has an excellent explanation
if you want a quick and dirty method to get an exception to the console(or other logging mechanisms) you can use this trick:
.catch((err) => setTimeout(() => throw err));
Or its es5 variant:
.catch(function (err) { setTimeout(function () {throw err},0)})
This will keep the error as is, and get it out of the promise chain, without changing it.
However, I think it's better to incorporate the way that Axel explains in his article.
I've found what I believe to be the answer to my question. Buried in this discussion on the AngularJS Github issues section, #gkalpak notes the following:
The only difference between them is that return $q.reject(anything) will just pass anything down the chain, while throw anything will additionally pass anything to the $exceptionHandler. Other than that, both methods work the same.
So, the issue as far as I understand it, is that the $exceptionHandler prints the exception to the console. Using $q.reject as I stated in my update and again below does avoid this behavior and is my recommended solution to avoiding the console error.
this.test = function() {
return $q(function(resolve, reject) {
var errorObject = {
httpStatusCode: 503,
error: {
code: 5030,
message: 'Oh no! Something went wrong, please try again'
}
};
reject(errorObject);
}).then(function successCallback(response) {
return response;
}).catch(function errorCallback(response) {
return $q.reject(response);
});
};
Update - Based on #Sanders-Eias answer below, it is bad practice to throw exceptions out of async functions in general. That statement further bolsters the $q.reject approach.

Angular test using $httpBackend fails with "400 thrown" error

For hours I've been trying to test my NewPostController with $httpBackend. The problem is whenever I set non-2xx status code in the response, the test fails.
NewPostController has the following method:
$scope.submit = function () {
var newPost = $scope.newPost;
PostService.insertPost(newPost).then(function (post) {
$location.path("/my-posts");
}, function (status) {
$scope.form.$setPristine();
$scope.error = status;
});
};
I have a problem testing the failure path:
it(...) {
...
$scope.post.text = "";
$httpBackend.expectPOST("/create-post", {"post":$scope.post}).respond(400);
$scope.submit();
$httpBackend.flush();
expect($scope.error).toBeDefined();
$scope.post.text = "This is a valid text.";
$httpBackend.expectPOST("/create-post", {"post": $scope.post}).respond(200);
$scope.submit();
$httpBackend.flush();
expect($location.path()).toBe("/my-posts");
});
The test fails with a message "400 thrown" (no callstack). I tried to change the order of subtests, use whenPOST instead of expectPOST and combine the methods as they do in Angular docs (https://docs.angularjs.org/api/ngMock/service/$httpBackend) but without success.
Please help.
EDIT:
Now when I look at PostService, it makes sense where the "400 thrown" comes from but I expected the error to be handled by angular. I threw it because of the section "Handling problems in nested service calls" of this article. It is supposed to be a shorter version of deferred.resolve/reject mechanism.
this.insertPost = function (newPost) {
return $http({
method: "post",
url: "/create-post",
data: {
post: newPost
}
}).then(function (res) {
return (res.data);
}, function (res) {
throw res.status;
});
};
This is indeed strange, and is perhaps something the angular team didn't consider.
When a promise is rejected by throwing (as you're doing), the angular $exceptionHandler service is called with the thrown exception. By default, this service just logs the exception in the browser console.
But when using ngMocks, this service is replaced by a mock implementation that can either log or rethrow the exception. The default mode is to rethrow, in order to make a test fail when an exception is thrown.
My advice would be to avoid using throw to simply reject a promise, and thus replace
function (res) {
throw res.status;
}
by
function (res) {
return $q.reject(res.status);
}
But if you really want to keep using throw, you can also configure the mock exceptionHandler to log instead of rethrowing:
beforeEach(module(function($exceptionHandlerProvider) {
$exceptionHandlerProvider.mode('log');
}));

Callback failing even though the statuscode is 200

I have an odata, breeze, angular application.
Please see here: http://bepozreports.azurewebsites.net/#/dashboard
You will notice an alert that I have setup which just says the callback has failed.
If you navigate to app/js/controllers.js you will see this code
accountFactory.getAll()
.then(successCallback)
.catch(failCallback);
The failCallback always is called even though the call to http://bepozreports.azurewebsites.net/odata/Accounts?$orderby=FirstName results in a correct response??
Any ideas?
If you debug your app and look at line 15199 of breeze.debug.js, you will find the following code:
OData.read({
requestUri: url,
headers: { "DataServiceVersion": "2.0" }
},
function (data, response) {
var inlineCount;
if (data.__count) {
// OData can return data.__count as a string
inlineCount = parseInt(data.__count, 10);
}
return deferred.resolve({ results: data.results, inlineCount: inlineCount });
},
function (error) {
return deferred.reject(createError(error, url));
});
The error callback is triggered here with your url, and the error response is message: "no handler for data"
A failure at good error reporting by breeze.
After doing a little bit of digging (I'm not familiar with datajs), it looks like the problem might have something to do with your CORS setup (or lack thereof). Hope that helps.

Resources