libreom / predirect

A manifest v3 web extension with minimal permissions to automatically redirect to privacy friendly frontends. ⭐️ Star to support our work!
https://github.com/libreom/predirect
GNU General Public License v3.0
208 stars 7 forks source link

Add optional full URL handling for custom instances #39

Open mbestavros opened 2 months ago

mbestavros commented 2 months ago

This PR adds some additional parsing logic to allow custom instance fields to be full URLs.

The primary benefit from the additional parsing is that custom instances can specify properties they couldn't before - specifically, port numbers and plain HTTP, if desired. This is particularly handy for users self-hosting their own frontends.

If the custom instance field is not populated with a valid URL, the extension will fall back to the old behavior - in other words, it should be fully backwards compatible.

cc: @libreom

coderabbitai[bot] commented 2 months ago

Walkthrough

The changes involve modifications to the createRedirectRule function within the updateRules function in src/background.js. The instance parameter is now parsed to extract the protocol, hostname, and port from a URL format, with added error handling to ensure robustness. The construction of the transform object for redirect properties has been updated to use the parsed URL components dynamically, enhancing flexibility in the generated redirection rules.

Changes

Files Change Summary
src/background.js Modified createRedirectRule function to include URL parsing and error handling for instance.

Poem

In the code where rabbits play,
Redirects now find their way.
With protocols parsed, oh what a sight,
Flexibility hops, taking flight!
Error handling, a wise little trick,
Ensures our rules are clever and quick! 🐇✨


Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between f0b691f8e525825b988d35243b56ed77f6d74530 and d76dd5279dcfb9684c6bf1a3cefef44cda8663be.
Files selected for processing (1) * src/background.js (2 hunks)
Additional comments not posted (2)
src/background.js (2)
`416-425`: **Excellent enhancements to the `createRedirectRule` function! LGTM.** The changes introduce several key improvements: 1. URL parsing: - Allows the `instance` parameter to accept full URLs, providing more flexibility to users. - Extracts the protocol, hostname, and port from the URL, enabling support for custom protocols and ports. - Provides a fallback to "https" protocol and `null` port if parsing fails, ensuring graceful handling of invalid URLs. 2. Dynamic `transform` object: - Constructs the `transform` object dynamically based on the parsed URL components. - Enables the function to generate redirect rules that match the provided URL format. - Maintains backward compatibility by defaulting to "https" and `null` port when parsing fails. 3. Error handling: - The try-catch block ensures that parsing failures are caught and handled gracefully. - Prevents the function from throwing errors and breaking the redirect rules. These enhancements greatly improve the flexibility, robustness, and user experience of the `createRedirectRule` function. Great job! --- `438-438`: **Correct usage of the `transform` object.** The `transform` object is properly used in the returned redirect rule to specify the scheme, host, and port for the redirect. This is consistent with the changes made to construct the `transform` object dynamically based on the parsed URL components.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
mbestavros commented 2 months ago

@libreom anything else needed here?

mbestavros commented 1 week ago

@libreom Pinging again - any chance this can be pulled in?

libreom commented 6 days ago

I just got free from uni work,will hopefully review this week