ruffle-rs / ruffle

A Flash Player emulator written in Rust
https://ruffle.rs
Other
15.46k stars 800 forks source link

Intercepting navigation #741

Open Sgeo opened 4 years ago

Sgeo commented 4 years ago

I'm attempting to implement a BitMagic player using Ruffle. BitMagic was a desktop application that would play .bm files, which were just a header + swf or dcr file. The Flash files would often attempt to open /bmcontrol/whatever as a way to control the player. Most often, /bmcontrol/next would indicate to play the next animation or go to the menu.

I would like to be able to detect these with some Javascript code, so that I can take the appropriate action instead of the page attempting to literally navigate to /bmcontrol/next.

3BB.bm.swf.zip is a quiz that, after the time allocated ends or an answer given, relies on /bmcontrol/next to stop the animation. If it isn't stopped quickly, the user will be presented with the results for the other answers.

14F.bm.swf.zip is an animation that does getURL("/bmcontrol/next") instead of the more common geturl("/bmcontrol/next", "_self"). In the current Ruffle implementation, this results in the tricky to intercept window.location.assign('/bmcontrol/next').

I could possibly implement something with service workers returning 204s and messaging back to the main page, but I'm worried that Ruffle might continue playing for a few frames afterwards, which would be a bit slow for this use case.

Sgeo commented 4 years ago

Tried the service worker approach, it seems to actually be sufficient only work if the viewer is at the top level domain so the service worker can catch it? I need to experiment more.