tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

observe-elementtiming.html (1672B)


      1 <!DOCTYPE HTML>
      2 <meta charset=utf-8>
      3 <title>Element Timing: observe elements with elementtiming attribute</title>
      4 <body>
      5 <style>
      6 body {
      7  margin: 0;
      8 }
      9 </style>
     10 <script src="/resources/testharness.js"></script>
     11 <script src="/resources/testharnessreport.js"></script>
     12 <script src="resources/element-timing-helpers.js"></script>
     13 <script>
     14  let beforeRender;
     15  let img;
     16  async_test(function (t) {
     17    assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
     18    const observer = new PerformanceObserver(
     19      t.step_func_done(function(entryList) {
     20        assert_equals(entryList.getEntries().length, 1);
     21        const entry = entryList.getEntries()[0];
     22        const pathname = window.location.origin + '/element-timing/resources/square100.png';
     23        checkElement(entry, pathname, 'my_image', 'my_id', beforeRender, img);
     24        // Assume viewport has size at least 100, so the element is fully visible.
     25        checkRect(entry, [0, 100, 0, 100]);
     26        checkNaturalSize(entry, 100, 100);
     27      })
     28    );
     29    observer.observe({entryTypes: ['element']});
     30    // We add the image during onload to be sure that the observer is registered
     31    // in time for it to observe the element timing.
     32    window.onload = () => {
     33      // Add image of width equal to 100 and height equal to 100.
     34      img = document.createElement('img');
     35      img.src = 'resources/square100.png';
     36      img.setAttribute('elementtiming', 'my_image');
     37      img.setAttribute('id', 'my_id');
     38      document.body.appendChild(img);
     39      beforeRender = performance.now();
     40    };
     41  }, 'Element with elementtiming attribute is observable.');
     42 </script>
     43 
     44 </body>