Skip to content

Ensure Click to Load events are dispatched at the right times #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

jonathanKingston
Copy link
Contributor

@kzar this is your patch rebased over the latest changes in #409 feel free to close this out once done. Just cherry pick this into your branch etc.

The Click to Load content script needs to communicate with the Click
to Load surrogate scripts sometimes. This is handled by dispatching
events on the page.

If those events are dispatched _before_ the receiving script has
loaded, the events will be missed and aspects of the feature
broken. So let's wait until page load before dispatching them.

That is made harder, by the fact that some of the events must be
dispatched targetting the tracking elements. That way, the receiver
can maintain a lookup of placeholder element <-> tracking element. If
the tracking element is removed _before_ an event is dispatched that
targets it, the event will no longer bubble up the DOM and be
received. To avoid that from happening, let's hide the tracking
element until the events are fired, and then unhide + remove it from
the DOM.

Worse still, it's also important that those events targetting the
tracking (and placeholder) elements are fired _before_ the
"ddg-ctp-ready" event. So let's also take care to wait for all the
element events to fire before sending it!

Note: This all still assumes that the website does not load the
      scripts (that are redirected to surrogate scripts) after page
      load has completed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants