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

Override Preflight Response code #8

Open
Shabinder opened this issue Mar 15, 2021 · 4 comments
Open

Override Preflight Response code #8

Shabinder opened this issue Mar 15, 2021 · 4 comments

Comments

@Shabinder
Copy link

Override Preflight Response code to 200 to allow certains CORS Request to pass

@NathanC
Copy link

NathanC commented Nov 21, 2022

Seconded. If calling a server that does not support Options at all, it results in a 405 - Method Not Allowed response. Injecting heads won't stop the browser from rejecting to make the call since the preflight request failed.

balvin-perrie added a commit that referenced this issue Nov 29, 2022
@balvin-perrie
Copy link
Owner

As far as I know, we need to use the chrome.debugger to alter the status codes. I just added this on the last commit. You can now ask the extension to intercept and change 4xx status codes. Give it a try and report back. You need to enable it from the action button's "Extra Options" menu.

If calling a server that does not support Options at all...

Can you provide an example to test this

@raff-run
Copy link

raff-run commented Dec 16, 2022

The "Overwrite 4xx status code for this tab" option works, but it also breaks my code in some cases since it also overwrites 4xx status code errors for methods other than OPTIONS. So if I make a HTTP GET and the API returns a 404 because it didn't find it, that gets changed to a 200 too.

For an example of a server that doesn't support OPTIONS: Azure Static Web Apps - https://azure.microsoft.com/en-us/products/app-service/static/

Since apps published in it by default access the api by a prefix instead of a different domain (ex: front-end is on www.mydomain.com, back-end is on www.mydomain.com/api/path-to-endpoint) on Azure Functions, it does not support CORS as it is not needed.

But if I want my frontend running on localhost to access www.devserver.mydomain.com/api/any-endpoint (so I don't need to run a local backend), the calls would fail because OPTIONS www.mydomain.com/api/any-endpoint returns 404.

@janpio
Copy link

janpio commented Feb 11, 2023

I might be doing something wrong, but I can't get this to work.

I have a preflight request returning 401:
image

The extension itself seems to work, because the error message changes when I enabled it:
image
(excuse the terrible ... annotations)

When I "Enable for this Tab" I also get the debugger warning:
image

But then running my script again nothing changes.

Is the extension supposed somehow to signal that the status code overwriting is active? ("Enable this Tab" stays clickable and unchanged from before, so I am not sure if it is actually active)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants