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

Event listener on navigate away #18982

Open
William-McGonagle opened this issue Dec 15, 2024 · 5 comments
Open

Event listener on navigate away #18982

William-McGonagle opened this issue Dec 15, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@William-McGonagle
Copy link

ruffleInstance.addEventListener("navigate", (event: any) => {
        event.preventDefault();
        const targetUrl = event.detail.url;
        if (targetUrl) {
          const confirmNavigation = window.confirm(
            "Are you sure you want to leave the site?"
          );
          if (confirmNavigation) {
            window.location.href = targetUrl;
          }
        }
      });

Describe the feature

I know that you can disable navigation or add a confirmation box with the config options in Ruffle, but it would be nice if you could add an event listener to receive the target URL and then handle it yourself. This would allow sites to not allow links to certain domains, and also add confirmation pages like on Twitter: "You are leaving Twitter and going to [domain], are you sure?"

I can implement this

@Herschel If you point me in the right direction as to where the code would be that covers this, I can implement the feature. This is my first time contributing to Ruffle, but I have significant experience with OSS.

@William-McGonagle William-McGonagle added the enhancement New feature or request label Dec 15, 2024
@William-McGonagle
Copy link
Author

Image

For context, this is the confirmation type of page that I'm referring to.

@Dinnerbone
Copy link
Contributor

If you point me in the right direction as to where the code would be that covers this, I can implement the feature. This is my first time contributing to Ruffle, but I have significant experience with OSS.

Web API wise, I think adding a | (string) => OpenURLMode to here:

And then change the rust side to call the method instead of accessing it directly - it's called here:

if self.open_url_mode == OpenUrlMode::Confirm {

My suggestion would be to replace the field with js_player: JavascriptPlayer, add a method to JavascriptPlayer like this one for "what mode should this url use", and call that. Implement it on this class.

Let me know if you need any help, and check out our contribution guidelines & discord for assistance!

(we'd also really appreciate a test if you do implement it <3)

@William-McGonagle
Copy link
Author

Sounds good @Dinnerbone – I'll check this out tomorrow when I finish exams.

William-McGonagle added a commit to William-McGonagle/ruffle that referenced this issue Dec 17, 2024
@William-McGonagle
Copy link
Author

Hey @Dinnerbone – I was hoping you could check out my changes... I wasn't sure how to test them or set up testing but if you could point me in the right direction there, I can get that setup.

@adrian17
Copy link
Collaborator

Hey, I'm trying to better understand the use case; for confirming leaving the site entirely, usually pages (say, Gmail) don't do anything fancy or customizable, I think they just use beforeunload event handler to use the browser's builtin dialog?

As for blocking specific domains, do you have some specific use case for this, or is it "just in case"?
Or is the use case more like "never ask if navigating within the same domain, but ask if different domain"?

Finally, for talking about any code, I'd suggest putting it in a draft pull request, that'd make it much easier to read and keep track of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants