{"id":20314906,"url":"https://github.com/catchpoint/webpagetest.api-recipes","last_synced_at":"2026-03-12T17:38:52.894Z","repository":{"id":40385677,"uuid":"465358601","full_name":"catchpoint/WebPageTest.api-recipes","owner":"catchpoint","description":"A collection of useful recipes for the WebPageTest API","archived":false,"fork":false,"pushed_at":"2024-12-03T09:24:11.000Z","size":908,"stargazers_count":12,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-11T17:48:21.556Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/catchpoint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-02T15:19:00.000Z","updated_at":"2024-12-03T09:24:16.000Z","dependencies_parsed_at":"2024-04-19T17:43:51.306Z","dependency_job_id":"dd090281-5fb5-42ee-98e8-2d7617adca44","html_url":"https://github.com/catchpoint/WebPageTest.api-recipes","commit_stats":null,"previous_names":["catchpoint/webpagetest.api-recipes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/catchpoint/WebPageTest.api-recipes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catchpoint%2FWebPageTest.api-recipes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catchpoint%2FWebPageTest.api-recipes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catchpoint%2FWebPageTest.api-recipes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catchpoint%2FWebPageTest.api-recipes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/catchpoint","download_url":"https://codeload.github.com/catchpoint/WebPageTest.api-recipes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catchpoint%2FWebPageTest.api-recipes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30435473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T18:17:08.477Z","updated_at":"2026-03-12T17:38:52.860Z","avatar_url":"https://github.com/catchpoint.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\u003cimg width=\"80%\" alt=\"Webpagetest Recipes Banner\" src=\"assets/images/recipe-banner.png\"\u003e\u003c/p\u003e\n\u003ch1 align=\"center\"\u003e\nWebPageTest API Recipes\n\u003c/h1\u003e\n\u003cp align=\"center\" style=\"font-size: 1.2rem;\"\u003e\n👩‍🍳 A collection of useful recipes for the \u003ca href=\"https://github.com/WebPageTest/webpagetest-api\"\u003eWebPageTest API\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\" style=\"font-size: 1.2rem;\"\u003e🍔 What's your favorite recipe?\u003c/p\u003e\n\n## 📖Table Of Contents\n\n- [Emulate a slow network](#emulate-a-slow-network)\n- [Emulate a slow network and CPU throttling](#emulate-network-\u0026-cputhrottle)\n- [Emulate a custom connectivity (Bandwidth, Latency, PacketLossRate)](#emulate-a-custom-connectivity)\n- [Emulate a test on mobile device](#Emulate-a-test-on-mobile-device)\n- [Retrieve your Core Web Vitals](#retrieve-your-core-web-vitals)\n- [Retrieve your Core Web Vitals + CrUX data for the tested URL](#retrieve-your-core-web-vitals-+-crux)\n- [Run a test with a third-party domain blocked](#run-a-test-with-a-third-party-domain-blocked)\n- [Run a test and get the filmstrip screenshots](#run-a-test-and-get-the-filmstrip-screenshots)\n- [Run a test and generate a lighthouse report](#run-a-test-and-generate-a-lighthouse-report)\n- [Run a multi-step test with scripting](#run-a-multi-step-test-with-scripting)\n- [Run a test and generate a waterfall image](#run-a-test-and-generate-a-waterfall-image)\n- [Run tests on multiple URLs](#run-tests-on-multiple-urls)\n- [Create a URL endpoint](#create-a-url-endpoint)\n- [Run a test and check a budget using testspecs](#run-a-test-and-check-a-budget-using-testspecs)\n- [Run a test using webpagetest chrome recorder](#run-a-test-using-webpagetest-chrome-recorder)\n- [Retrieving chrome trace data](#retrieving-chrome-trace-data)\n- [Retrieving response body](#retrieving-response-body)\n\n\u003ch3 id=\"emulate-a-slow-network\"\u003eEmulate a slow network\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\n// Simulated network throttling (Slow 3G)\nlet options = {\n  location: \"Dulles:Chrome\", //mandatory with connectivity\n  connectivity: \"3G\",\n};\n\n// Run the test\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Slow-network](/assets/images/basic-test.png \"Emulate a slow network using Webpagetest\")\n\n[Source](slow-network.js)\n\n\u003ch3 id=\"emulate-network-\u0026-cputhrottle\"\u003eEmulate a slow network and CPU throttling\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\n// Simulated network \u0026 cpu throttling\nlet options = {\n  location: \"Dulles:Chrome\",\n  connectivity: \"3G\",\n  throttleCPU: 5,\n};\n\n// Run the test\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n\n```\n\n[Source](network-and-cpu-throttling.js)\n\n\u003ch3 id=\"emulate-a-custom-connectivity\"\u003eEmulate a custom connectivity (Bandwidth, Latency, PacketLossRate)\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\n// Simulated custom connectivity options (custom)\nlet options = {\n  connectivity: \"custom\",\n  location: \"ec2-us-east-1:Chrome\",\n  label: \"custom connectivity\",\n  bandwidthDown: 1000,\n  bandwidthUp: 1000,\n  latency: 5,\n  packetLossRate: 5,\n};\n\n// Run the test\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n\n[Source](connectivity-custom.js)\n\n\u003ch3 id=\"Emulate-a-test-on-mobile-device\"\u003eEmulate a test on mobile device\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  location: \"ec2-us-east-1:Chrome\",\n  label: \"emulate mobile device\",\n  firstViewOnly: true,\n  emulateMobile: true,\n  device: \"Nexus5\", // optional (default: MotoG4)\n};\n\n//Supported devices: https://github.com/WPO-Foundation/webpagetest/blob/master/www/settings/mobile_devices.ini\n\n// Run the test\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n\n[Source](mobile-device.js)\n\n\u003ch3 id=\"retrieve-your-core-web-vitals\"\u003eRetrieve your Core Web Vitals\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  firstViewOnly: true,\n  location: \"Dulles:Chrome\",\n  pollResults: 60,\n  timeout: 240,\n};\n\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log({\n      CumulativeLayoutShift: result.data.average.firstView[\"chromeUserTiming.CumulativeLayoutShift\"],\n      LargestContentfulPaint: result.data.average.firstView[\"chromeUserTiming.LargestContentfulPaint\"],\n      TotalBlockingTime: result.data.average.firstView[\"TotalBlockingTime\"],\n    });\n  } else {\n    console.log(err);\n  }\n});\n\n\n```\n![Webvitals](/assets/images/webvitals.png \"Get your webvitals using webpagetest WPT\")\n\n[Source](webvitals.js)\n\n\n\u003ch3 id=\"retrieve-your-core-web-vitals-+-crux\"\u003eRetrieve your Core Web Vitals + CrUX data for the tested URL\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://www.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  firstViewOnly: true,\n  location: \"Dulles:Chrome\",\n  pollResults: 60,\n  timeout: 240,\n};\n\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(\"\u003c-------------Core Web Vitals-------------\u003e\");\n    console.log({\n      CumulativeLayoutShift: result.data.average.firstView[\"chromeUserTiming.CumulativeLayoutShift\"],\n      LargestContentfulPaint: result.data.average.firstView[\"chromeUserTiming.LargestContentfulPaint\"],\n      TotalBlockingTime: result.data.average.firstView[\"TotalBlockingTime\"],\n    });\n\n    if (result.data.median.firstView.CrUX !== undefined) {\n      console.log(\"\u003c----------------Crux Data----------------\u003e\");\n      console.log(result.data.median.firstView.CrUX);\n    } else {\n      console.log(\"No CrUX Data Found\");\n    }\n  } else {\n    console.log(err);\n  }\n});\n\n```\n\n![Webvitals + CrUX](/assets/images/crux.png \"Generate a CrUX report using webpagetest WPT\")\n\n[Source](webvitals-crux.js)\n\n\u003ch3 id=\"run-a-test-with-a-third-party-domain-blocked\"\u003eRun a test with a third-party domain blocked\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://theverge.com\"; //Your URL here\n\n// URL's must be seprated by spaces (space-delimited)\nlet options = {\n  block:\n    \"https://pagead2.googlesyndication.com https://creativecdn.com https://www.googletagmanager.com https://cdn.krxd.net https://adservice.google.com https://cdn.concert.io https://z.moatads.com https://cdn.permutive.com\",\n};\n\n// Run the test\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n\n[Source](third-party-domain-blocked.js)\n\n\u003ch3 id=\"run-a-test-and-get-the-filmstrip-screenshots\"\u003eRun a test and get the filmstrip screenshots\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\nimport fs from \"fs\";\nimport axios from \"axios\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  firstViewOnly: true,\n  location: \"Dulles:Chrome\",\n  connectivity: \"4G\",\n  pollResults: 60, //keep polling for results after test is scheduled\n};\n\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    result.data.median.firstView.videoFrames.forEach((item, index) =\u003e {\n      axios({\n        method: \"get\",\n        url: item.image,\n        responseType: \"stream\",\n      }).then(function (response) {\n        response.data.pipe(fs.createWriteStream(`screenshot-${index}.png`));\n      });\n    });\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Screenshot strip](/assets/images/screenshot-strip.jpg \"Screenshot strip Webpagetest WPT\")\n\n[Source](screenshot-strip.js)\n\n\u003ch3 id=\"run-a-test-and-generate-a-lighthouse-report\"\u003eRun a test and generate a lighthouse report\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  pollResults: 60,\n  timeout: 240,\n  lighthouse: 1, // This parameter will generate both WPT results and Lighthouse report\n};\n\n// Run the test\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(`\\n\n      Lighthouse scores:\n       Performance: ${result.data.lighthouse.categories.performance.score * 100},\n       Accessibility: ${result.data.lighthouse.categories.accessibility.score * 100},\n       Best Practices: ${result.data.lighthouse.categories['best-practices'].score * 100},\n       SEO: ${result.data.lighthouse.categories.seo.score * 100},\n       PWA: ${result.data.lighthouse.categories.pwa.score * 100}\n\n      Lighthouse report: https://www.webpagetest.org/lighthouse.php?test=${result.data.id}\n      Full WebPageTest results: ${result.data.summary}\n    `);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Lighthouse scores by Webpagetest WPT](/assets/images/lighthouse-scores.png \"Lighthouse scores\")\n\n![Lighthouse report by Webpagetest WPT](/assets/images/lighthouse.png \"Lighthouse report\")\n\n[Source](lighthouse.js)\n\n\u003ch3 id=\"run-a-multi-step-test-with-scripting\"\u003eRun a multi-step test with scripting\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet options = {\n  pollResults: 60,\n  firstViewOnly: true, //Skips the Repeat View test\n};\n\nconst script = wpt.scriptToString([\n  { logData: 0 },\n  { navigate: \"http://foo.com/login\" },\n  { logData: 1 },\n  { setValue: [\"name=username\", \"johndoe\"] },\n  { setValue: [\"name=password\", \"12345\"] },\n  { submitForm: \"action=http://foo.com/main\" },\n  \"waitForComplete\",\n]);\n\n// Run the test\nwpt.runTest(script, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n\nVisit [Scripting Docs](https://docs.webpagetest.org/scripting/) for more information \n\n[Source](multistep.js)\n\n\n\u003ch3 id=\"run-a-test-and-generate-a-waterfall-image\"\u003eRun a test and generate a waterfall image\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\nimport fs from \"fs\";\nimport axios from \"axios\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  firstViewOnly: true,\n  location: \"Dulles:Chrome\",\n  connectivity: \"4G\",\n  pollResults: 60, //keep polling for results after test is scheduled\n};\n\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    let imgurl = result.data.median.firstView.images.waterfall;\n\n    axios({\n      method: \"get\",\n      url: imgurl,\n      responseType: \"stream\",\n    }).then(function (response) {\n      response.data.pipe(fs.createWriteStream(\"waterfall.png\"));\n    });\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Waterfall image by WbePagetest WPT](/assets/images/waterfall.png \"Waterfall image\")\n\n[Source](waterfall-image.js)\n\n\u003ch3 id=\"run-tests-on-multiple-urls\"\u003eRun tests on multiple URLs\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wpt = new WebPageTest(\"www.webpagetest.org\", \"YOUR_API_KEY\");\nconst finalResults = [];\n\n// Your list of URLs to test\nlet urls = [\n  \"https://www.webpagetest.org/\",\n  \"https://www.product.webpagetest.org/api\",\n  \"https://docs.webpagetest.org/api/\",\n  \"https://blog.webpagetest.org/\",\n  \"https://www.webpagetest.org/about\",\n];\n\nlet options = {\n  firstViewOnly: true,\n  location: \"Dulles:Chrome\",\n  connectivity: \"4G\",\n  pollResults: 60,\n  timeout: 240,\n};\n\nconst runTest = (wpt, url, options) =\u003e {\n  return new Promise((resolve, reject) =\u003e {\n    console.log(`Submitting test for ${url}...`);\n    wpt.runTest(url, options, async (err, result) =\u003e {\n      try {\n        if (result) {\n          return resolve(result);\n        } else {\n          return reject(err);\n        }\n      } catch (e) {\n        console.info(e);\n      }\n    });\n  });\n};\n\n(async function () {\n  Promise.all(\n    urls.map(async (url) =\u003e {\n      try {\n        await runTest(wpt, url, options).then(async (result) =\u003e {\n          if (result.data) {\n            let median = result.data.median.firstView;\n            //Pushing the data into the Array\n            finalResults.push({\n              id: result.data.id,\n              url: result.data.url,\n              cls: median[\"chromeUserTiming.CumulativeLayoutShift\"],\n              lcp: median[\"chromeUserTiming.LargestContentfulPaint\"],\n              tbt: median[\"TotalBlockingTime\"],\n            });\n          }\n        });\n      } catch (e) {\n        console.error(e);\n      }\n    })\n  ).then(() =\u003e {\n    console.info(finalResults);\n  });\n})();\n\n```\n![Bulk Tests URLs using WebPageTest WPT](/assets/images/bulk-tests.png \"Bulk Tests\")\n\n[Source](bulk-tests.js)\n\n\u003ch3 id=\"create-a-url-endpoint\"\u003eCreate a URL endpoint\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet options = {\n  dryRun: true, // outputs the api endpoint\n};\n\n// multistep script\nconst script = wpt.scriptToString([\n  { navigate: 'https://timkadlec.com/' },\n  { execAndWait: 'document.querySelector(\"#nav \u003e ul \u003e li:nth-child(2) \u003e a\").click();' },\n  { execAndWait: 'document.querySelector(\"#nav \u003e ul \u003e li:nth-child(3) \u003e a\").click();' },\n  { execAndWait: 'document.querySelector(\"#nav \u003e ul \u003e li:nth-child(4) \u003e a\").click();' },\n]);\n\n// fire up the runtest function with a script or a url\nwpt.runTest(script, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n\n```\n![Generate a url using dryRun option](/assets/images/dryrun.png \"DryRun Test\")\n\n[Source](dryrun.js)\n\n\u003ch3 id=\"run-a-test-and-check-a-budget-using-testspecs\"\u003eRun a test and check a budget using testspecs\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testURL = \"https://docs.webpagetest.org/\"; //Your URL here\n\nlet options = {\n  firstViewOnly: true,\n  location: \"Dulles:Chrome\",\n  pollResults: 60,\n  timeout: 240,\n  // Set you budget specs here\n  specs: {\n    average: {\n      firstView: {\n        \"chromeUserTiming.CumulativeLayoutShift\": 0.1,\n        \"chromeUserTiming.LargestContentfulPaint\": 2500,\n        firstContentfulPaint: 2000,\n        TotalBlockingTime: 0.1,\n      },\n    },\n  },\n};\n\nwpt.runTest(testURL, options, (err, result) =\u003e {\n  if (result) {\n    console.log(`Your results are here for test ID:- ${result.testId}`);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Check a budget using testspecs](/assets/images/specs.png \"testspecs\")\n\nCheck [Testspecs](https://github.com/WebPageTest/webpagetest-api/wiki/Test-Specs) for more details on setting a budget\n\n[Source](testspecs.js)\n\n\u003ch3 id=\"run-a-test-using-webpagetest-chrome-recorder\"\u003eRun a test using webpagetest chrome recorder\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\nimport { WPTStringifyChromeRecording } from \"webpagetest-chrome-recorder\";\n\n//Recording generated using chrome recorder\nconst recordingContent = {\n  title: \"Webpagetest Chrome Recorder\",\n  steps: [\n    {\n      type: \"setViewport\",\n      width: 1263,\n      height: 600,\n      deviceScaleFactor: 1,\n      isMobile: false,\n      hasTouch: false,\n      isLandscape: false,\n    },\n    {\n      type: \"navigate\",\n      url: \"https://blog.webpagetest.org/\",\n      assertedEvents: [\n        {\n          type: \"navigation\",\n          url: \"https://blog.webpagetest.org/\",\n          title: \"WebPageTest Blog\",\n        },\n      ],\n    },\n    {\n      type: \"click\",\n      target: \"main\",\n      selectors: [[\"header li:nth-of-type(2) \u003e a\"]],\n      offsetY: 27.802078247070312,\n      offsetX: 26.427078247070312,\n      assertedEvents: [\n        {\n          type: \"navigation\",\n          url: \"https://blog.webpagetest.org/categories/webpagetest-news/\",\n          title: \"\",\n        },\n      ],\n    },\n  ],\n};\n\n//Converting json recording to webpagetest script\nconst script = await WPTStringifyChromeRecording(recordingContent);\nconsole.log(\"Stringified Webpagetest Recorder Script: \\n\\n\" + script + \"\\n\");\n\n// Initializing webpagetest\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet options = {\n  firstViewOnly: true,\n  label: recordingContent.title,\n};\n\nconsole.log(\"Webpagetest Custom Script Test Result: \\n\");\n\n// Run the test using webpagetest script\nwpt.runTest(script, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Run a test using webpagetest chrome recorder](/assets/images/webpagetest-chrome-recorder.png \"webpagetest chrome recorder\")\n\nCheck [Webpagetest Chrome Recorder](https://github.com/WebPageTest/Recorder-To-WPT-Script) for more details\n\n[Source](webpagetest-chrome-recorder.js)\n\n\u003ch3 id=\"retrieving-chrome-trace-data\"\u003eRetrieving chrome trace data\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testId = \"YOUR_TEST_ID\"; //Your URL here\n\n// Retrieving Chrome Trace Data\nwpt.getChromeTraceData(testId, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Retrieving chrome trace data](/assets/images/chrometracedata.png \"chrome trace\")\n\n[Source](getChromeTraceData.js)\n\n\u003ch3 id=\"retrieving-response-body\"\u003eRetrieving Response Body\u003c/h3\u003e\n\n```js\nimport WebPageTest from \"webpagetest\";\n\nconst wptServer = \"https://www.webpagetest.org\";\nconst wpt = new WebPageTest(wptServer, \"YOUR_API_KEY\");\n\nlet testID = \"YOUR_TEST_ID\";\n\nlet options = {\n  run: 1, // the run from which you'd want to fetch the response body\n  request: 2, // the request number same as waterfall\n  cached: 0, // check for the repeat view\n};\n\n// Retrieving response body (Make sure you've enabled the save response body on this test)\nwpt.getResponseBody(testID, options, (err, result) =\u003e {\n  if (result) {\n    console.log(result);\n  } else {\n    console.log(err);\n  }\n});\n\n```\n![Retrieving Response Body](/assets/images/getresponsebody.png \"Response Body\")\n\n[Source](getResponseBody.js)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatchpoint%2Fwebpagetest.api-recipes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatchpoint%2Fwebpagetest.api-recipes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatchpoint%2Fwebpagetest.api-recipes/lists"}