Issues with GridView on IE but not on Firefox - javascript

IE takes forever to load my GridView where as Firefox is almost instant (big surprise I know; but you know users and how they love IE).
We have a GridView which when the user scrolls to the bottom loads more entries into the list (basically lazy loading, instead of loading the whole list, it loads 20 entries and when you scroll to the bottom it loads the next 20). However like I said there is a huge difference in how this performs on IE vs FF. When debugging on IE I consistently get Javascript timeout errors.
during this code block:
function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {
if (this._request === executor.get_webRequest()) {
this._processingRequest = false;
this._additionalInput = null;
this._request = null;
}
var handler = this._get_eventHandlerList().getHandler("endRequest");
var errorHandled = false;
if (handler) {
var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
handler(this, eventArgs);
errorHandled = eventArgs.get_errorHandled();
}
if (error && !errorHandled) {
throw error;
}
}
This error AFAIK is the reason we implemented lazy loading (to get rid of the timeouts). However it seems to not be helping, merely duplicating the issue every time is runs. NOTE: prior to our last release it would load all the data as opposed to Lazy Loading.
Also when debugging it seems to cycle on this piece of code when it is "loading" on IE:
Protected Overrides ReadOnly Property ControlSkins() As System.Collections.IDictionary
Get
Return Me.__controlSkins
End Get
End Property
I believe due to fact that FF displays the data without the timeout that whatever is causing this is specific to IE and maybe common to other implementation of a GridView population.
I should note however that Im not positive that FF communicates with VS like IE does. Meaning that the warnings I get (the screenshot above) might happen on FF and VS doesnt show them to me but like I said FF has no problems with our page.
Followup [similar error q/a]:
After further testing the ControlSkins() method that is getting called repeatedly (posted above) here is its value. It alternates between that HybridDictionary and Nothing
I have to continue testing but I think/hope (fingers are crossed) that adding AsyncPostBackTimeout="300" on my ScriptManager (for that widget) has stopped the timeout error. Of course this doesn't help with the large load times on IE.

Related

loading from the storage works in the console, but not on page load

EDIT: the issue has been resolved. Apparently, the page didn't load fast enough for the id referenced to to be in place. Adding a event listener as follows solved the issue:
window.addEventListener('load', function() {stuff that's supposed to happen})
on my clueless journey to creating a little game I'm currently battling saving to and loading from the user's local storage. While saving appears to be working, loading doesn't, unless I manually put the respective commands into the console.
Here's the code snippet that's acting up:
//definition of variables
var dayLength = 10;
//if function to check if there's stored data, loading it and changing the document accordingly
if ( localStorage.saveExists === "true" ) {
dayLength = Number(localStorage.dayLength);
document.getElementById("displayDayLength").innerHTML = dayLength.toFixed(3);
}
var loadingAttempted = "true";
//function to save which occurs every 15 seconds (or through a button click)
function saveAuto() {
if ( loadingAttempted === "true" ) {
var saveExists = "false";
localStorage.saveExists = "true";
localStorage.dayLength = dayLength;
}
When no data are in the local storage (in other words, if saveExists = "false") the site won't attempt to load something and works as intended. The moment there is data in the local storage, the file attempts to load it (so thus far it works).
However, I'll get an error in the line supposed to change the document according to the loaded data, claiming that dayLength is "null".
If I then manually input localStorage.dayLength into the console, it returns "10", as it should. I know that storing the data into the local storage works, because otherwise the if function for loading wouldn't know (saveExists === "true") and thus not do anything. For whatever reason though, it fails to load any other data correctly and returns "null", unless I manually put the exact same code into the console.
Best part is, that I got the whole idea from another little game that does the exact same thing and there it works flawlessly.
I'm at a total loss as to why it works at the other project, but not with mine.
Educate me, if you will. And thank you in advance.
PS: I tried to use localStorage.setItem and localStorage.getItem also, but the issue remained.

JavaScript Executor Click does not work properly on Internet explorer unless the IE 11 is resetted and Restored and the computer is restarted

When not functioning properly - it will execute the javascript click and i see the button being clicked. But the line that i am printing in next line of my code using System.print will not print anything. It looks like it is getting somewhere lost after clicking the button and not coming out of the javascript click method.
But the interesting part is that - if i reset the IE and restart my computer - it starts to work and prints the next line and everything gets executed.
This issue started happening recently like a week ago and i tried to revert the updates - security ones from microsoft but no luck.
I also tried using different versions of IE driver starting from the latest one upto the 8 previous versions.
This issue starts arising very randomly. It happened like 4 times in a week and i have to reset the browser and restart my pc in order to get my tests execute.
Here is my code;
public void enteringValuesForAKMWithExistingTieNumber(AKMSimulatorTO akmto, String storedTieNumber)
{
customerName.sendKeys(akmto.getCustomerName());
customerTie.sendKeys(storedTieNumber);
List<WebElement> ls = getDriver().findElements(By.cssSelector("input"));
accountNumber.sendKeys(akmto.getAccountNumber());
javascriptExecutorClick(ls.get(3));
System.out.println("Button is clicked");
}
protected void javascriptExecutorClick(WebElement element) {
JavascriptExecutor js = (JavascriptExecutor) (getDriver());
js.executeScript("arguments[0].click();", element);
}

SWFObject event undefined in Chrome works in IE

I want to get the currentFrame of my Flash movie when it is loaded. I followed the the tutorial found here http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/index.html and SWFOBJECT CurrentFrame Javascript. I am using SWFObject 2.3 beta. This works perfectly fine on Internet Explorer however it does not work on Google Chrome.
In Chrome I get the error
Uncaught TypeError: e.ref.currentFrame is not a function
Checking e it returns [object Object]
Checking e.ref returns [object HTMLObjectElement]
Checking e.ref.totalFrames returns undefined
var flashvars = {};
var params = {};
var attributes = {};
function mycall(e){
setInterval(function(){console.log("Frame: " + e.ref.currentFrame)},1000);
}
swfobject.embedSWF("notmyswf.swf", "course", "100%", "100%", "6.0.0", false, flashvars, params, attributes, mycall);
Why is this not working on Chrome but works well with IE? Is the event e not detected? Is there a work-around on how to make this work on Chrome?
The purpose of this is for me to create a check if the user is really using the course he has opened and not just leaving it idle. I have already added a code that will check idle but it is not enough. Most learners, have figured out a way to just open a course, leave it there to accumulate hours of training. Some even have a program running in their computers that will just move the mouse 1-pixel every few seconds so that the computer does not go to idle. If I can check the current frame of the Flash movie, I can create a function that will calculate the current page the user is viewing every 15 minutes. If he is stuck in the same page I can then show a prompt that the user must click in order to continue viewing the course or it will automatically close.
I suggest dropping the SWF-based currentFrame approach in favor of monitoring your calls to the database using JavaScript. (Based on your comments, it sounds like the DB calls are being sent by JS, so this shouldn't be a problem.)
If the course bookmark is auto-saved every 3 minutes (as described in your comments), you can cache the value in your page's JS and do a compare every time the save is performed. If the value hasn't changed in x number of minutes, you can display your timeout warning.
If you're using a SCORM wrapper (or similar), this is really simple, just modify the wrapper to include your timer code. Something like:
//Old code (pseudocode, not tested)
function setBoomark (val){
API.SetValue("cmi.core.lesson_location", val);
}
//New code (pseudocode, not tested)
var current_location = "";
var activityTimer;
function disableCourse(){
//do stuff to disable course because it timed out
}
function setBoomark (val){
API.SetValue("cmi.core.lesson_location", val);
if(val === current_location){
//do nothing, timer keeps ticking
} else {
//reset timer using new bookmark value
if(activityTimer){ clearTimeout(activityTimer); }
activityTimer = setTimeout(disableCourse, 15000);
//Update current_location value
current_location = val;
}
}
This is a rough sketch but hopefully you get the idea.
I feel stupid!
It did not work in Chrome and Firefox because I used the wrong casing for the functions but in IE11 it works no matter the case.
So the correct functions are:
e.ref.CurrentFrame() //I used currentFrame() which still works in IE11
e.ref.TotalFrames() //I used totalFrames() which still works in IE11
e.ref.PercentLoaded() //I used this correctly and was able to get the value

In a Firefox restartless add-on, how do I run code when a new window opens (listen for window open)?

I am starting to build a restartless Firefox add-on and I am having trouble setting up the bootstrap.js. Everyone seems to agree that the core of a bootstrap.js is pretty much boilerplate code, along these lines:
const Cc = Components.classes;
const Ci = Components.interfaces;
function startup() {
let wm = Cc["#mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
// then can control what happens with domWindow.document
}
}
function shutdown() {}
function install() {}
function uninstall() {}
This code works and I can control things in the existing windows. For example, domWindow.alert("text") successfully creates a standard alert saying "text" on every window that is currently open.
However, I can't find any code that will allow me to do things in new windows; i.e. those created after the script runs. What is the correct way to handle the creation of new windows and gain control over them, to the point where I could get another "text" alert from one when it is created?
Edit: Using the nsWindowMediator class and the code sample from MDN, I now have this:
var windowListener = {
onOpenWindow: function (aWindow) {
try {
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
domWindow.addEventListener("load", function () {
domWindow.removeEventListener("load", arguments.callee, false);
//window has now loaded now do stuff to it
domWindow.alert("text");
}, false);
} catch (err) {
Services.prompt.alert(null, "Error", err);
}
},
onCloseWindow: function (aWindow) {},
onWindowTitleChange: function (aWindow, aTitle) {}
};
function startup(aData, aReason) {
// Load into any existing windows
try {
let wm = Cc["#mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
loadIntoWindow(domWindow);
}
} catch (err) {
Services.prompt.alert(null, "Error", err);
}
Services.wm.addListener(windowListener);
}
However, there is still no output from the onOpenWindow call - the "text" alert does not appear, nor does the error alert in the catch block. I can confirm that onOpenWindow is actually being entered; if I put a Services.prompt.alert() at the beginning of onOpenWindow, I get the alert when I create a new window. Unfortunately, I get an infinite loop of alerts and I have no idea why.
However, I can't find any code that will allow me to do things in new windows; i.e. those created after the script runs. What is the correct way to handle the creation of new windows and gain control over them, to the point where I could get another "text" alert from one when it is created?
The correct way to act on each window when it opens is to use addListener() from nsIWindowMediator. The example code below does this. The nsIWindowMediator is included in Services.jsm and is accessed through Services.wm.addListener(WindowListener). In order to use a window listener, you have to pass it an nsIWindowMediatorListener (ref2) object. An nsIWindowMediatorListener contains three keys: onOpenWindow, onCloseWindow, and onWindowTitleChange. Each should be defined as a function which will be called when the appropriate event occurs.
The MDN document How to convert an overlay extension to restartless in "Step 9: bootstrap.js" contains an example of a basic bootstrap.js which will run the code in the function loadIntoWindow(window) for each currently open browser window and any browser window which opens in the future. I have used code modified from this in a couple of different add-ons. The example is substantially similar to the code you are already using. The example is (slightly modified):
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/Services.jsm");
function startup(data,reason) {
// Load this add-ons module(s):
Components.utils.import("chrome://myAddon/content/myModule.jsm");
// Do whatever initial startup stuff is needed for this add-on.
// Code is in module just loaded.
myModule.startup();
// Make changes to the Firefox UI to hook in this add-on
forEachOpenWindow(loadIntoWindow);
// Listen for any windows that open in the future
Services.wm.addListener(WindowListener);
}
function shutdown(data,reason) {
if (reason == APP_SHUTDOWN)
return;
// Unload the UI from each window
forEachOpenWindow(unloadFromWindow);
// Stop listening for new windows to open.
Services.wm.removeListener(WindowListener);
// Do whatever shutdown stuff you need to do on add-on disable
myModule.shutdown();
// Unload the module(s) loaded specific to this extension.
// Use the same URL for your module(s) as when loaded:
Components.utils.unload("chrome://myAddon/content/myModule.jsm");
// HACK WARNING: The Addon Manager does not properly clear all add-on related caches
// on update. In order to fully update images and locales, their
// caches need clearing here.
Services.obs.notifyObservers(null, "chrome-flush-caches", null);
}
function install(data,reason) { }
function uninstall(data,reason) { }
function loadIntoWindow(window) {
/* call/move your UI construction function here */
}
function unloadFromWindow(window) {
/* call/move your UI tear down function here */
}
function forEachOpenWindow(todo) {
// Apply a function to all open browser windows
var windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements())
todo(windows.getNext().QueryInterface(Ci.nsIDOMWindow));
}
var WindowListener = {
onOpenWindow: function(xulWindow) {
var window = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
function onWindowLoad() {
window.removeEventListener("load",onWindowLoad);
// Only add UI changes if this is a browser window
if (window.document.documentElement.getAttribute("windowtype")
== "navigator:browser")
loadIntoWindow(window);
}
window.addEventListener("load",onWindowLoad);
},
onCloseWindow: function(xulWindow) { },
onWindowTitleChange: function(xulWindow, newTitle) { }
};
While there is quite a bit more that your might want to do in your bootstrap.js code, the above is organized reasonably well and keeps all of the code to load into the Firefox UI within loadIntoWindow(window) and unloading the UI within unloadFromWindow(window). However, it should be noted that some UI elements you should only be adding/removing once (e.g. australis widgets, like buttons) and other elements (e.g. direct changes to the Firefox DOM) have to be added once in each window.
Unfortunately, I get an infinite loop of alerts and I have no idea why.
One of the significant differences between this example and what you are currently using is the test for the type of window that has opened. This is done so that we are only acting on newly opened windows which are browser windows instead of all newly opened windows:
if (window.document.documentElement.getAttribute("windowtype") == "navigator:browser")
loadIntoWindow(window);
The problem you describe of getting an infinite loop of alert() popups is caused by not checking to make sure that you are only acting on browser windows. The alert() popup is a window. Thus, you are calling alert() for every alert() window you open which, of course, just opens another alert() window on which you call alert(). This is your infinite loop.
Additional references:
1. Working with windows in chrome code
However, I can't find any code that will allow me to do things in new windows
When working with XPCOM objects you generally want to study their interfaces, which are often found on MDN. In this case your starting point would be nsIWindowMediator, since that's the service you're using in line 5.
As you can see it has an addListener function, which takes a parameter implementing nsIWindowMediatorListener. There's a code-example right there on the page.
But let's assume for the moment there isn't a code example. You could search for the interface on MDN, but it isn't listed. The next step would be searching MXR for the .idl. idl = interface description language
Once you got the interface contract you can more or less just implement it in javascript, at least for listeners. Implementing your own xpcom services would be a little more complicated.
Searching the addon sdk can often provide some hints too. In this case they don't seem to be using .addListener, but the file hints at another interesting service, which in turn you can find on MDN: nsIWindowWatcher.
Basically, if you're writing restartless addons you're rummaging through the entrails of firefox and will have to do some detective work to find the exact components you need. If you want something more convenient I would recommend the addon sdk, which provides a more organized but also more restricted set of commonly used APIs

Java Script error - can't convert undefined to object

I get "can't convert undefined to object" error while trying to run this piece of code. I'm not a programmer and can barely code therefore my question might be quite stupid/unanswerable for what I'm deeply sorry.
Code:
if (path == F[0])
{
//go N
if (pointAy > 0)
{
if (!(PS.BeadData(pointAx, pointAy - 1) === "blocked"))
{
// Set bead to Previous State
PS.BeadColor(pointAx, pointAy, previous_bead_NPC[NPCid][2]);
PS.BeadData(pointAx, pointAy, 0);
PS.BeadGlyph(pointAx, pointAy, " ");
// Increment
pointAy -= 1;
// Place NPC
MakeNPC(pointAx, pointAy, NPC[NPCid][2], NPC[NPCid][3], NPC[NPCid][4], NPC[NPCid][5], 1);
}
}
}
Can't really tell if this is enough to find an answer for you - I can post more of the code if it would help.
Maybe there is some generic answer to such an error a normal programmer would know, but such a noob like me will be oblivious to?
UPDATE
Ok, through step-by-step execution I found out that the error pops out in a different function even though disabling above piece of code makes the error not pop up. This is the function that makes the error pop up:
PS.Tick = function ()
{
"use strict";
for (var NPCid = 0; NPCid < 10; NPCid++)
{
NPCAI(NPCid);
};
};
This function is called every second and it calls AI logic function to move 10 NPC on a grid by supplying the NPCid to the AI function. Script fails here, but not always - usually one or two of the NPCs makes a step and only then the function fails.
If you are using Chrome or Firebug you can step through the JavaScript code. On Chrome, open up the tools icon (wrench in the upper right corner), then enable the developer tools by selecting "Tools" from the drop down menu and the "Developer Tools". At the bottom you should see a button in the lower part of your screen for scripts. Click on that and navigate to your page. When you see your JavaScript file open it and put a breakpoint at the "if" statement. Reload your page and then look at the values of PS and NPC when the debugger stops your code.

Categories