I use the following command to launch a JS script: C:\Windows\System32\cscript.exe /nologo //E:{16d51579-a30b-4c8b-a276-0ff4dc41e755}
in order to use the latest Chakra engine.
In my script, the command WScript.Echo( ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion() + "." + ScriptEngineBuildVersion());
outputs 11.0.19326
.
I know this increases performance, and I thought I'd be also able to use the latest XMLHttpRequest
instead of the good old Microsoft.XMLHTTP
(I need responseURL) but it looks like I am not.
Is there a solution?
My guess is, the way you're loading the Chakra engine it's loading an invisible IE instance. But according to this MDN compatibility table there is no version of Internet Explorer that supports responseURL
.
Through much testing, attempting to load Edge's Chakra engine into Windows Script Host, I can land on no permutation that works. Creating an htmlfile
COM object and forcing compatibility using x-ua-compatible
, attempting the same with an HTA application (both natively and again with an htmlfile
COM object), attempting to create a MSXML2.ServerXMLHTTP.6.0
object, no Windows Script Host hack I can conceive will expose the .responseURL
property of an XMLHttpRequest object.
Best bet would be to pick a different language. In PowerShell you could do something like this:
$req = [Net.WebRequest]::Create("https://youtu.be/")
$resp = $req.GetResponse()
$resp.ResponseURI.AbsoluteURI
... which would print
https://www.youtube.com/?feature=youtu.be
And if you need the equivalent of .responseText
, just add the following:
$reader = new-object System.IO.StreamReader $resp.GetResponseStream()
$responseText = $reader.ReadToEnd()
If you want to parse $responseText using DOM methods...
$htmlfile = new-object -COM htmlfile
$htmlfile.IHTMLDocument2_writeln($responseText)
$buttons = $htmlfile.getElementsByTagName("button")
You can see the original revision of this answer for an example of what doesn't work.