Is it possible to change "Origin" header sent within HTTP request from mobile app?

Hello, Obsidian community

Now, when [Feature] support "Pasting" images is implemented, I decided to try to enable my Imgur plugin on mobile.

I enabled debugging with USB on my Android phone and connected to it with chrome://inspect tab to see what fails in terms of network request on attempt to upload an image.

The HTTP error from the plugin I observe on mobile app is: “429 Too Many Requests” with a human-readable payload in HTTP body: “Imgur is temporarily over capacity. Please try again later.”

I compared the headers from both (desktop and mobile Obsidian apps) to see the difference and to understand why the plugin fails on mobile. One major difference, that I noticed is the Origin header.

  • desktop Obsidian app uses app:// for Origin
  • while mobile app uses http://localhost
    So, even though the pre-flight request says Access-Control-Allow-Origin: *, in reality it gets rejected with 429 status code. I would say it’s not a CORS restriction, but I am pretty sure it’s still a problem of a http://localhost value for Origin, which is kind of banned by the target server.

I’ve tried to provide custom value for Origin, but it looks like I do not have control over it since the value in real request does not change (I use fetch API btw)
From Make HTTP requests from plugins - #8 by intellectronica I’ve read a couple of tricks:

  • using NodeJS libs for making HTTP requests (can work only on desktop Electron app)
  • using a middleware/proxy server (which seems to have the same limitation as a 1st option, because mobile app is not a NodeJS app; or I need to host middleware somewhere outside of Obsidian, which I do not consider as an option)

So, is there any other chance for me to adjust Origin header sent by mobile app or Obsidian mobile app behaves strictly like a browser, because it’s powered by Android WebView?
If I can not change Origin in Obsidian mobile, is it possible for Obsidian mobile developers change the value from http://localhost to app://, like it’s done for Desktop app where my plugin works?

I can see you’re using fetch, can you use requestUrl which bypasses CORS restrictions?

1 Like