I Followed this article, explaining how to spice up an Internet Explorer COM-Object with jQuery. While the author used Python, I want to do something similar in Powershell. So now I have this code:
function addJQuery ($browser) {
$url="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"
$document = $browser.document
$window = $document.parentWindow
$head = @($document.getElementsByTagName("head"))[0]
$script = $document.createElement("script")
$script.type = "text/javascript"
$script.src = $url
$head.appendChild($script)
while (!$window.jQuery) {
sleep -milliseconds 100
}
return $window.jQuery
}
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.Navigate("https://some.site.com")
while ($ie.busy) {start-sleep -milliseconds 500}
$j = addJQuery $ie
With Fiddler and via the document.scripts collection I verified that the file gets downloaded. However, the script sleeps forever and when I try to output $window.jQuery it prints nothing in the Powershell ISE console.
The Script is nevertheless correctly loaded, since jQuery-Functions can be called from the browser's console. Could it be that the exposed properties of the Internet Explorer COM-Object differ between Python and Powershell?