Skip to content
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

Inject util: Stop processing disconnected elements #1518

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marcustyphoon
Copy link
Collaborator

@marcustyphoon marcustyphoon commented Jun 22, 2024

Description

As noted in #1466 (comment) and previously addressed by #1501, it is possible for exceptions to be logged to the javascript console when we call certain injected functions on a target element that is no longer in the page by the time the injected function is executed.

As of #1514, it is usually fairly difficult for this to happen.

Nevertheless, it should be possible; the first time an injected function is executed it has to be imported asynchronously, for example.

This therefore uses a similar "just don't trigger the listener and resolve the promise" method to prevent any processing code from being run in this now-extremely-rare case. Fortunately, the new structure makes this a oneliner.

Testing steps

  • Confirm basic functionality.

If one wants to observe the behavior this fixes:

  • Load the extension without this PR. Enable at least one feature that calls timeline()
  • Open the javascript console on Tumblr Patio (with at least one column that the feature processes).
  • Click the Tumblr Patio button, triggering a refresh (redpop does not use soft navigate in this instance, so this will perform a full page load and full extension initialization).
  • During the resulting post load, click "home" to navigate to the dashboard. This will—not always, but fairly reliably with the right click timing—log a bunch of errors to the console as unbury_timeline_object throws on every Patio post for every feature that uses it.
  • Perform this same sequence of events with this PR and confirm there are no longer exceptions logged.

@marcustyphoon marcustyphoon changed the title MV3: Stop processing disconnected elements Inject util: Stop processing disconnected elements Jun 23, 2024
@marcustyphoon marcustyphoon marked this pull request as ready for review June 23, 2024 17:22
@marcustyphoon
Copy link
Collaborator Author

Oh, wait... I guess the target of an event has to be a Node, doesn't it. I forgot it defaulted to document.documentElement.

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.

None yet

1 participant