rsnext/packages/next/compiled/web-vitals/web-vitals.umd.js
Keen Yee Liau dc36199b22
add method to measure Interaction to Next Paint (INP) (#36490)
This commit lets users measure their Interaction to Next Paint [INP](https://web.dev/inp/) web vital.
Note that the `web-vitals` package is beta to denote that INP is an experimental metric, the code is stable and v3 is backwards compatible.

    `web-vitals` CHANGELOG for v3:
    
    - [BREAKING] Report TTFB after a bfcache restore
    - [BREAKING] Only include last LCP entry in metric entries
    - Add support for the new INP metric
    - Rename getXXX() functions to onXXX()
    - Add a navigationType property to the Metric object
    
    See https://github.com/GoogleChrome/web-vitals/blob/next/CHANGELOG.md

Upgraded `playwright-chromium` from `1.14.1` to `1.17.2` because the Events Timing API used to measure INP is only available in Chromium >= v98.



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-06-07 18:28:58 +00:00

1 line
No EOL
6.2 KiB
JavaScript

(function(){var e={61:function(e,n){!function(e,o){true?o(n):0}(this,(function(e){"use strict";var n,o,y,T,w,C=!1,c=function(e){addEventListener("pageshow",(function(n){n.persisted&&(C=!0,e(n))}),!0)},u=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,n={entryType:"navigation",startTime:0};for(var o in e)"navigationStart"!==o&&"toJSON"!==o&&(n[o]=Math.max(e[o]-e.navigationStart,0));return n}())},f=function(e,n){var o=u();return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:C?"back_forward_cache":o&&o.type}},s=function(e,n,o){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var y=new PerformanceObserver((function(e){n(e.getEntries())}));return y.observe(Object.assign({type:e,buffered:!0},o||{})),y}}catch(e){}},l=function(e,n){var o=function t(o){"pagehide"!==o.type&&"hidden"!==document.visibilityState||(e(o),n&&(removeEventListener("visibilitychange",t,!0),removeEventListener("pagehide",t,!0)))};addEventListener("visibilitychange",o,!0),addEventListener("pagehide",o,!0)},d=function(e,n,o){var y;return function(T){n.value>=0&&(T||o)&&(n.delta=n.value-(y||0),(n.delta||void 0===y)&&(y=n.value,e(n)))}},I=-1,v=function(){return"hidden"===document.visibilityState?0:1/0},m=function(){l((function(e){var n=e.timeStamp;I=n}),!0)},h=function(){return I<0&&(I=v(),m(),c((function(){setTimeout((function(){I=v(),m()}),0)}))),{get firstHiddenTime(){return I}}},g=function(e,n){n=n||{};var o,y=h(),T=f("FCP"),a=function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(C&&C.disconnect(),e.startTime<y.firstHiddenTime&&(T.value=e.startTime,T.entries.push(e),o(!0)))}))},w=window.performance&&window.performance.getEntriesByName&&window.performance.getEntriesByName("first-contentful-paint")[0],C=w?null:s("paint",a);(w||C)&&(o=d(e,T,n.reportAllChanges),w&&a([w]),c((function(y){T=f("FCP"),o=d(e,T,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){T.value=performance.now()-y.timeStamp,o(!0)}))}))})))},P=!1,M=-1,E=function(e,n){n=n||{},P||(g((function(e){M=e.value})),P=!0);var o,i=function(n){M>-1&&e(n)},y=f("CLS",0),T=0,w=[],u=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=w[0],C=w[w.length-1];T&&e.startTime-C.startTime<1e3&&e.startTime-n.startTime<5e3?(T+=e.value,w.push(e)):(T=e.value,w=[e]),T>y.value&&(y.value=T,y.entries=w,o())}}))},C=s("layout-shift",u);C&&(o=d(i,y,n.reportAllChanges),l((function(){u(C.takeRecords()),o(!0)})),c((function(){T=0,M=-1,y=f("CLS",0),o=d(i,y,n.reportAllChanges)})))},N={passive:!0,capture:!0},O=new Date,L=function(e,T){n||(n=T,o=e,y=new Date,A(removeEventListener),S())},S=function(){if(o>=0&&o<y-O){var e={entryType:"first-input",name:n.type,target:n.target,cancelable:n.cancelable,startTime:n.timeStamp,processingStart:n.timeStamp+o};T.forEach((function(n){n(e)})),T=[]}},b=function(e){if(e.cancelable){var n=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,n){var t=function(){L(e,n),r()},i=function(){r()},r=function(){removeEventListener("pointerup",t,N),removeEventListener("pointercancel",i,N)};addEventListener("pointerup",t,N),addEventListener("pointercancel",i,N)}(n,e):L(n,e)}},A=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(n){return e(n,b,N)}))},F=function(e,y){y=y||{};var w,C=h(),I=f("FID"),p=function(e){e.startTime<C.firstHiddenTime&&(I.value=e.processingStart-e.startTime,I.entries.push(e),w(!0))},v=function(e){e.forEach(p)},P=s("first-input",v);w=d(e,I,y.reportAllChanges),P&&l((function(){v(P.takeRecords()),P.disconnect()}),!0),P&&c((function(){var C;I=f("FID"),w=d(e,I,y.reportAllChanges),T=[],o=-1,n=null,A(addEventListener),C=p,T.push(C),S()}))},R=0,H=1/0,J=0,k=function(e){e.forEach((function(e){e.interactionId&&(H=Math.min(H,e.interactionId),J=Math.max(J,e.interactionId),R=J?(J-H)/7+1:0)}))},B=function(){return w?R:performance.interactionCount||0},D=function(){"interactionCount"in performance||w||(w=s("event",k,{type:"event",buffered:!0,durationThreshold:0}))},z=0,x=function(){return B()-z},G=[],K={},q=function(e,n){n=n||{},D();var o,y=f("INP"),r=function(e){e.forEach((function(e){e.interactionId&&function(e){var n=G[G.length-1],o=K[e.interactionId];if(o||G.length<10||e.duration>n.latency){if(o)o.entries.push(e),o.latency=Math.max(o.latency,e.duration);else{var y={id:e.interactionId,latency:e.duration,entries:[e]};K[y.id]=y,G.push(y)}G.sort((function(e,n){return n.latency-e.latency})),G.splice(10).forEach((function(e){delete K[e.id]}))}}(e)}));var n,T=(n=Math.min(G.length-1,Math.floor(x()/50)),G[n]);T&&T.latency!==y.value&&(y.value=T.latency,y.entries=T.entries,o())},T=s("event",r,{durationThreshold:n.durationThreshold||40});o=d(e,y,n.reportAllChanges),T&&(l((function(){r(T.takeRecords()),y.value<0&&x()>0&&(y.value=0,y.entries=[]),o(!0)})),c((function(){G=[],z=B(),y=f("INP"),o=d(e,y,n.reportAllChanges)})))},Q={},_=function(e,n){n=n||{};var o,y=h(),T=f("LCP"),a=function(e){var n=e[e.length-1];if(n){var w=n.startTime;w<y.firstHiddenTime&&(T.value=w,T.entries=[n],o())}},w=s("largest-contentful-paint",a);if(w){o=d(e,T,n.reportAllChanges);var u=function(){Q[T.id]||(a(w.takeRecords()),w.disconnect(),Q[T.id]=!0,o(!0))};["keydown","click"].forEach((function(e){addEventListener(e,u,{once:!0,capture:!0})})),l(u,!0),c((function(y){T=f("LCP"),o=d(e,T,n.reportAllChanges),requestAnimationFrame((function(){requestAnimationFrame((function(){T.value=performance.now()-y.timeStamp,Q[T.id]=!0,o(!0)}))}))}))}},j=function(e,n){n=n||{};var o,y=f("TTFB"),T=d(e,y,n.reportAllChanges);o=function(){var e=u();if(e){if(y.value=e.responseStart,y.value<0||y.value>performance.now())return;y.entries=[e],T(!0)}},"complete"===document.readyState?setTimeout(o,0):addEventListener("load",(function(){return setTimeout(o,0)})),c((function(o){y=f("TTFB"),T=d(e,y,n.reportAllChanges),y.value=performance.now()-o.timeStamp,T(!0)}))};e.getCLS=E,e.getFCP=g,e.getFID=F,e.getINP=q,e.getLCP=_,e.getTTFB=j,e.onCLS=E,e.onFCP=g,e.onFID=F,e.onINP=q,e.onLCP=_,e.onTTFB=j,Object.defineProperty(e,"__esModule",{value:!0})}))}};if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n={};e[61](0,n);module.exports=n})();