0

I want add a parameter to a Twitter URL (removing the one that's there if there is one already)

Using this URL as an example, https://twitter.com/RequestlyIO/status/1272478326838292488 it would need to detect the URL having "twitter" in the name, and "status" in the path.

If the URL matches both, then the parameter "?s=21" should be added to the end.

I have Requestly Chrome Extension installed in Chrome and using it to add the parameter.

This is so another program I use will work correctly with it. (Buffer)

This works fine in Firefox, but I have tried this in 3 different versions of Chrome and it will not work.

Any ideas?

1 Answers1

0

Chrome extensions do not play well with Service Workers. Any Request made by Service Workers is not visible inside Chrome Extensions and therefore can not be modified (or blocked).

For example - Try this one

Create a Redirect Rule

Request URL Contains twitter.com

Destination https://stackoverflow.com

enter image description here

Save it and try to open twitter.com. You will see the rule won't do the redirect because Twitter has registered a ServiceWorker which is responsible for providing the response (either from disk cache) or from network.

Have a look at this screenshot

enter image description here

In order to bypass this, you can use Insert Script Rule in which you can write a small custom script to do the redirect when your URL condition matches.

Here's an example

enter image description here

Here's the code which you can use

const currentURL = window.location.href.toLowerCase();
// match your condition here
// Also check the param is not already added to avoid infinite redirects
if (currentURL.indexOf('status') > -1 && currentURL.indexOf('requestlyio') > -1 && currentURL.indexOf('s=21') === -1) {
  // Do the redirect here
  window.location.href = currentURL + '?s=21'
}

Here is the link of the Insert Script SharedList

https://app.requestly.io/rules/#sharedList/1595750670410-add-parameter-to-twitter-status