<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecore Xperiences &#187; Phantom JS</title>
	<atom:link href="http://blog.peplau.com.br/category/phantom-js/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.peplau.com.br</link>
	<description>The things I&#039;ve seen as a Sitecore Professional</description>
	<lastBuildDate>Sun, 13 Feb 2022 16:58:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.34</generator>
	<item>
		<title>PhantomJS Screenshots not being generated with Windows Authentication turned on</title>
		<link>http://blog.peplau.com.br/phantomjs-screenshots-not-being-generated-with-windows-authentication-turned-on/</link>
		<comments>http://blog.peplau.com.br/phantomjs-screenshots-not-being-generated-with-windows-authentication-turned-on/#comments</comments>
		<pubDate>Sun, 26 Mar 2017 18:06:19 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Phantom JS]]></category>
		<category><![CDATA[Support Ticket]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=560</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="http://blog.peplau.com.br/phantomjs-screenshots-not-being-generated-with-windows-authentication-turned-on/"></div>It has been observed with several versions of Sitecore 8 and above (empty versions) &#8211; including 8.2 Update 2 &#8211; that the screenshot generation is broken when the site has Windows Authentication turned ON. Symptoms When attempting to start up a test in any level, the Test Start dialog will show screenshots of your website to demonstrate [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>It has been observed with several versions of Sitecore 8 and above (empty versions) &#8211; including 8.2 Update 2 &#8211; that the screenshot generation is broken when the site has Windows Authentication turned ON.</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Test-Screenshots-3.png"><img class=" size-full wp-image-562 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Test-Screenshots-3.png" alt="How Windows Authentication is turned on on IIS" width="481" height="142" /></a></p>
<h2>Symptoms</h2>
<p>When attempting to start up a test in any level, the Test Start dialog will show screenshots of your website to demonstrate how your tested content will display. This can be experienced, for instance, if you trigger the Page Test command inside Experience Editor:</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Page-Test.png"><img class=" size-full wp-image-563 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Page-Test.png" alt="Create Page Test" width="81" height="93" /></a></p>
<p>When the Page Test dialog appears you will noticed screenshots are all broken:</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Test-Screenshots-1.png"><img class="alignnone size-full wp-image-564" src="http://blog.peplau.com.br/wp-content/uploads/Test-Screenshots-1.png" alt="Page Test - Screenshot errors 1" width="487" height="465" /></a></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Test-Screenshots-2.png"><img class="alignnone size-full wp-image-565" src="http://blog.peplau.com.br/wp-content/uploads/Test-Screenshots-2.png" alt="Page Test - Screenshot errors 2" width="562" height="581" /></a></p>
<p>Sitecore log shows the following messages during the generation of screenshots:</p>
<pre>ManagedPoolThread #16 19:09:27 INFO Job started: Generate screenshots
18756 19:09:28 INFO [Content Testing]: PhantomJS console: 
Resource error
id: 0
url: http://sc82rev161221/?sc_mode=edit&amp;sc_itemid={110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}&amp;sc_disable_edit=yes&amp;sc_lang=en&amp;sc_version=1&amp;sc_vercomp=0
errorCode: 5
errorString: Operation canceled
!--error--!
ManagedPoolThread #16 19:09:28 INFO Job ended: Generate screenshots (units processed: 1)
ManagedPoolThread #5 19:09:30 INFO Job started: Generate screenshots
28116 19:09:30 INFO [Content Testing]: PhantomJS console: 
Resource error
id: 0
url: http://sc82rev161221/?sc_mode=edit&amp;sc_itemid={110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}&amp;sc_disable_edit=yes&amp;sc_lang=en&amp;sc_version=1&amp;sc_vercomp=0
errorCode: 5
errorString: Operation canceled
!--error--!
ManagedPoolThread #5 19:09:30 INFO Job ended: Generate screenshots (units processed: 1)</pre>
<h2>Root Cause</h2>
<p>In the end the root cause is not exactly Windows Authentication, but the fact that PhantomJs, when confronted with the Windows Authentication prompt, don&#8217;t know how to proceed.</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/WIndows-Auth-Prompt.png"><img class="alignnone size-full wp-image-566" src="http://blog.peplau.com.br/wp-content/uploads/WIndows-Auth-Prompt.png" alt="WIndows Auth Prompt" width="459" height="330" /></a></p>
<p>Unable to type Login and Password at this prompt, PhantomJS will get back a &#8220;403 &#8211; Forbidden&#8221; error and fail creating screenshots.</p>
<blockquote><p><em><strong>Short Story:</strong> the root cause is that PhantomJS doesn&#8217;t have proper permissions to access the filesystem and write down the screenshot images. This issue thus, may also happen in scenarios where Windows Authentication is not enabled.</em></p></blockquote>
<h2>How Windows Authentication is being used</h2>
<p>We are using Windows Authentication to achieve a specific goal at our environment: During Sitecore development, we have multiple Sitecore instances with different purposes (DEV, QA, UAT), being constantly updated by TeamCity, our Continuous Integration server. One of these instances (generally UAT) is exposed to public so our clients can access from outside. However, we don&#8217;t want unrelated people accessing this address, so we lock it down with Windows Authentication and provide our clients one or multiple internal accounts to login and access the website. Unrelated people would be stopped at the Windows Authentication prompt.</p>
<p>Ideal solution would be for us to know exactly what folder(s) to enable Anonymous authentication, so the website itself is protected and still PhantonJS can properly generate screenshots.</p>
<h2>Solution</h2>
<p>With the help of Sitecore Helpdesk we were able to determine how to tweak our website, enabling PhantomJS to properly generate screenshots of our website, and still sheltering it from being accessed by anyone but the people we want.</p>
<p>The solution consists of A) enabling Anonymous authentication for the site root node and B) disabling Anonymous authentication for every sub-folder and files</p>
<h2>Powershell Script</h2>
<p>Simple to understand, hard to implement.</p>
<p>Can we have this automatized? Yes of course! With the assistance of my college Eduardo Pereira  (thank you very much, my friend!) I was able to end up with the following PowerShell script:</p>
<pre>Import-Module WebAdministration
$Str_IISSiteName = "Your-Website-Name-On-IIS"
$Str_PSPath = "IIS:\Sites\" + $Str_IISSiteName + "\"
$Obj_Site = Get-Item $Str_PSPath
$Obj_Items = Get-ChildItem $Obj_Site.physicalPath
write-host "Changing authentication method on " $Str_IISSiteName
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/AnonymousAuthentication" -Name Enabled -Value True -PSPath $Str_PSPath
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/WindowsAuthentication" -Name Enabled -Value True -PSPath $Str_PSPath
Foreach ($Obj_Item in $Obj_Items)
{
    write-host "Changing authentication method on" $Str_PSPath$Obj_Item
    Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/AnonymousAuthentication" -Name Enabled -Value False -PSPath $Str_PSPath -location $Obj_Item
    Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/WindowsAuthentication" -Name Enabled -Value True -PSPath $Str_PSPath -location $Obj_Item
}</pre>
<p><strong>Important:</strong> you may need to give proper access to enable PowerShell to properly execute the script above. According to <a href="http://stackoverflow.com/questions/24535200/enable-authentication-for-iis-app-in-powershell" target="_blank">this StackOverflow article</a>, that very well describes the issue and solution, you may have to firstly execute the steps below:</p>
<ol>
<li>Open IIS Manager</li>
<li>Click the server name in the tree on the left</li>
<li>Right hand pane, Management section, double click Configuration Editor</li>
<li>At the top, choose the section system.webServer/security/authentication/anonymousAuthentication<br />
Right hand pane, click Unlock Section</li>
<li>At the top, choose the section system.webServer/security/authentication/windowsAuthentication<br />
Right hand pane, click Unlock Section</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.peplau.com.br/phantomjs-screenshots-not-being-generated-with-windows-authentication-turned-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
