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

Experiment: Create navigation utility #1294

Merged
merged 4 commits into from
Oct 1, 2023

Conversation

marcustyphoon
Copy link
Collaborator

@marcustyphoon marcustyphoon commented Sep 30, 2023

Description

This implements a wrapper around window.tumblr.on('navigation') so that XKit Rewritten can subscribe to soft navigation events.

More elegant form of #453.

Potentially useful for simplifying logic where something must happen when a navigation event removes an element from the page (as one can't detect removals with pageModifications), but when using both one can't be sure of the order they're fired in and thus must be careful, presumably.

Testing steps

@marcustyphoon
Copy link
Collaborator Author

Note that this demonstrates something Redpop could reasonably just do. My guess is that no one uses window.tumblr.on('navigation'), but some might reasonably use window.addEventListener('navigation').

AprilSylph
AprilSylph previously approved these changes Sep 30, 2023
Copy link
Owner

@AprilSylph AprilSylph left a comment

Choose a reason for hiding this comment

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

me likey

@marcustyphoon
Copy link
Collaborator Author

API surface musings include:

  • As in my previous PR, should the callbacks be called with the current and previous locations? Would this be reliable (i.e. is there ever a case where the URL meaningfully changes but the navigate hook is not called? Probably yes?) I wouldn't implement that until a script needed it, but:
  • If that is not desired or not possible, is there any point of this file not just being just an inject statement that one calls for its side effect? There's really no difference between registering and unregistering a callback and just adding and removing an event listener on window. Of course, importing a file for its side effect is easy to forget and generally feels pretty stupid; this way makes it clear why the logic works. If Redpop were to fire that event, though, I would just delete this and make any script that uses it use addEventListener directly.

@marcustyphoon
Copy link
Collaborator Author

Oh... hm. I wonder what happens when XKit Rewritten gets updated by Firefox with this code running. If I recall correctly, old event listeners in the extension sandbox are killed... but I don't think the shim that we inject here would, so unless it was written very specifically not to do this, there would be two shims, which would fire two custom events, both of which would trigger the handler in the fresh web extension context.

@AprilSylph
Copy link
Owner

there would be two shims, which would fire two custom events, both of which would trigger the handler in the fresh web extension context.

Add a random string to the event name? I think we still have a good random string generator in crypto.js

marcustyphoon and others added 3 commits October 1, 2023 04:25
@marcustyphoon marcustyphoon marked this pull request as ready for review October 1, 2023 11:26
Copy link
Owner

@AprilSylph AprilSylph left a comment

Choose a reason for hiding this comment

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

nice

@marcustyphoon marcustyphoon merged commit 5e82652 into AprilSylph:master Oct 1, 2023
@marcustyphoon marcustyphoon deleted the location-handler-3 branch October 1, 2023 17:59
@marcustyphoon
Copy link
Collaborator Author

oops I should have renamed that

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