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

Failed xhr.open gives BadUrl, but may be caused by security restrictions #33

Open
StefanLiebig opened this issue Aug 21, 2017 · 3 comments
Labels

Comments

@StefanLiebig
Copy link

I wrote a little Elm (0.18.0) app that plays with the giphy.com api. It works within the browser. But while moving it to cordova (android) I received the message "badUrl: ..." for a good url.
I inserted in https://github.com/elm-lang/http/blob/master/src/Native/Http.js at
try { xhr.open(request.method, request.url, true); } catch (e) { return callback(_elm_lang$core$Native_Scheduler.fail({ ctor: 'BadUrl', _0: request.url })); }
an alert( e );
This unveiled the real cause. In my case it was a problem with the "Content Security Police".

I think "badUrl" is too generic and can be misleading. Is there any good way to incorporate the "real" cause?

@process-bot
Copy link

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@evancz evancz changed the title Misleading error text "badUrl" Failed xhr.open gives BadUrl, but may be caused by security restrictions Aug 22, 2017
@evancz
Copy link
Member

evancz commented Aug 22, 2017

Can you say more about exactly what the error you saw was? To capture it and state it explicitly, I must be able to reproduce it.

@StefanLiebig
Copy link
Author

Yes, the alert shows:
image
It is a screen shot from the android emulator. It also occurs on the device.

For reproducing it you have to install cordova (https://cordova.apache.org/#getstarted) and add the android platform.
Then I tweaked the example app (https://cordova.apache.org/docs/en/latest/guide/cli/index.html) such that the example www/js/index.js embeds the JavaScript code of my Elm app.
The content security policy element within the index.html is
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
I hope this helps.

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

No branches or pull requests

3 participants