-
Notifications
You must be signed in to change notification settings - Fork 923
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
Use $.ajax instead of iframe to make remote control requests #3760
Conversation
I can't remember the details but there were very good reasons it was done with an iframe... Maybe things have moved on and it's no longer necessary but it would be good to know what the original reasoning was if anybody can remember. |
The most likely reason is this one described here: Changing |
Right, but even with CORS the editor will need to send back an |
Maybe that's not required for localhost in modern browsers though? But how modern? |
You're doing cross-domain requests with $.ajax() since at least 2014 for overpass searches. |
Yes but that is making a request to an overpass server that we know sends an appropriate |
|
Without |
In modern browsers it's possible to do no-cors fetch instead of adding hidden elements and altering their src:
|
I haven't had much luck figuring out how new exactly a browser has to be to support that but it's been in the specification (under that name) since 2014 so I'm guessing it should be reasonably well supported by now. |
I'm not completely sure about Safari: |
You don't actually need that for XHR to support it though, as the XHR support is client side - whether it chooses to abort or return the limited access response when there is no CORS response header. |
I believe using Maybe you could open an issue on https://github.com/systemed/potlatch3 and discuss adding an "Access-Control-Allow-Origin" header somewhere around here: https://github.com/systemed/potlatch3/blob/master/com/airhttp/ActionController.as#L149-L174 |
What is the error popup they are used to? Without this PR there's no CORS error. |
I tested Potlatch 3 remote control on osm.org, which shows the error popup. But again, let’s not spend much time on Potlatch. |
When launching it from a note page or from any page? |
I didn't use the note page. Just plain remote edit. |
I don't get any error popups. You may get one if the request takes more than 5 seconds. Actually I increased it from one second when I added the second request to note pages. With just one second I was sometimes getting the popup even when using josm. |
I think potlatch 3 immediately loaded the respective area, I don't see where a delay should come from. It's not like JOSM where you might have to accept the remote call depending on configuration. |
Are you talking about this popup in the browser window: "Editing failed - make sure JOSM or Merkaartor is loaded and the remote control option is enabled"? Do you have the "OK" response from "load_and_zoom" request when the popup appears? |
Yes, exactly. I don't know what Potlatch' response looked like, but the remote control did work. |
Can you check the response in the Developer Tools (F12, Network tab)? If the response appears there, how long does it takes? (this should be visible in the timeline column) |
I tried it again today, still on Ubuntu 22.04, but I cannot reproduce the error popup at this time. 🤷 |
To be clear are you talking about testing Potlatch 3 with the current site? or with this PR merged? Before I merge this is there any good reason not to add the |
So with this pull request in place, I'm getting: I also tested the current site yesterday, and thought I saw the same popup. Upon retesting this today, I don't see the timeout popup anymore. Most likely, I mixed up the master branch and this pull request in my local install at one point. If needed I can also test |
Yes please do try it after changing this:
to this:
|
Unfortunately, that didn't work, I'm getting the same "Editing failed" popup as above. By the way, you can also simulate what Potlatch is sending by running:
(includes a delay of 1s) Based on:
|
Is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this is erroring is not because of CORS it's because the CSP is not allowing the XHR fetches - the rules at https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/application_controller.rb#L289 need to be changed to move the 127.0.0.1 rules from child_src
and frame_src
to connect_src
.
Yes, I think that'd work. I'll probably do a new release of P3 in the New Year so it'd be good to have a steer before then if this is going to happen. |
I tried this today without much luck. It seems we would still need the Access-Control-Allow-Origin header to get rid of the error message. |
Does anybody happen to have an instance with these changes running somewhere? Maybe the change would make #1478 superfluous as the main reason for the complications was the iframe use, so it would be nice to test Vespucci against it. |
My personal feeling would to avoid jQuery for this. Do the same as jQuery does which gives more control (and is more stable with jQuery updates). |
Well my personal preference would be to use it because it's what all the rest of our code does so unless you have an actual concrete reason not to use it rather than vague accusations then I think I win. |
Funny stuff example: |
What does it have to do with |
Moved "http://127.0.0.1:8111" to Did nothing about CORS because looks like jQuery doesn't support no-cors mode. But that shouldn't stop the request from working. |
Superseded by #5375. |
iframe with src set to remote control request urls first appeared in c3453cf and was updated with timeout alert in d413539.
jQuery's $.ajax can make the same requests and has builtin timeout support.