Skip to content

URL Metric mutation helpers should be exposed in initialize args to match finalize args #1930

@westonruter

Description

@westonruter

As discussed in #1928 (comment):

(Granted, this might be able to be refactored so that it happens at initialize(), so that in the handleLCPMetric() function it calls the extendRootData() function every time. This would depend on passing extendRootData() and extendElementData() to initialize() and we'd need to define urlMetric earlier. This would allow Image Prioritizer to get rid of its externalBackgroundImages variable since it would be directly putting the LCP data into the urlMetric whenever a new one is detected.)

This becomes more important when considering that if the browser is asked to do too much work during pagehide it may terminate execution of the function. See #1928. So the earlier we amend the URL Metric data the better.

These are the relevant properties of FinalizeArgs:

readonly getRootData: () => URLMetric;
readonly extendRootData: ( properties: ExtendedRootData ) => void;
readonly getElementData: ( xpath: string ) => ElementData | null;
readonly extendElementData: (
xpath: string,
properties: ExtendedElementData
) => void;

We need to include them in InitializeArgs.

Then we'll need to move the client extension initialization logic down to occur after:

urlMetric = {
url: currentUrl,
viewport: {
width: win.innerWidth,
height: win.innerHeight,
},
elements: [],
};

Aside:

Let's add logging for each extension that is loaded.

We should also remove this old log entry (cf. d2e266d):

log( 'Detection is stopping.' );

Lastly, let's move this line up to a more logical spot to right after it is last used (see 4025e61, although it should be placed right after disconnectIntersectionObserver()):

// Clean up.
breadcrumbedElementsMap.clear();

Finally, we should deprecate finalize because we cannot reliably compress the URL Metric data at pagehide.

Metadata

Metadata

Assignees

Labels

Projects

Status

Done 😃

Relationships

None yet

Development

No branches or pull requests

Issue actions