Ouput console.time + timeEnd to txt file

Hi All,

I am having an issue trying to output the console.time for javascript to output into a txt file… I have had the same issue within another post using Microtime for PHP.but that has been completed

I have the following code - it shows me the time it takes to fetch the table in the google console log but how do I get that to show in a txt file.?

      url: '/users',
      type: 'GET'
    .done(function(users) {
    .fail(function(e) {

You can’t capture the console output in a variable or something; instead, you can use the performance API to measure, well, performance. Also you can’t write directly to a file from the browser, but you can create a blob from the data, convert that to an object URL, and redirect to that URL so that it gets displayed in the browser window (or the user gets prompted to save the file… this depends if the browser can handle the given type):

// Do something computation-intensive...
performance.measure('users', 'users-start', 'users-end')

// Get the performance entries and format them as desired
const usersEntries = performance.getEntriesByName('users')
const usersDurations = usersEntries.map(entry => `Duration: ${entry.duration}\n`)

// Create a blob and then an object URL from that blob
const blob = new Blob(usersDurations, { type: 'text/plain' })
const url = URL.createObjectURL(blob)

// Redirect to that URL
window.location.href = url

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.