| 213 | } |
| 214 | |
| 215 | function check(layoutReady = false) { |
| 216 | if ( |
| 217 | !sample || |
| 218 | !armed || |
| 219 | finishing || |
| 220 | (armed.layout && !layoutReady) || |
| 221 | !matches(armed.conditions) |
| 222 | ) { |
| 223 | return; |
| 224 | } |
| 225 | finishing = true; |
| 226 | sample.semanticReady = performance.now(); |
| 227 | // This is a rendering-opportunity proxy, not a claim about presented pixels. |
| 228 | // Waiting two frames also keeps a commit observed inside rAF from ending early. |
| 229 | requestAnimationFrame(() => |
| 230 | requestAnimationFrame(() => { |
| 231 | if (sample) { |
| 232 | sample.renderingOpportunity = performance.now(); |
| 233 | cancelAnimationFrame(frame); |
| 234 | if (marking) { |
| 235 | performance.measure('bench:ready', {start: sample.start, end: sample.semanticReady}); |
| 236 | performance.measure('bench:window', { |
| 237 | start: sample.start, |
| 238 | end: sample.renderingOpportunity |
| 239 | }); |
| 240 | } |
| 241 | } |
| 242 | }) |
| 243 | ); |
| 244 | } |
| 245 | |
| 246 | function observe(records: MutationRecord[] = []) { |
| 247 | if (sample && !sample.renderingOpportunity) { |