File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
plugins/optimization-detective Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,12 @@ function recursiveFreeze( obj ) {
127
127
Object . freeze ( obj ) ;
128
128
}
129
129
130
+ // This needs to be captured early in case the user later resizes the window.
131
+ const viewport = {
132
+ width : win . innerWidth ,
133
+ height : win . innerHeight ,
134
+ } ;
135
+
130
136
/**
131
137
* URL Metric being assembled for submission.
132
138
*
@@ -443,10 +449,7 @@ export default async function detect( {
443
449
444
450
urlMetric = {
445
451
url : currentUrl ,
446
- viewport : {
447
- width : win . innerWidth ,
448
- height : win . innerHeight ,
449
- } ,
452
+ viewport,
450
453
elements : [ ] ,
451
454
} ;
452
455
@@ -507,6 +510,20 @@ export default async function detect( {
507
510
) ;
508
511
} ) ;
509
512
513
+ // Only proceed with submitting the URL Metric if viewport stayed the same size. Changing the viewport size (e.g. due
514
+ // to resizing a window or changing the orientation of a device) will result in unexpected metrics being collected.
515
+ if (
516
+ window . innerWidth !== urlMetric . viewport . width ||
517
+ window . innerHeight !== urlMetric . viewport . height
518
+ ) {
519
+ if ( isDebug ) {
520
+ log (
521
+ 'Aborting URL Metric collection due to viewport size change.'
522
+ ) ;
523
+ }
524
+ return ;
525
+ }
526
+
510
527
if ( extensions . size > 0 ) {
511
528
for ( const [
512
529
extensionModuleUrl ,
You can’t perform that action at this time.
0 commit comments