function createHAR(page, creator) {
  // @see: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html
  var address = page.address;
  var title = page.title;
  var startTime = page.startTime;
  var resources = page.resources;

  var entries = [];

  resources.forEach(function (resource) {
    var request = resource.request;
    var response = resource.response;

    if (!request || !response) {
      return;
    }

    // Exclude data URIs from the HAR because they aren't
    // included in the spec.
    if (request.url.substring(0, 5).toLowerCase() === "data:") {
      return;
    }

    entries.push({
      cache: {},
      pageref: address,
      request: {
        // Accurate bodySize blocked on https://github.com/ariya/phantomjs/pull/11484
        bodySize: -1,
        cookies: [],
        headers: request.headers,
        // Accurate headersSize blocked on https://github.com/ariya/phantomjs/pull/11484
        headersSize: -1,
        httpVersion: "HTTP/1.1",
        method: request.method,
        queryString: [],
        url: request.url,
      },
      response: {
        bodySize: response.bodySize,
        cookies: [],
        headers: response.headers,
        headersSize: response.headersSize,
        httpVersion: "HTTP/1.1",
        redirectURL: "",
        status: response.status,
        statusText: response.statusText,
        content: {
          mimeType: response.contentType || "",
          size: response.bodySize, // uncompressed
          text: "",
        },
      },
      startedDateTime: resource.startTime && resource.startTime.toISOString(),
      time: response.timeToLastByte,
      timings: {
        blocked: 0,
        dns: -1,
        connect: -1,
        send: 0,
        wait: 0, // response.timeToFirstByte || 0,
        receive: 0, // response.receiveTime,
        ssl: -1,
      },
    });
  });

  return {
    log: {
      creator: creator,
      entries: entries,
      pages: [
        {
          startedDateTime: startTime.toISOString(),
          id: address,
          title: title,
          pageTimings: {
            onLoad: page.onLoad || -1,
            onContentLoad: page.onContentLoad || -1,
          },
        },
      ],
      version: "1.2",
    },
  };
}
Inspired by phantomHAR
@author: Christopher Van (@cvan)
@homepage: https://github.com/cvan/phantomHAR
@original: https://github.com/cvan/phantomHAR/blob/master/phantomhar.js