1

I looked at the documentation for TamperMonkey and didn't see an obvious way to do this and didn't see any examples in StackOverflow.

I am on WebsiteA, which loads a JSON file from WebsiteB. Can TamperMonkey replace the JSON from WebsiteB?

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Derrick H
  • 11
  • 2
  • 1
    As in, intercept the request? You can use the [webRequest API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest) for that – Spectric Jul 25 '21 at 22:27
  • Further to the above, that documents Browser Extensions - and *tampermonkey* is such a browser extension, but that doesn't mean you get access to `filterResponseData` - as that is only available in *firefox*, and since *tampermonkey* is supposed to be somewhat cross-browser - your chances are very slim at best (in *firefox*) or none (in a different browser) - of course, if *WebsiteA* is yours, you can use tampermoney without the need for webRequest API, to achieve your goal – Bravo Jul 25 '21 at 23:10
  • Simply override `XMLHttpRequest` or `fetch` via `unsafeWindow`, look for examples. – wOxxOm Jul 26 '21 at 03:24
  • The above did not work for me or wasn't an option. Specifically I couldn't override `window.fetch` or use `unsafeWindow` because they would be reset after my script was run. Overriding `XMLHttpRequest` did work though. You can check out my solution here -> https://stackoverflow.com/a/72137265/422312 – Nate-Wilkins May 06 '22 at 06:52

0 Answers0