CRM 2015 Microsoft app xpathevaluator' is undefined - javascript

We are using crm 2015 and it is working without a problem.
All code is executed correctly in IE and in Chrome.
But when we try to use the crm app from Microsoft we get the error: 'xpathevaluator' is undefined.
I think it is the xrmservicetoolkit that is throwing the error.
if (typeof (node.selectSingleNode) != "undefined") {
return node.selectSingleNode(xpathExpr);
} else {
var xpe = new XPathEvaluator();
var xPathNode = xpe.evaluate(xpathExpr, node, _NSResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
return (xPathNode != null) ? xPathNode.singleNodeValue : null;
}

Related

javascript - Intercept and modify XHR response in chrome plugin

I'm writing a plugin that will intercept all the requests and responses and will extract data and if needed also modify the response. Below is the code I'm using to intercept the request, but it seems I can only read the response and not modify it. The code is injected into the page by manifest.json.
(function(xhr)
{
var XHR = XMLHttpRequest.prototype;
var send = XHR.send;
XHR.send = function(postData)
{
this.addEventListener('load', function()
{
if (postData)
{
if (typeof postData === 'string')
{
try
{
this._requestHeaders = postData;
} catch (err)
{
console.log(err);
}
}
else if (typeof postData === 'object' || typeof postData === 'array' || typeof postData === 'number' || typeof postData === 'boolean')
{
var enc = new TextDecoder("utf-8");
requestdata = enc.decode(postData);
console.log("postData");
var json = JSON.parse(requestdata);
console.log(json);
// Extract data from request
var req = this.responseText
// Change req, this does nothing!
this.responseText = req;
}
}
});
return send.apply(this, arguments);
};
})(XMLHttpRequest);
I understand this is because responseText is actually read only, and then property itself returns a cloned string, rather than a reference to actual response text. Is there any way around it? The only other way I see is using CEF, opening a web site from my CEF application and intercepting the requests there, which is nice, I can enhance the web site inside my application, but on the other hand it's cumbersome and I want my users to be able to download the plugin instead of having to use an exe.
Thanks!

Create Xml document based on the browser using Javascript

I am trying to get an older application to work in Chrome and Edge. It currently works only in Compatibility Mode. I have narrowed it down to where it gets the browser type and then creates the xml document based on the browser type.
// Identify and return the browser type
function getBrowserType()
{
try
{
if (typeof ActiveXObject != 'undefined')
{
//Microsoft Internet Explorer
return 'MSIE';
}
else if (typeof document != 'undefined'
&& document.implementation
&& document.implementation.createDocument
&& typeof DOMParser != 'undefined')
{
//Other browsers
return 'OTH';
}
}
catch(ex)
{
alert('Unable to find browser type.\n' + ex.message);
}
}
//create the xml DOM by browser detection
function createDoc(browserType)
{
var xmlDOM = null;
if (browserType == 'MSIE')
{
try
{
var names = [ 'Msxml2.DOMDocument.6.0',
'Msxml2.DOMDocument.3.0',
'MSXML2.DOMDocument',
'MSXML.DOMDocument',
'Microsoft.XMLDOM' ];
for (var key in names)
{
try
{
xmlDOM = new ActiveXObject(names[key]);
}
catch(ex)
{}
}
}
catch(ex)
{
alert('Unable to create XML Document.\n' + ex.message);
}
}
else if (browserType == 'OTH')
{
try
{
xmlDOM = document.implementation.createDocument("", "", null);
}
catch(ex)
{
alert('Unable to create XML Document.\n' + ex.message);
}
}
return xmlDOM;
}
So the object that is created is incorrect and it will not create the xml document. If the object created is the ActiveXObject, in Compatibility Mode, it has no problem. So this is based on the browser. So I basically need a way for this to work in all browsers. I think there may be a better way to do this as this is very old 2009 code.
I have tested your code on my side, it seems that I can't detect the IE browser (I'm using IE 11).
I suggest you could try to detect the browser using the window.navigator.userAgent property. code as below:
if (window.navigator.userAgent.toLowerCase().indexOf("trident") > -1) {
//Microsoft Internet Explorer
return "IE";
}
Because, the Browser Agent strings as below:
[Note] The navigator data can be changed by the browser owner, if the userAgent was not modified, user could use the above method to detect the browser using JavaScript.
Then, you could refer to this article to create XML DOM.

Fall-back support for XMLHTTPRequest

We have a web application that makes use of native XMLHttpRequest() to send data back to our server. One of our larger clients have users that appear to be running IE8 in Win7 (64-bit) and have "Enable native XMLHTTP support" disabled in their browser.
We've implemented the typical scenario of instantiating an ActiveXObject in place of XMLHttpRequest in order to try to support the likes if IE6 (no native XMLHTTP support; yes, we still have clients running this on thin clients!) which I am hoping IE8 can utilise as a fallback if this checkbox option has been switched off. However, once an object has been created, I get a type error when calling open() method on it.
Here's my code:
// Posts back an xml file synchronously and checks for parse error.
// Returns xml object or null. Used in RSUserData.
XML.PostXmlFile = function(sURL, doc)
{
try
{
// Validate Input
if ((typeof (sURL) != "string") || (sURL == ""))
return null;
if (window.XMLHttpRequest) // IE7+, FF and Chrome
{
// Mozilla, create a new DOMParser and parse from string
// Although IE9 and IE10 can successfully load XML using this block, it can't use document.evaluate nor selectNodes/selectSingleNode to navigate it
// Ref: http://msdn.microsoft.com/en-us/library/ie/ms535874(v=vs.85).aspx
// Ref: http://msdn.microsoft.com/en-us/library/ie/ms534370(v=vs.85).aspx
// Ref: http://blogs.msdn.com/b/ie/archive/2012/07/19/xmlhttprequest-responsexml-in-ie10-release-preview.aspx
var req = new XMLHttpRequest();
req.open("post", sURL, false);
req.send(doc);
if (req.status != 200)
throw { message: 'HTTP Post returned status ' + req.status + ' (' + req.statusText + ') when sending to ' + sURL };
// IE11+: req.responseXML returns a native XML Document
// IE9/10: req.responseXML returns an IXMLDOMDocument2 object but we can convert req.responseText to native XML using DOMParser
// IE6/7/8: req.responseXML returns an IXMLDOMDocument2 object but DOMParser is not available
if (window.DOMParser)
{
var parser = new DOMParser();
return parser.parseFromString(req.responseText, 'application/xml');
}
else
return req.responseXML; // NATIVE
}
else
{
// up to IE6:
// Ref: http://blogs.msdn.com/b/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx
var oXML = XML.GetActiveX_XML();
if (!oXML)
throw { message: "Could not instantiate an Msxml2 ActiveXObject", innerException: e };
oXML.open('POST', sURL, true);
oXML.send(sFile);
if (oXML.parseError.errorCode == 0)
{
xmlDoc = oXML;
return xmlDoc;
}
return null;
}
}
catch (e)
{
var s = "Exception in XML.PostXmlFile(). " + (e.message ? e.message : "");
throw { message: s, innerException: e };
}
}
XML.GetActiveX_XML = function()
{
var progIDs = ['Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.3.0'];
for (var i = 0; i < progIDs.length; i++)
{
try
{
var oXML = new ActiveXObject(progIDs[i]);
var sl = oXML.getProperty("SelectionLanguage");
if (sl !== "XPath")
oXML.setProperty("SelectionLanguage", "XPath"); // Changes v3.0 from XSLPattern to XPath
var ns = "xmlns:rs='" + XML._nsResolver('rs') + "' xmlns:xsi='" + XML._nsResolver('xsi') + "'";
// ns = "xmlns:na='http://myserver.com' xmlns:nb='http://yourserver.com'";
oXML.setProperty("SelectionNamespaces", ns);
return oXML;
}
catch (ex) { }
}
return null;
}
NOTES:
The aim is to call to XML.PostXmlFile() with the url and payload.
Modern browsers use new XMLHttpRequest() as expected
IE6 is expected to use XML.GetActiveX_XML() on account that window.XMLHttpRequest returns falsey
IE8 with "Enable native XMLHTTP support" disabled falls through to the IE6 code (because window.XMLHttpRequest returns falsey) but the instantiated object fails because it doesn't support open() method (oXML.open('POST', sURL, true);)
Is there any way I can post my payload back using IE8 when "Enable native XMLHTTP support" is disabled?
You should see if the Microsoft.XMLHTTP is available before checking if there is a XMLHttpRequest:
var bActiveX;
try {
new ActiveXObject('Microsoft.XMLHTTP');
bActiveX = true;
}
catch(e) {
bActiveX = false;
}
And then, check in your if condition:
if (window.XMLHttpRequest || bActiveX) { // IE7+, FF and Chrome
var req = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
/* the rest of your code */
}

issue with frames in chrome

I am facing an issue with frames with this particular code throwing an error:
window.parent.frames["searchoutput"].document.open("text/html");
Error: Uncaught TypeError: cannot call method 'open' of undefined
Any help is highly appreciated.
var frame = window.parent.frames["searchoutput"];
var frameDocument = (frame.contentWindow.document || frame.contentDocument);
frameDocument.open("text/html");
or more comprehensive version to check how to get document:
var doc;
if (iframe.document)
iframe.doc = iframe.document;
else if (iframe.contentDocument)
iframe.doc = iframe.contentDocument;
else if (iframe.contentWindow)
iframe.doc = iframe.contentWindow.document;

File API writing file doesn't work Samsung smart tv SDK

I have this javascript code which makes possible writing in a file
{
var fileSystemObj = new FileSystem();
var fileObj = fileSystemObj.openCommonFile(curWidget.id +
‘/testFile.data’, ‘w’);
fileObj.writeLine(‘something to write.’);
fileSystemObj.closeCommonFile(fileObj);
}
but it doesn't work. Doesn't even display any error!
samsung developer forum (you may not see unless you sign in... )
I am quoting it.
case tvKey.KEY_RED:
alert('RED BUTTON!');
alert('CWID: '+curWidget.id);
try {
var fileSystemObj = new FileSystem();
var fileObj = fileSystemObj.openCommonFile(curWidget.id+'/testFile.data','w');
fileObj.writeLine('something to write.');
fileSystemObj.closeCommonFile(fileObj);
} catch (e) {
alert('Error: file handling: '+e);
}
break;
lead to error:
alert() : Error: file handling: TypeError: 'null' is not an object
(evaluating 'fileObj.writeLine')
Reading cause same problem.
and solution accepted in that link is:
I suppose that problem is that you have to create common dir (if does not exist ) at first :
var fileObj = fileSystemObj.openCommonFile(filePath, 'w');
if(!fileObj){
var bValid = fileSystemObj.isValidCommonPath(curWidget.id);
if (!bValid) {
fileSystemObj.createCommonDir(curWidget.id);
}
}
fileObj = fileSystemObj.openCommonFile(filePath, 'w');
fileObj.writeLine('something to write.');
fileSystemObj.closeCommonFile(fileObj);

Categories

Resources