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

web: Implement URL rewrite rules #18252

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

Conversation

kjarosh
Copy link
Member

@kjarosh kjarosh commented Oct 13, 2024

These rules are configurable and they allow rewriting URLs used in SWFs. The main rationale behind them is to rewrite obsolete links to working ones in order to preserve old content.

In order to add a rewrite rule, add a urlRewriteRules config option which is an array of rewrite rules. Each rule consists of a matcher (either a string or a regex), and a replacement, e.g.:

window.RufflePlayer.config = {
    "urlRewriteRules": [
        // Rewrites to a relative URL
        [/^https?:\/\/example.com\/(.*)\.swf$/, "$1.swf"],
        // Rewrites to an absolute URL
        [/^(.*)\.test\.swf$/, "$1.swf"],
        // Rewrites using a string (exact match, not a regex)
        ["http://old.example.com/site.html", "http://new.example.com/other_site.html"],
    ],
};

Related to #1486.

@kjarosh kjarosh added A-web Area: Web & Extensions T-feature Type: New Feature (that Flash doesn't have) labels Oct 13, 2024
@kjarosh kjarosh force-pushed the url-rewrite branch 3 times, most recently from f96f416 to 4389bd1 Compare October 13, 2024 08:02
@kjarosh kjarosh added the waiting-on-review Waiting on review from a Ruffle team member label Oct 13, 2024
@MrCheeze
Copy link
Contributor

Love to see it! Just one thing - can we say more explicitly whether this rewrites URLs in urlrequests, when navigating to a URL, or both? (I assume both, since that would be the most useful.)

@kjarosh
Copy link
Member Author

kjarosh commented Oct 14, 2024

Yes, it will rewrite URLs in both network requests and links. Added that to the doc.

I originally needed URL rewrite for links only, but I figured that there must be content that needs to have all URLs rewritten in order to work.

cl.click();
}
},
await player.shadow$$(".modal:not(.hidden)"),
Copy link
Contributor

@danielhjacobs danielhjacobs Oct 28, 2024

Choose a reason for hiding this comment

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

WebdriverIO v9 automatically pierces the shadow DOM, so hopefully this .shadow$$ is not needed anymore: https://webdriver.io/docs/api/element/shadow$/

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be good now!

These rules are configurable and they allow rewriting URLs used in SWFs.
The main rationale behind them is to rewrite obsolete links to
working ones in order to preserve old content.

In order to add a rewrite rule, add a `urlRewriteRules` config option
which is an array of rewrite rules.  Each rule consists of a matcher
(either a string or a regex), and a replacement, e.g.:

    window.RufflePlayer.config = {
        "urlRewriteRules": [
            // Rewrites to a relative URL
            [/^https?:\/\/example.com\/(.*)\.swf$/, "$1.swf"],
            // Rewrites to an absolute URL
            [/^(.*)\.test\.swf$/, "$1.swf"],
            // Rewrites using a string (exact match, not a regex)
            ["http://old.example.com/site.html", "http://new.example.com/other_site.html"],
        ],
    };
Useful on Chromium-based browsers, where the modal
is always displayed at the beginning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web Area: Web & Extensions T-feature Type: New Feature (that Flash doesn't have) waiting-on-review Waiting on review from a Ruffle team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants