 /*******************************************************************************************************************************
 * It's Browser Time!
 * 
 *
 * Copyright (C) 2013 by Tobias Lidskog (https://twitter.com/tobiaslidskog) &  Peter Hedenskog (http://peterhedenskog.com)
 *
 ********************************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at
 * 
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is 
 * distributed  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   
 * See the License for the specific language governing permissions and limitations under the License.
 *
 ********************************************************************************************************************************
 */
package com.soulgalore.web.browsertime.datacollector;

import com.soulgalore.web.browsertime.timings.TimingRun;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

import java.util.Map;

/**
 * Custom data defined by browser time.
 */
public class BrowserTimeDataCollector extends TimingDataCollector {

    private static final MarkInterval[] intervals = {
            new MarkInterval("domainLookupTime", "domainLookupStart", "domainLookupEnd"),
            new MarkInterval("redirectionTime", "navigationStart","fetchStart"),
            new MarkInterval("serverConnectionTime", "connectStart", "connectEnd"),
            new MarkInterval("serverResponseTime", "requestStart", "responseStart"),
            new MarkInterval("pageDownloadTime", "responseStart", "responseEnd"),
            new MarkInterval("domInteractiveTime", "navigationStart", "domInteractive"),
            new MarkInterval("domContentLoadedTime", "navigationStart", "domContentLoadedEventStart"),
            new MarkInterval("pageLoadTime", "navigationStart", "loadEventStart"),            
    };

    @Override
    public void collectPageData(JavascriptExecutor js, Map<String, String> pageInfo) {
        // This won't give proper url in case in connections error
        if (js instanceof WebDriver) {
            pageInfo.put("actualUrl", ((WebDriver)js).getCurrentUrl());
        }

        if (js instanceof HasCapabilities) {
            Capabilities caps = ((HasCapabilities) js).getCapabilities();
            pageInfo.put("browserName", caps.getBrowserName());
            pageInfo.put("browserVersion", caps.getVersion());
            pageInfo.put("platform", caps.getPlatform().name());
            // caps.asMap()
        }
    }

    @Override
    public void collectMeasurements(JavascriptExecutor js, TimingRun results) {
        for (MarkInterval interval : intervals) {
            interval.collectMeasurement(results);
        }
    }

}

@@ -1,9 +1,8 @@
- 
 /*******
@@ -122,16 +122,16 @@
 *******%0A
+
  * It's 
@@ -146,17 +146,16 @@
 Time!%0A *
- 
 %0A *%0A * C
@@ -587,17 +587,16 @@
 se at%0A *
- 
 %0A *%0A *  
@@ -1213,17 +1213,16 @@
 ingRun;%0A
-%0A
 import o
@@ -1380,24 +1380,47 @@
 WebDriver;%0A%0A
+import java.util.List;%0A
 import java.
@@ -1757,16 +1757,17 @@
 nStart%22,
+ 
 %22fetchSt
@@ -2298,28 +2298,16 @@
 Start%22),
-            
 %0A    %7D;%0A
@@ -2564,16 +2564,17 @@
 bDriver)
+ 
 js).getC
@@ -2921,37 +2921,489 @@
     
+%7D%0A%0A
     
-// caps.asMap()%0A        %7D
+    pageInfo.put(%22userAgent%22, js.executeScript(%22return window.navigator.userAgent%22).toString());%0A        List size = (List) js.executeScript(%22var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')%5B0%5D,%22 +%0A                %22x=w.innerWidth%7C%7Ce.clientWidth%7C%7Cg.clientWidth,y=w.innerHeight%7C%7Ce.clientHeight%7C%7Cg.clientHeight;%22 +%0A                %22return %5Bx,y%5D;%22);%0A        pageInfo.put(%22windowSize%22, String.valueOf(size.get(0)) + %22x%22 + String.valueOf(size.get(1)));
 %0A   

Include userAgent and windowSize in pageInfo.