Skip to content

Instantly share code, notes, and snippets.

@jraps20
Created October 24, 2017 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jraps20/ff3872110cac95cb29fb52a6644d1070 to your computer and use it in GitHub Desktop.
Save jraps20/ff3872110cac95cb29fb52a6644d1070 to your computer and use it in GitHub Desktop.
Gist to illustrate modifying the PhantomJS default timeout of zero to a new value
using Sitecore.ContentTesting.Pipelines.GetScreenShotForURL;
namespace MyLibrary.GetScreenShotForURL
{
public class AddTimeoutToScript : GenerateScreenShotProcessor
{
public string Timeout { get; set; }
private const string StandardExit = "phantom.exit();\r\n});";
private string TimeoutExit => "window.setTimeout(function () {\r\n page.render('%outfile%');\r\n phantom.exit();\r\n }, " + Timeout + ");\r\n});";
public override void Process(GetScreenShotForURLArgs args)
{
args.Script = args.Script.Replace(StandardExit, TimeoutExit);
var outputFilePath = Sitecore.ContentTesting.Helpers.PathHelper.MapPath(args.OutputFilename).Replace("\\", "\\\\");
args.Script = args.Script.Replace($"page.render('{outputFilePath}');", "");
args.Script = args.Script.Replace("%outfile%", outputFilePath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment