Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

perl scripter error ReferenceError: The variable ActiveXObject has not been declared

by gurudutt.rv (Initiate)
on Aug 02, 2012 at 09:32 UTC ( #984992=perlquestion: print w/ replies, xml ) Need Help??
gurudutt.rv has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run a js script from the response of http request. Following is the code.
#!/usr/bin/perl use WWW::Scripter; use URI; $w = new WWW::Scripter; $w->use_plugin('JavaScript'); $response=$w->get("sdt1.corp.xyz.com:8080/click/phoenix/339cd9 +314fe0136d3c30f6e9984b1ddc?clickId=sfshsksk1234go"); $data_ref = $response->content_ref( ); #this response is a html code with a js link enbedded my $h = $$data_ref; my $u = new URI 'data:'; $u->media_type('text/html'); $u->data( $h ); $w->get($u);
The html code in $h is as follows
<html><body><div id="iat-click-js"></div><script>var _clickurl="http:/ +/sdt1.corp.xyz.com:8080/click/phoenix/339cd9314fe0136d3c30f6e9984b1dd +c?clickId=sfshsksk1234go&csrdmnb=1343895381009";var _fpdatakey="afpda +ta";(function(){var e=document.createElement('script');e.src='https:/ +/d3hhytn20582jn.cloudfront.net/iatclickbeacon.js';e.async=true;docume +nt.getElementById('iat-click-js').appendChild(e);}());</script></body +></html>
and the content of the js is as follows.
fortyone=new function(){this.e=(new Date(2005,0,15)).getTimezoneOffset +();this.f=(new Date(2005,6,15)).getTimezoneOffset();this.plugins=[];t +his.d={Flash:["ShockwaveFlash.ShockwaveFlash",function(b){return b.ge +tVariable("$version")}],Director:["SWCtl.SWCtl",function(b){return b. +ShockwaveVersion("")}]};this.r=function(b){var c;try{c=document.getEl +ementById(b)}catch(d){}if(c===null||typeof c==="undefined")try{c=docu +ment.getElementsByName(b)[0]}catch(e){}if(c===null||typeof c==="undef +ined")for(var f=0;f<document.forms.length;f++)for(var g=document.form +s[f],h=0;h<g.elements.length;h++){var a=g[h];if(a.name===b||a.id===b) +return a}return c};this.b=function(b){var c="";try{if(typeof this.c.g +etComponentVersion!=="undefined")c=this.c.getComponentVersion(b,"Comp +onentID")}catch(d){b=d.message.length;b=b>40?40:b;c=escape(d.message. +substr(0,b))}return c};this.exec=function(b){for(var c=0;c<b.length;c +++)try{var d=eval(b[c]);if(d)return d}catch(e){}return""};this.p=func +tion(b){var c="";try{if(navigator.plugins&&navigator.plugins.length){ +var d=RegExp(b+".* ([0-9._]+)");for(b=0;b<navigator.plugins.length;b+ ++){var e=d.exec(navigator.plugins[b].name);if(e===null)e=d.exec(navig +ator.plugins[b].description);if(e)c=e[1]}}else if(window.ActiveXObjec +t&&this.d[b])try{var f=new ActiveXObject(this.d[b][0]);c=this.d[b][1] +(f)}catch(g){c=""}}catch(h){c=h.message}return c};this.q=function(){f +or(var b=["Acrobat","Flash","QuickTime","Java Plug-in","Director","Of +fice"],c=0;c<b.length;c++){var d=b[c];this.plugins[d]=this.p(d)}};thi +s.g=function(){return Math.abs(this.e-this.f)};this.h=function(){retu +rn this.g()!==0};this.i=function(b){var c=Math.min(this.e,this.f);ret +urn this.h()&&b.getTimezoneOffset()===c};this.n=function(b){var c=0;c +=0;if(this.i(b))c=this.g();return c=-(b.getTimezoneOffset()+c)/60};th +is.j=function(b,c,d,e){if(typeof e!=="boolean")e=false;for(var f=true +,g;(g=b.indexOf(c))>=0&&(e||f);){b=b.substr(0,g)+d+b.substr(g+c.lengt +h);f=false}return b};this.m=function(){return(new Date(2005,5,7,21,33 +,44,888)).toLocaleString()};this.k=function(b){var c=new Date,d=[func +tion(){return"TF1"},function(){return"015"},function(){return ScriptE +ngineMajorVersion()},function(){return ScriptEngineMinorVersion()},fu +nction(){return ScriptEngineBuildVersion()},function(a){return a.b("{ +7790769C-0471-11D2-AF11-00C04FA35D02}")},function(a){return a.b("{898 +20200-ECBD-11CF-8B85-00AA005B4340}")},function(a){return a.b("{283807 +B5-2C60-11D0-A31D-00AA00B92C03}")},function(a){return a.b("{4F216970- +C90C-11D1-B5C7-0000F8051515}")},function(a){return a.b("{44BBA848-CC5 +1-11CF-AAFA-00AA00B6015C}")},function(a){return a.b("{9381D8F2-0288-1 +1D0-9501-00AA00B911A5}")},function(a){return a.b("{4F216970-C90C-11D1 +-B5C7-0000F8051515}")},function(a){return a.b("{5A8D6EE0-3E18-11D0-82 +1E-444553540000}")},function(a){return a.b("{89820200-ECBD-11CF-8B85- +00AA005B4383}")},function(a){return a.b("{08B0E5C0-4FCB-11CF-AAA5-004 +01C608555}")},function(a){return a.b("{45EA75A0-A269-11D1-B5BF-0000F8 +051515}")},function(a){return a.b("{DE5AED00-A4BF-11D1-9948-00C04F98B +BC9}")},function(a){return a.b("{22D6F312-B0F6-11D0-94AB-0080C74C7E95 +}")},function(a){return a.b("{44BBA842-CC51-11CF-AAFA-00AA00B6015B}") +},function(a){return a.b("{3AF36230-A269-11D1-B5BF-0000F8051515}")},f +unction(a){return a.b("{44BBA840-CC51-11CF-AAFA-00AA00B6015C}")},func +tion(a){return a.b("{CC2A9BA0-3BDD-11D0-821E-444553540000}")},functio +n(a){return a.b("{08B0E5C0-4FCB-11CF-AAA5-00401C608500}")},function() +{return eval("navigator.appCodeName")},function(){return eval("naviga +tor.appName")},function(){return eval("navigator.appVersion")},functi +on(a){return a.exec(["navigator.productSub","navigator.appMinorVersio +n"])},function(){return eval("navigator.browserLanguage")},function() +{return eval("navigator.cookieEnabled")},function(a){return a.exec([" +navigator.oscpu","navigator.cpuClass"])},function(){return eval("navi +gator.onLine")},function(){return eval("navigator.platform")},functio +n(){return eval("navigator.systemLanguage")},function(){return eval(" +navigator.userAgent")},function(a){return a.exec(["navigator.language +","navigator.userLanguage"])},function(){return eval("document.defaul +tCharset")},function(){return eval("document.domain")},function(){ret +urn eval("screen.deviceXDPI")},function(){return eval("screen.deviceY +DPI")},function(){return eval("screen.fontSmoothingEnabled")},functio +n(){return eval("screen.updateInterval")},function(a){return a.h()},f +unction(a){return a.i(c)},function(){return"@UTC@"},function(a){retur +n a.n(c)},function(a){return a.m()},function(){return eval("screen.wi +dth")},function(){return eval("screen.height")},function(a){return a. +plugins.Acrobat},function(a){return a.plugins.Flash},function(a){retu +rn a.plugins.QuickTime},function(a){return a.plugins["Java Plug-in"]} +,function(a){return a.plugins.Director},function(a){return a.plugins. +Office},function(){return(new Date).getTime()-c.getTime()},function(a +){return a.e},function(a){return a.f},function(){return c.toLocaleStr +ing()},function(){return eval("screen.colorDepth")},function(){return + eval("window.screen.availWidth")},function(){return eval("window.scr +een.availHeight")},function(){return eval("window.screen.availLeft")} +,function(){return eval("window.screen.availTop")},function(a){return + a.a("Acrobat")},function(a){return a.a("Adobe SVG")},function(a){ret +urn a.a("Authorware")},function(a){return a.a("Citrix ICA")},function +(a){return a.a("Director")},function(a){return a.a("Flash")},function +(a){return a.a("MapGuide")},function(a){return a.a("MetaStream")},fun +ction(a){return a.a("PDFViewer")},function(a){return a.a("QuickTime") +},function(a){return a.a("RealOne")},function(a){return a.a("RealPlay +er Enterprise")},function(a){return a.a("RealPlayer Plugin")},functio +n(a){return a.a("Seagate Software Report")},function(a){return a.a("S +ilverlight")},function(a){return a.a("Windows Media")},function(a){re +turn a.a("iPIX")},function(a){return a.a("nppdf.so")},function(a){ret +urn a.o()}];this.q();for(var e="",f=0;f<d.length;f++){if(b){e+=this.j +(d[f].toString(),'"',"'",true);e+="="}var g;try{g=d[f](this)}catch(h) +{g=""}e+=b?g:escape(g);e+=";";if(b)e+="\\n"}return e=this.j(e,escape( +"@UTC@"),(new Date).getTime())};this.l=function(b){try{if(!b)return t +his.k();var c;c=this.r(b);if(c!==null)try{c.value=this.k()}catch(d){c +.value=escape(d.message)}}catch(e){}};this.a=function(b){try{if(navig +ator.plugins&&navigator.plugins.length)for(var c=0;c<navigator.plugin +s.length;c++){var d=navigator.plugins[c];if(d.name.indexOf(b)>=0)retu +rn d.name+(d.description?"|"+d.description:"")}}catch(e){}return""};t +his.o=function(){var b=document.createElement("span");b.innerHTML="&n +bsp;";b.style.position="absolute";b.style.left="-9999px";document.bod +y.appendChild(b);var c=b.offsetHeight;document.body.removeChild(b);re +turn c}};try{fortyone.c=document.createElement("span");typeof fortyon +e.c.addBehavior!=="undefined"&&fortyone.c.addBehavior("#default#clien +tCaps")}catch(i){}window.fortyone=fortyone;window.fortyone.collect=fo +rtyone.l; function sendclickping(){ var req; if (window.XMLHttpRequest) { req=new XMLHttpRequest(); } else { req=new ActiveXObject("Microsoft.XMLHTTP"); } if (req != null) { req.open("POST",_clickurl,true); req.onreadystatechange= function() { if (req.readyState==4 && req.status==200) { var _rurl=req.getResponseHeader("location"); if (_rurl && _rurl.length != 0) { window.location.replace(_rurl); } else { console.log("could not get the redirect url"); } } } req.setRequestHeader("Content-type","application/x-www-form-ur +lencoded"); var _pbody=_fpdatakey+"="+escape(fortyone.collect()); req.send(_pbody); } else { console.log("AJAX (XMLHTTP) not supported."); } } sendclickping();
It was running perfectly fine until this morning and not even a single line of code has been changed. I am getting the following error now when i run the perl script.

gurudutt@MK-QA-28:~$ ./js1.pl ReferenceError: The variable ActiveXObject has not been declared at https://d3hhytn20582jn.cloudfront.net/iatclickbeacon.js, line 8.

I have no idea what went wrong.

Comment on perl scripter error ReferenceError: The variable ActiveXObject has not been declared
Select or Download Code
Re: perl scripter error ReferenceError: The variable ActiveXObject has not been declared
by Anonymous Monk on Aug 02, 2012 at 09:46 UTC

    I have no idea what went wrong.

    Unsupported feature is unsupported (activex)

      If you look at the js, it should not have gone inside the else condition, all this while when it was working, i think the if condition was satisfied. But for some reason it is not going into the if condition today and am really appalled by so little support in perl by the module owners.
      if (window.XMLHttpRequest) { req=new XMLHttpRequest(); } else { req=new ActiveXObject("Microsoft.XMLHTTP"); }
      In this script, this part holds the key
      my $u = new URI 'data:'; $u->media_type('text/html'); $u->data( $h ); $w->get($u);
      Is there something to do with media_style, using something else instead of text/html?

        "But for some reason it is not going into the if condition today and am really appalled by so little support in perl by the module owners."

        Wait, you contacted them about your code not working today and they haven't fixed it for you yet? That's disgraceful! The support contract and maintenance you pay for states that... oh what, forget it. I notice there are zero open bugs listed in the RT queue.

        Consider debugging this yourself rather than being appalled with anyone else, it's a more productive use of effort. If you find a genuine problem consider actually reporting it.

        Not to quibble over the use of language which may be less than precisely clear, but you do understand, don't you, that "the module owners" are unpaid volunteers, all over the world?

        Why, the indivual or team responsible may even have been asleep, out fighting a fire, coaching a kid's team or -- horrors -- on vacation, when you encountered your problem.

        Have you got WWW::Scripter::Plugin::Ajax installed?

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Hi,

        Are you using a different browser?
        This is the code I use.

        try { // Firefox, Opera 8.0+, Safari Http=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { Http=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { Http=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } }

        It may catch your error, it's worth a try.

        J.C.

Re: perl scripter error ReferenceError: The variable ActiveXObject has not been declared
by sundialsvc4 (Monsignor) on Aug 02, 2012 at 14:16 UTC

    Pardon me for being unwilling to try to prize apart some “minify’d” JavaScript code, but my initial impression of the matter is that the code must be expecting other declarations to have previously been downloaded (i.e. by means of a <script> tag).   It expects these to have been incorporated into the same JavaScript environment before the code in question is received and the attempt is made to compile and run it.   (It also expects that no syntax error has lately been introduced into any of that code!   An error would stop the JavaScript interpreter, with or without a visible warning .. look in the browser debugger .. perhaps before the declarations you need have been processed.)

    I thnk that you need to “look underneath these other toadstools.”   It is actually unreasonable to think that something “just happened yesterday” to the material that is being received from the AJAX call.   If your shop maintains version-control as it should, pore through the list of recent commits.   Look, with an open mind, for anything that this material may “touch,” that has been updated in any way whatsoever during the period of time since your “last known good” state.   Also, clear the browser caches and methodically test the behavior to “box it in” on various available computer systems and browser types.   The error-messages and (e.g. FireBug) debugging outputs available on different browsers might give you an important clue.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://984992]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2014-08-21 04:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls