Skip to content

Dispatch Click to Load ready event again when necessary #457

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

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

kzar
Copy link
Contributor

@kzar kzar commented Apr 21, 2023

The "ddg-ctp-ready" event is dispatched by the Click to Load
content-scope-script, to let the surrogate scripts know when the
feature is ready. Very occasionally that event is dispatched too
early, and so the surrogate script misses it. Workaround that by
dispatching the event again, if we see that a surrogate script
finished loading after page load has finished.

@kzar kzar requested a review from ladamski as a code owner April 21, 2023 16:31
Copy link
Contributor

@ladamski ladamski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this mean that ddg-ctp-ready sometimes fires twice, and that would result in multiple firings of onClickToPlayReady() in the surrogate?

If this second path is more reliable would it make sense to only use that? Or put a guard in onClickToPlayReady() to handle redundant calls?

@kzar
Copy link
Contributor Author

kzar commented Apr 21, 2023

Would this mean that ddg-ctp-ready sometimes fires twice, and that would result in multiple firings of onClickToPlayReady() in the surrogate?

Our event listener for ddg-ctp-ready uses the once: true option for that reason, to avoid it catching the event twice.

If this second path is more reliable would it make sense to only use that?

Yea, it might make sense to do that in the future. Thing is it would add quite a bit of complexity, keeping track of when the various surrogate scripts are ready and dispatching the relevant events only after that. I'd like to avoid it if we can, so far I've only ever see the ddg-ctp-ready event fire too early very occasionally on one website.

Edit: I'll add the surrogate-load event to the Facebook surrogate script too. That way, if we do decide to do this in the future we'll be ready.

@kzar kzar force-pushed the fix-ctl-youtube-placeholders-p14 branch 4 times, most recently from ac26b13 to aeb0270 Compare April 25, 2023 12:18
The "ddg-ctp-ready" event is dispatched by the Click to Load
content-scope-script, to let the surrogate scripts know when the
feature is ready. Very occasionally that event is dispatched too
early, and so the surrogate script misses it. Workaround that by
dispatching the event again, if we see that a surrogate script
finished loading _after_ page load has finished.
@kzar kzar force-pushed the fix-ctl-youtube-placeholders-p14 branch from aeb0270 to 09d2e9e Compare April 26, 2023 08:44
@kzar kzar merged commit be0b5f9 into duckduckgo:main Apr 26, 2023
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