I am trying to associate an XMLHttpRequest with a tab on the browser using the following code:
function getBrowserFromChannel(aChannel) {
var notificationCallbacks =
aChannel.notificationCallbacks ?
aChannel.notificationCallbacks :
aChannel.loadGroup.notificationCallbacks;
if (!notificationCallbacks) {
console.log("no callbacks");
return (0);
}
var loadContext = notificationCallbacks.getInterface(Ci.nsILoadContext);
getInterface(Ci.nsILoadContext) fails with: "Component does not have requested interface"
Any idea how else I can get the browser?
Thanks
Try this code (from Lightbeam):
function getLoadContext(aRequest) {
try {
// first try the notification callbacks
var loadContext = aRequest.QueryInterface(Ci.nsIChannel)
.notificationCallbacks.getInterface(Ci.nsILoadContext);
return loadContext;
} catch (ex) {
// fail over to trying the load group
try {
if (!aRequest.loadGroup) return null;
var loadContext = aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
return loadContext;
} catch (ex) {
return null;
}
}
}
Note the license is MPL 1.1/GPL 2.0/LGPL 2.1
Related
I´m trying to take a screenshot after a step failed:
const { After } = require('cucumber');
After(function (scenario) {
if (scenario.result.status ==='failed') {
var world = this;
return browser.takeScreenshot().then(function(screenShot, error) {
if (!error) {
world.attach(screenShot, "image/png");
}
});
}
});
It shows me an error with the browser:
ReferenceError: browser is not defined
Try the below. Make sure to match the webdriver var name matched as per your usage.
var {After, Status} = require('cucumber');
After(function (testCase) {
var world = this;
if (testCase.result.status === Status.FAILED) {
// driver- update this with the correct webDriver variable
return driver.takeScreenshot().then(function(screenShot) {
// screenShot is a base-64 encoded PNG
world.attach(screenShot, 'image/png');
});
}
});
I'm trying to use the Kaazing Library in our HTML5 client. I already implemented it in a java client and it worked. It seems that there is a problem with the LoginHandler. When I debug the code it ends in a endless loop in the LoginHandler. The line callback(new PasswordAuthentication(usr, pwd)) is called over and over again:
// Configure a Basic Challenge Handler
var basicHandler = new BasicChallengeHandler();
basicHandler.loginHandler = function(callback) {
callback(new PasswordAuthentication(usr, pwd));
}
JmsConnectionProperties jmsProps = new JmsConnectionProperties();
jmsProps.connectionTimeout = 1000000;
jmsProps.reconnectAttemptsMax = -1;
jmsProps.reconnectDelay = 3000;
jmsProps.shutdownDelay = 5000;
console.log("Connect to: " + url);
// Create Connection Factory
jmsConnectionFactory = new JmsConnectionFactory(url, jmsProps);
websocketFactory = jmsConnectionFactory.getWebSocketFactory();
websocketFactory.setChallengeHandler(basicHandler);
// reate Connection future handler for the result
try {
if (connection == null) {
var connectionFuture = jmsConnectionFactory.createConnection( function() {
try {
// never comes to this line!!!
connection = connectionFuture.getValue();
// DO SOME STUFF
} catch (e) {
console.dir(e);
// alert(e.message);
}
});
} else {
try {
connection.close(function() { /* Closed */
});
} finally {
connection = null;
}
}
} catch (ex) {
console.dir(ex);
}
Any help would be very appreciated!
Regards
Angela
Is it possible that the username and password combination is incorrect, so that the client is being re-challenged?
I get data back from a php server and sometimes it tosses in warnings. These warnings cause the parsing of the response to throw a syntax error which defies all try/catch code I have in place and just stops processing, leaving complex objects in partial states that can't be recovered.
How can I catch these errors? I want to have a chance to get the object back into some steady state.
Ideally, I would not receive answers stating that I should rethink architecture or change php settings. I would like to know how to respond to SyntaxErrors being thrown by JSON.parse().
Thank you,
Jeromeyers
EDIT:
It has come to my attention that the problem is more complex than I originally thought. This is the code that doesn't catch the SyntaxError:
generateSubmissionSuccessCallback: function (reloadOnSave) {
var self = this;
var submissionCallback = function(response) {
var processingError = false;
try
{
var responseObject = {};
if (self.isAspMode())
{
if (typeof response !== 'object') // Chrome auto-parses application/json responses, IE & FF don't
{
response = JSON.parse(response);
}
responseObject = {
entity: response.Payload,
success: response.Success,
message: response.Exception
};
if (jQuery.isArray(response.ValidationErrors))
{
responseObject.message += ' \r\n\r\nValidation Errors\r\n';
for (var i = 0, maxi = response.ValidationErrors.length; i < maxi; i++)
{
var error = response.ValidationErrors[i];
responseObject.message += error.Error + '\r\n';
}
}
}
else
{
responseObject = JSON.parse(response);
}
if (!responseObject || (responseObject.success !== undefined && responseObject.success !== true))
{
processingError = true;
var message = responseObject ? responseObject.message : response;
ErrorHandler.processError(
'An attempt to save failed with following message: \r\n' + message,
ErrorHandler.errorTypes.clientSide,
null,
jQuery.proxy(self.validatingAndSubmittingFinallyFunction, self));
}
else
{
// If this is a parent metaform, reload the entity, otherwise, close the metaform
if (self.metaformType === 'details')
{
if (self.substituteWhatToDoAfterSavingCallback)
{
self.substituteWhatToDoAfterSavingCallback(responseObject);
}
else if (reloadOnSave)
{
self.reloadCurrentEntity(true, responseObject.entity);
}
if (self.doesViewOutlineDefinePostSaveHook())
{
self.viewOutline.functions.postSaveHook(self);
}
}
else if (self.metaformType === 'childDetails')
{
// Reload the Grid by which this form was made
if (self.associatedGridId)
{
Metagrid.refresh(self.associatedGridId);
}
if (self.parentMetaform.associatedGridId && self.childPropertyName)
{
var annotation = self.parentMetaform.getAnnotationByPropertyName(self.childPropertyName);
if (annotation && annotation.hasPropertyOptions('updateParentMetaformAssociatedGrid'))
{
Metagrid.refresh(self.parentMetaform.associatedGridId, self.parentMetaform.entityId);
}
}
if (self.substituteWhatToDoAfterSavingCallback)
{
if (self.doesViewOutlineDefinePostSaveHook())
{
self.viewOutline.functions.postSaveHook(self);
}
self.substituteWhatToDoAfterSavingCallback(responseObject);
}
else
{
if (self.doesViewOutlineDefinePostSaveHook())
{
self.viewOutline.functions.postSaveHook(self);
}
self.disposeMetaform();
}
}
}
}
catch (ex)
{
processingError = true;
ErrorHandler.processError(
"Please immediately inform the authorities that: \r\n\r\n" + typeof response === 'string' ? response : JSON.parse(response) + "\r\n\r\nand:\r\n\r\n " + ex.message,
ErrorHandler.errorTypes.clientSide,
null,
jQuery.proxy(self.validatingAndSubmittingFinallyFunction, self));
}
finally
{
// If we are reporting an error to the user then we can't reset these state variables
// because in the case where this is a child form, the parent will close the form
// before the user has read the error.
if (!processingError)
{
self.validatingAndSubmittingFinallyFunction();
}
}
};
return jQuery.proxy(submissionCallback, self);
}
There's really a lot going on in there, and a lot of structure that it fits into. I don't know if including it will really help.
Assuming you are talking about JSON and it raising an error (and not actual JavaScript being served to the page):
var data;
try{
data = JSON.parse(jsonString);
}catch(e){
// handle the error here, if you like
}
if (typeof data !== "undefined"){
// Yay, we got some!
}
Read more about try...catch at MDN.
For example (from Chrome's console):
> try{ JSON.parse('3/') }catch(e){ console.log('oh no!') }; console.log('OK!')
"oh no!"
"OK!"
Here is how the code is.
function AppAssistant() {
this.dbObj = new DatabaseAssistant();
this.schemaObj = new SchemaAssistant();
this.result = {};
}
AppAssistant.prototype.setup = function() {
}
AppAssistant.prototype.handleLaunch = function(launchParams) {
if (gConfigDatabase.engine == "sqllite") {
} else {
}
}
AppAssistant.prototype.processResult = function() {
}
AppAssistant.prototype.execMigrations = function(version) {
}
// Database error handler
// If the db does not exists, it will generate set of tables
AppAssistant.prototype.errorHandler = function() {
Mojo.Log.info("In app asst error handler.");
if (gConfigDatabase.engine == "sqllite") {
try {
// execute some queries to create tables and insert some values in the HTML Opendatabase.
// Show disclaimer Page
Mojo.Controller.stageController.pushScene('disclaimer');
} catch (e) {
Mojo.Log.error("In AppAssistant errorHandler : ", e);
}
} else {
Mojo.Log.info("db8 part of app asst error handler");
try {
// execute operations to create kinds for db8 analogous to tables
Mojo.Controller.stageController.pushScene("disclaimer");
} catch (e) {
Mojo.Log.info("Error in db8 appAsst error handler", e);
}
}
}
AppAssistant.prototype.handleCommand = function(event) {
}
All this was done to support both sqllite and db8 for an webOS app. The problem i am facing is that when i configure a variable (gConfigDatabase) as sqllite then the Mojo.Controller.stageController.pushScene` method which is there in the errorHandler function works. but when i change it so that db8 engine is used, then i get an error saying undefined method pushScene. Any clues or hints on debugging or solving this ?
Is there a way to test if an ActiveX control is installed using Javascript?
function AXOrNull(progId) {
try {
return new ActiveXObject(progId);
}
catch (ex) {
return null;
}
}
Solution, try to invoke a new ActiveXObject:
function testForActiveX(){
tester = null;
try {
tester = new ActiveXObject('htmlfile');
}
catch (e) {
// catch the exception
}
if (tester) {
// ActiveX is installed
return true;
}
return false;
}
try{
if(new ActiveXObject("Nameofplugin")){
// write your code if plugin available
}
else{
// write your code if plugin is not available
}
}
catch(erro){
//write your code if plugin is not available
}
`
Nameofplugin you can get from IE--> Tool-->ManageAddons-->Check the List and pick the name of your supportive plugin