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

make puzzles embeddable via iframe #11337

Open
ericries opened this issue Aug 9, 2022 · 15 comments
Open

make puzzles embeddable via iframe #11337

ericries opened this issue Aug 9, 2022 · 15 comments
Labels
wanted Dead or alive. Backed by a regular contributor.

Comments

@ericries
Copy link

ericries commented Aug 9, 2022

Currently, analysis boards, live games, and the puzzle of the day are available to embed via iframe. Other pages are blocked from embedding because of the Cross-Origin-Opener-Policy header (set in LilaController.scala)

other open-source projects (such as chessli, which integrates lichess with Anki) have to work around this limitation by using another website's puzzle viewer embedded in an iframe. It would be much better to be able to use the lichess puzzle viewer (which is way better)

for what it's worth, other similar sites don't have such a restrictive content policy. for example, the thing that originally got me down this rabbit hole was using Anki to study puzzles in go/baduk, using the open-source online-go.org and Anki. because they do not have a restrictive content policy, their existing puzzle pages work nicely embedded in iframes. I recognize that their scale and significance is different from lichess, I just thought that was an interesting datapoint.

@labbeast89
Copy link

I would like that feature too!

@ssrihari4102
Copy link
Contributor

ssrihari4102 commented Nov 8, 2022

I would like to work on this. @benediktwerner I noticed you mentioned there is an API endpoint to get a puzzle in lichess-org/api#183. Do you have any code or documentation pointers on where I could get started on making a proper embed page for puzzles? Also, I still need to play around with this myself but I was wondering what the main issues that exist if one were to currently replace the src field in the iframe with the aforementioned endpoint (is it just the cross origin issue mentioned by @ericries?).

@benediktwerner
Copy link
Member

The API endpoint returns puzzles as JSON. It's entirely unrelated to iframe embeds. It just can get you the puzzle data to make your own "embed"/puzzle widget.

Closer would be using the actual puzzle page from the website, but besides the "cross origin issue" (really, the main issue is surely the x-frame-options: DENY header), it obviously also has a bunch of additional stuff like the navigation menu that you don't want in an embed. So it needs a separate embed endpoint that excludes all that, probably has some custom CSS, and allows embedding.

Similar embeddable endpoints do exist for studys, games, etc. which can be used as reference:

But ofc it needs to integrate the stuff from the puzzle endpoint instead.

@ericries
Copy link
Author

ericries commented Nov 9, 2022

Please let me know if I can help. I think the plan of taking one of the existing embeds (maybe study is closest?) and replacing the contents with the puzzle logic is sound.

FWIW, as a workaround, I built my own HTML/javascript version that pulls data from the puzzle API and the massive puzzle CSV to produce something that looks a lot like lichess. But I would much rather replace all that jank with a proper iframe.

@ssrihari4102
Copy link
Contributor

I'm working on this issue with @JBaker05 for a college project. We have setup our dev environments and started looking through the code pointers above. Our understanding is that we first need to create an embed route for the puzzles page which simply returns the puzzles page as it is. After this, we can write custom CSS for the embed route so it strips away extraneous elements, such as navigation.

We are not sure if we need to explicitly set the x-frame-options to SAMEORIGIN for our embed page or if that will be handled by default? In general, we were not able to determine where this setting is configurable based on the codebase and previous discussions in the discord.

@ericries
Copy link
Author

ericries commented Nov 13, 2022 via email

@ornicar ornicar assigned ornicar and unassigned ornicar Nov 14, 2022
@ornicar ornicar added the wanted Dead or alive. Backed by a regular contributor. label Nov 14, 2022
@ssrihari4102
Copy link
Contributor

We have locally created a Puzzle.embed endpoint and controller based off of the ones for Puzzle.show. After doing this, we tested that it has the same functionality as the existing endpoint by creating an HTML page that has an iframe with our local embed endpoint as its src.

For the view, we are trying to figure out how to control the CSS so we can strip away the same elements as zen mode does. Namely, we're struggling to figure out how the CSS for zen mode becomes active when you turn on zen mode. Do either of you have any thoughts on working on the view, especially with regards to zen mode?

@ssrihari4102
Copy link
Contributor

Hey @ericries and @benediktwerner. We were wondering if we could get some general feedback and advice on next steps for the above PR? In the PR description we discussed what we think went well and what still needs to be worked on for the PR to be merged. We understand that the needs of the repository as a whole take precedence; however, we were hoping to get some advice relatively soon since the deadline for our assignment is a week or so away and we would like to make as much progress on the issue as possible before then.

@ericries
Copy link
Author

ericries commented Dec 1, 2022 via email

@ssrihari4102
Copy link
Contributor

Thanks for getting back to me! Yes I'm in the server. However, I only have access to the dev-onboarding channel. Also, since you two are somewhat familiar with this issue I figured I'd ask here first.

@ericries
Copy link
Author

ericries commented Dec 1, 2022 via email

@schlawg
Copy link
Collaborator

schlawg commented Dec 1, 2022

Among people who regularly give onboarding advice, benedikt (1vader on discord) is probably a good one to bounce your embedding ideas off of. Also - friendly heads up re lichess discord - avoid pinging maintainers in non-emergency cases it won't speed up response.

@benediktwerner
Copy link
Member

Sorry, I haven't really been following GitHub much the last few weeks.

Zen mode definitely doesn't seem like the way to go here. We just want to directly remove all that stuff. The main way to get rid of most of that is to use views.html.base.embed instead of views.html.base.layout in the view.

More fundamentally though, as Thibault mentioned in the Draft PR, it does seem kinda unclear what exactly this is supposed to do. Is it an embed of a single puzzle or can you continue playing puzzles after another?

@ericries
Copy link
Author

ericries commented Dec 9, 2022 via email

@levallem
Copy link

levallem commented Mar 7, 2023

On many occasions I try to make an entry on my blog about tactical patterns and in fact I need to be able to put some puzzles that can be solved within my blog.
At the moment I usually add the url of a lichess studio where they can do the exercises. But it is not ideal.
I hope that in the future lichess can find a solution, it would be of great help to the chess community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wanted Dead or alive. Backed by a regular contributor.
Projects
None yet
Development

No branches or pull requests

7 participants