I am building an angular web application and I am wanting to send any javascript exceptions and callstacks from the client to the server for logging. In chrome and firefox I am able to get the callstack by looking at the exception.stack property, but this value is not available when using IE. Here is a code example from my angular controller:
function LogTestController($scope) {
$scope.TestError = function () {
callError1();
}
function callError1() {
callError2();
}
function callError2() {
var x = y;
}
};
And here is the exception.stack from chrome:
"ReferenceError: y is not defined
at callError2 (http://localhost:85/App/Offer/OfferController.js:16:17)
at callError1 (http://localhost:85/App/Offer/OfferController.js:12:9)
at Scope.LogTestController.$scope.TestError (http://localhost:85/App/Offer/OfferController.js:8:9)
at $parseFunctionCall (http://localhost:85/Scripts/angular.js:12345:18)
at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:85/Scripts/angular.js:21435:17)
at Scope.$get.Scope.$eval (http://localhost:85/Scripts/angular.js:14401:28)
at Scope.$get.Scope.$apply (http://localhost:85/Scripts/angular.js:14500:23)
at HTMLButtonElement.<anonymous> (http://localhost:85/Scripts/angular.js:21440:23)
at HTMLButtonElement.jQuery.event.dispatch (http://localhost:85/Scripts/jquery-1.9.1.js:3074:9)
at HTMLButtonElement.jQuery.event.add.elemData.handle (http://localhost:85/Scripts/jquery-1.9.1.js:2750:46)"
Which is very helpful in debugging. But IE does not have the extension.stack property when the error occurs inside of the angular controller.
However if I force the same error in IE when it is not inside an angular controller then there is a value for exception.stack. Here is an example of that code:
<script type="text/javascript">
try {
first();
} catch (exception) {
var trace = exception.stack;
};
function first() {
second();
};
function second() {
var x = y;
}
</script>
In IE the exception.trace is as follows:
"ReferenceError: 'y' is undefined
at second (http://localhost:85/App/logtest.html:20:13)
at first (http://localhost:85/App/logtest.html:16:13)
at Global code (http://localhost:85/App/logtest.html:10:13)"
I have also tried to use stacktrace.js to get the callstack from IE, but this library is reliant on the exception.stack value to be present.
Could somebody please help me understand why this is acting differently when inside an angular controller and how to get the stack trace from IE inside the angular controller?
Thanks
Related
I created a function which return the new Browser object from the JS function browser.forkNewDriverInstance() and i created a global variable in my config file and i'm calling a function from that file by using this global variable. but here when i'm calling that function it is throwing error like utility.openNewBrowser is not a function error.
Config File:
onPrepare: function () {
global.utility=require("../src/test/resources/com.learnFramework.utility/timeOutConfig.js");
}
Cucumber Opts functions
cucumberOpts: {
//i'm using the same file for setting up the timeout.. is this creating the issue??
require:['../src/test/resources/com.learnFramework.utility/timeOutConfig.js'],
tags: false,
profile: false,
format:'json:../Reports/jsonResult/results.json',
'no-source': true
}
Function
var configure = function () {
this.setDefaultTimeout(100 * 1000);
this.openNewBrowser=function(){
return browser.forkNewDriverInstance(true);
}
};
module.exports = configure;
Error Log
TypeError: utility.openNewBrowser is not a function
When i called the forkNewBrowserInstance method directly i'm getting the below error.
both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details
can some help me to resolve this issue.. i got this error because the first browser ignoring synchronization but second browser how can i ignore the synchronization?
What you did above is the correct way of defining a global variable. But I think the global variable name should be configure instead of utility that is why it is throwing the TypeError.
And wherever you want to call it, use that variable name as is. This is actually how protractor, browser and other built-in global variables were made available globally. The following posting was helpful and also the protractor doc where it's explaining the property: params?: any;
Hope this helps, please let me know.
I faced the same issue but with jasmine.
so i had done the following workaround and issue was resolved.
class abc{
constructor() {
var configure = function () {
this.setDefaultTimeout(100 * 1000);
this.openNewBrowser=function(){
return browser.forkNewDriverInstance(true);
}
};
}
}
module.exports = new abc();
I've a javascript function that has to create graph:
<script>
window.setGraph = (lab, ser) => {
console.log(document.getElementById("weather-chart"));
console.log(lab);
console.log(ser);
var chart = new Chartist.Line('#weather-chart', {
labels: lab,
series: ser
});
console.log("done");
return true;
}
</script>
This function is called by one of my blazor component:
protected override async Task OnInitAsync()
{
some-data-a = await RetrieveSomeData();
some-data-b = await RetrieveSomeOtherData();
JSRuntime.Current.InvokeAsync<bool>("setGraph", some-data-a, some-data-b);
}
Everything is executed, my console.log are called. But it appears that at this moment my element #weather-chart cannot be found, because I get this:
chartist.min.js:8 Uncaught TypeError: Cannot read property 'querySelectorAll' of null
at Object.c.createSvg (chartist.min.js:8)
at f.d [as createChart] (chartist.min.js:8)
at f.h (chartist.min.js:8)
AND
my console.log(document....) is returning null.
If I go to this page, I've the error, and if just after getting this error I do something like window.setGraph([1,2,3], [[1,2,3]]) in my chrome developer tools, everything is initialized correctly.
So what did I do wrong? Why chartist doesn't seems to be able to find the element?
It appears that blazor's databinding was taking some time to display the html. So basically after I set the _items, it was changing the template, but not fast enough for the line after this(not sure why, since there was an await).
I've got a script which runs on page load and does the following.
===== start of js file======
var curFldCtrl = Xrm.Page.getControl("transactioncurrencyid");
function ResetFieldLayout() {
curFldCtrl.setVisible(false);
}
function OnLoad() {
ResetFieldLayout();
}
===========end js file==============
Funny thing is that this code works find in Chrome and IE11, but when I run it in Microsoft Edge, it throws an error.
There was an error with this field's customized event.
Field:window
Event:onload
Error:Unable to get property 'setVisible' of undefined or null reference.
Anyone come across this before or know why this is happening?
Thanks in advance.
Try placing the variable declaration inside your function.
function ResetFieldLayout() {
var curFldCtrl = Xrm.Page.getControl("transactioncurrencyid");
curFldCtrl.setVisible(false);
}
function OnLoad() {
ResetFieldLayout();
}
I've got a problem in AngularJS where $scope.$watchCollection() throws an error. I've reduced my code to the point where it's exactly the same as example code in the docs (http://docs.angularjs.org/api/ng.$rootScope.Scope#$watchCollection), and the error is still thrown:
function OverviewCtrl($scope) {
$scope.names = ['igor', 'matias', 'misko', 'james'];
$scope.dataCount = 4;
$scope.$watchCollection('names', function(newNames, oldNames) {
$scope.dataCount = newNames.length;
});
}
I get the error
'undefined' is not a function (evaluating '$scope.$watchCollection('names', function(newNames, oldNames) {
$scope.dataCount = newNames.length;
})')
I have no idea what the problem could possibly be. I'm doing exactly what the docs say, except I'm putting it in a controller, but it seems this code is intended for use in controllers. So what's the problem here?
You could also use the following syntax :
$scope.$watch('myCollection', function(value, oldValue) {
// insert awesome code here
}, true);
The true parameter tells AngularJS to "deepwatch" the value.
I am chasing down a bug in a FireFox extension. I've finally managed to see it for myself (I've only had reports before) and I can't understand how what I saw is possible.
One error message from my extension in the Error Console is "gBrowser is not defined". This by itself would be surprising enough, since the overlay is over browser.xul and navigator.xul, and I expect gBrowser to be available from both. Even worse is the actual place where it happens: line 101 of nextplease.js. That is, inside the function isTopLevelDocument, which is only called from onContentLoaded, which is only called from onLoad here:
gBrowser.addEventListener(this.loadType, function (event) {
nextplease.loadListener.onContentLoaded(event);
},
true);
So gBrowser is defined in onLoad, but somehow undefined in isTopLevelDocument.
When I tried to actually use the extension, I got another error: "nextplease is not defined". The interesting thing is that it happened on lines 853 and 857. That is, inside the functions
nextplease.getNextLink = function () {
nextplease.getLink(window.content, nextplease.NextPhrasesMap, nextplease.NextImagesMap, nextplease.isNextRegExp, nextplease.NEXT_SEARCH_TYPE);
}
nextplease.getPrevLink = function () {
nextplease.getLink(window.content, nextplease.PrevPhrasesMap, nextplease.PrevImagesMap, nextplease.isPrevRegExp, nextplease.PREV_SEARCH_TYPE);
}
So nextplease is somehow defined enough to call these functions, but isn't defined inside them.
Finally, executing typeof(nextplease) in Execute JS returns "object". Same for gBrowser.
How can this happen? Any ideas?
For the second case:
nextplease.getNextLink = function () {
nextplease.getLink(window.content, nextplease.NextPhrasesMap, nextplease.NextImagesMap, nextplease.isNextRegExp, nextplease.NEXT_SEARCH_TYPE);
}
nextplease.getPrevLink = function () {
nextplease.getLink(window.content, nextplease.PrevPhrasesMap, nextplease.PrevImagesMap, nextplease.isPrevRegExp, nextplease.PREV_SEARCH_TYPE);
}
I'd try this instead:
nextplease.getNextLink = function () {
this.getLink(window.content, this.NextPhrasesMap, this.NextImagesMap, this.isNextRegExp, this.NEXT_SEARCH_TYPE);
}
nextplease.getPrevLink = function () {
this.getLink(window.content, this.PrevPhrasesMap, this.PrevImagesMap, this.isPrevRegExp, this.PREV_SEARCH_TYPE);
}
I'm not sure what's happening (in which context the code is running and therefore why it's not seeing the gbrowser and other global variables) but an easy workaround for gbrowser being undefined would be to get a reference to the main window and access it from there:
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
mainWindow.gbrowser.addEventListener( ... )
This should work independently of the context where the code is running since you would not rely on global variables.