MutationHandler


Handles the MutationObserver for BOOMR.plugins.AutoXHR.

Methods


pause()

Pauses the MutationObserver. Call resume to start it back up.


resume()

Resumes the MutationObserver after a pause.


start()

Initiate MutationHandler.observer on the outer parent document.

Uses addObserver to instrument.

Our internal handler will be called if something happens.


stop()

Disable internal MutationObserver instance. Use this when uninstrumenting the site we're on.


add_event_resource(resource)

Adds a resource to the current event.

Might fail (return -1) if: a) There are no pending events b) The current event is complete c) There's no passed-in resource

Parameters:

Name Type Description
resource

Resource

Returns:

Event index, or -1 on failure


addEvent(resource)

If an event has triggered a resource to be fetched we add it to the list of pending events here and wait for it to eventually resolve.

Parameters:

Name Type Description
resource object

Resource object we are waiting for

Returns:

Type: index

If we are already waiting for an event of this type null otherwise index in the queue.


calculateSpaTimings(resource)

Calculates SPA Back-End and Front-End timings for Hard and Soft SPA navigations.

Parameters:

Name Type Description
resource object

Resouce to calculate for


clearTimeout()

If this instance of the MutationHandler has a timer set, clear it


load_finished(index, loadEventEnd)

Decrement the number of nodes_to_wait for the PendingEvent Object.

If the nodes_to_wait is decremented to 0 and the event type was SPA:

When we're finished waiting on the last node, the MVC engine (eg AngularJS) might still be doing some processing (eg on an XHR) before it adds some additional content (eg IMGs) to the page. We should wait a while (1 second) longer to see if this happens. If something else is added, we'll continue to wait for that content to complete. If nothing else is added, the end event will be the timestamp for when this load_finished(), not 1 second from now.

Parameters:

Name Type Description
index number

Index of the event found in the pending_events array

loadEventEnd TimeStamp

TimeStamp at which the resource was finnished loading


queue_is_empty()

Determines if the resources queue is empty

Returns:

Type: boolean

True if there are no outstanding resources


sendEvent(i)

If called with an event in the pending events list trigger a beacon for this event.

When the beacon is sent for this event is depending on either having a crumb, in which case this beacon will be sent immediately. If that is not the case we wait 5 seconds and attempt to send the event again.

Parameters:

Name Type Description
i number

Index in event list to send

Returns:

Type: undefined

Rturns early if the event already completed


sendResource(resource, eventIndex)

Creates and triggers sending a beacon for a Resource that has finished loading.

Parameters:

Name Type Description
resource Resource

The Resource to send a beacon on

eventIndex number

index of the event in the pending_events array


setTimeout(timeout, index)

Will create a new timer waiting for timeout milliseconds to wait until a resources load time has ended or should have ended. If the timeout expires the Resource at index will be marked as timedout and result in an error Resource marked with XHR_STATUS_TIMEOUT as status information.

Parameters:

Name Type Description
timeout number

time ot wait for the resource to be loaded

index number

Index of the Resource in our MutationHandler#pending_events


timedout(index)

Sends a Beacon for the Resource at index with the status XHR_STATUS_TIMEOUT code, If there are multiple resources attached to the pending_events array at index.

Parameters:

Name Type Description
index number

Index of the event in pending_events array


wait_for_node(node, i)

Determines if we sohuld wait for resources that would be fetched by the specified node.

Parameters:

Name Type Description
node Element

DOM node

i number

Event index

Type Definitions


load_cb(ev)

Once an asset has been loaded and the resource appeared in the page we check if it was part of the interesting events on the page and mark it as finished.

Parameters:

Name Type Description
ev Event

Load event Object


mutation_cb(mutations)

Callback called once Mutation Observer instance noticed a mutation on the page. This method will determine if a mutation on the page is interesting or not.

Parameters:

Name Type Description
mutations Array.<Mutation>

Mutation array describing changes to the DOM