Skip to content
Jan Odvarko edited this page Dec 1, 2015 · 11 revisions

Summary:

--

HAR is not defined

Since HAR object is exposed into the page content asynchronously it isn't available from the very beginning, so if your script is executed before HAR is available you might get HAR is not defined error.

Note that the HAR object is exposed to a browser tab just once after the tab is loaded for the first time. When the tab content (i.e. the web-page) is reloaded or navigated to different location the HAR object stays there all the time.

To solve the error you need to check existence of the HAR object before using it. See the script below.

function triggerExport() {
  var options = {
    token: "test",    // Value of the token in your preferences
    getData: true,    // True if you want to get HAR data as a string
  };

  HAR.triggerExport(options).then(result => {
    console.log(result.data);
  });
};

// If HAR isn't yet defined, wait for the `har-api-ready` event.
// Otherwise trigger the export right away.
if (typeof HAR === 'undefined') {
  addEventListener('har-api-ready', triggerExport, false);
} else {
  triggerExport();
};

Similar script should be used when using Selenium to trigger the export.

Clone this wiki locally