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

origin is null for requests sent with window.fetch on WKWebView engine #897

Open
1 of 3 tasks
StaymanHou opened this issue Jun 11, 2020 · 8 comments
Open
1 of 3 tasks

Comments

@StaymanHou
Copy link

Issue Type

  • Bug Report
  • Feature Request
  • Support Question

Description

I'm attempting to upgrade cordova-ios from 5.1.1 to 6.0.0 for a project. At the same time, I'm also trying to migrate from uiwebview to wkwebview since that's the new default. And uiwebview is going to be deprecated anyways.

Following the release note, I've managed to get the standard xhr working by setting the scheme and hostname preferences in config.xml

However the requests sent with window.fetch still have the origin set to null despite the custom scheme configuration.

Is that the expected behavior, and I will have to migrate to some other plugin to replace the window.fetch functionality? Is there something else that I'm missing?

@breautek
Copy link
Contributor

This sounds like a wkwebview issue if it works with standard XMLHttpRequest but not with fetch.

@breautek
Copy link
Contributor

breautek commented Jun 11, 2020

My wild guess is wkwebview is treating the request as a tainted origin, which I believe only does this on the fetch api. If the origin is considered tainted, then the origin becomes null, according to the Fetch spec.

https://fetch.spec.whatwg.org/#serializing-a-request-origin

But I don't know what qualifies as a tainted origin...

@StaymanHou
Copy link
Author

Managed to workaround that by using https://github.com/aporat/cordova-plugin-fetch

Still would love to figure out the cause when get a chance, but the fetch plugin by @aporat would do it for now.

@75341704
Copy link

Same problem when the axios is used.

@jony89
Copy link

jony89 commented Sep 22, 2020

same problem here with axios as well, occurs only with cordova-ios v > 6:

Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin.

Not reproduced with cordova-ios 5.1.1, the origin header does not appear at all in the request.

@micro-sugar
Copy link

in CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
after WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
add [configuration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"];
can fix api fail

@gaollard
Copy link

gaollard commented Nov 7, 2020

Same problem when the axios is used.

@adipascu
Copy link

adipascu commented Nov 5, 2021

Here are some links that may or may not be relevant for this issue:

I am not sure what the proper fix is on the app side, I chose to enable (preflight) cors requests from the "null" origin on the server side.

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

7 participants