{"id":308,"date":"2022-01-27T03:04:16","date_gmt":"2022-01-27T11:04:16","guid":{"rendered":"https:\/\/blog.mozilla.org\/performance\/?p=308"},"modified":"2022-01-27T03:04:16","modified_gmt":"2022-01-27T11:04:16","slug":"another-step-in-automating-the-pageload-recordings","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/performance\/2022\/01\/27\/another-step-in-automating-the-pageload-recordings\/","title":{"rendered":"Another Step in Automating the Pageload Recordings"},"content":{"rendered":"<h3>Background<\/h3>\n<p>In a previous article, <a href=\"https:\/\/blog.mozilla.org\/performance\/author\/ksereduckmozilla-com\/\">Kimberly Sereduck<\/a> told us about <a href=\"https:\/\/blog.mozilla.org\/performance\/2021\/11\/30\/updates-to-warm-page-load-tests\/\">Updates to Warm Page Load Tests<\/a> and how we are continuously working to make our tests more representative of real user behavior. Besides that, we are working on automating the process of recording the website&#8217;s page load.<\/p>\n<h3>The Issue<\/h3>\n<p>One challenge in this process is the GDPR prompts that appear in the EU territory. There are a few ways the internet sites allow visitors to set their cookie preferences, from a simple notice included in the page, to prompts that load on a layer over the website. One problem with those is that they sometimes take a while to load, especially on cold loads (first page load after the browser is open). Some of them even take a good portion of the screen, obstructing the calculation of the visual metrics.<\/p>\n<div id=\"attachment_324\" style=\"width: 1010px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-324\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-324 size-extra-large\" src=\"http:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn-1000x616.jpg\" alt=\"espn.com cookie prompt - before\" width=\"1000\" height=\"616\" srcset=\"https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn-1000x616.jpg 1000w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn-300x185.jpg 300w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn-600x369.jpg 600w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn-768x473.jpg 768w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn-1536x945.jpg 1536w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_prompt_espn.jpg 2000w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><p id=\"caption-attachment-324\" class=\"wp-caption-text\">espn.com cookie prompt &#8211; before<\/p><\/div>\n<h3>The Fix<\/h3>\n<p>In order to have an objective measurement of the page load times, we had to treat them in one way or the other. The automation consists of saving the minimal cookie preferences allowed by every website.<\/p>\n<div id=\"attachment_326\" style=\"width: 1010px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-326\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-326 size-extra-large\" src=\"http:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1-1000x616.jpg\" alt=\"cnn.com - after\" width=\"1000\" height=\"616\" srcset=\"https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1-1000x616.jpg 1000w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1-300x185.jpg 300w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1-600x369.jpg 600w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1-768x473.jpg 768w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1-1536x945.jpg 1536w, https:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/test_url_espn-1.jpg 2000w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><p id=\"caption-attachment-326\" class=\"wp-caption-text\">cnn.com &#8211; after<\/p><\/div>\n<p>Once the prompt is dismissed, it won&#8217;t appear on subsequent loads of the page. This is translated into cleaner and more objective measurements of the site. The way we treat those prompts can be used in the future for automating all sorts of similar scenarios.<\/p>\n<p>The code that handles those prompts is pretty simple. We save the list of Xpath addresses of the elements to be clicked on and we use <a href=\"https:\/\/www.sitespeed.io\/documentation\/sitespeed.io\/scripting\/#clickbyxpathandwaitxpath\">browsertime\u2019s click by Xpath<\/a> to interact with the page.<\/p>\n<pre>await commands.measure.start(testUrl);\r\nif (input_cmds) {\r\n  context.log.info(\"Searching for cookie prompt elements...\");\r\n  let cmds = input_cmds.split(\";;;\");\r\n  for (let cmdstr of cmds) {\r\n    let [cmd, ...args] = cmdstr.split(\":::\");\r\n    context.log.info(cmd, args);\r\n    let result = await commands.js.run(\r\n      `return document.evaluate(\"` +\r\n        args +\r\n        `\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;`\r\n    );\r\n    if (result) {\r\n      context.log.info(\"Element found, clicking on it.\");\r\n      await run_command(cmdstr, context, commands);\r\n    } else {\r\n      context.log.info(\r\n        \"Element not found! The cookie prompt may have not appeared, please check the screenshots.\"\r\n      );\r\n      break;\r\n    }\r\n  }\r\n}<\/pre>\n<p>This is how a side-by-side comparison looks before and after:<\/p>\n<div style=\"width: 2560px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-308-1\" width=\"2560\" height=\"1024\" loop=\"1\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/cold-side-by-side.mp4?_=1\" \/><a href=\"http:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/cold-side-by-side.mp4\">http:\/\/blog.mozilla.org\/performance\/files\/2022\/01\/cold-side-by-side.mp4<\/a><\/video><\/div>\n<h3>What&#8217;s Next?<\/h3>\n<p>This automation was tested on desktop site only, but we plan to include the mobile sites as well. And this doesn\u2019t stop here. <a href=\"https:\/\/blog.mozilla.org\/performance\/author\/gmierzwinski\/\">Gregory Mierzwinsky<\/a> is working on an automated system of logging into the websites that require authentication in our scenarios.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background In a previous article, Kimberly Sereduck told us about Updates to Warm Page Load Tests and how we are continuously working to make our tests more representative of real &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/performance\/2022\/01\/27\/another-step-in-automating-the-pageload-recordings\/\">Read more<\/a><\/p>\n","protected":false},"author":1808,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[457005,453323,311,812,265],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/posts\/308"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/users\/1808"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/performance\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}