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

websocket script is added to embedded iframes #25

Closed
hafen opened this issue Mar 6, 2016 · 4 comments
Closed

websocket script is added to embedded iframes #25

hafen opened this issue Mar 6, 2016 · 4 comments

Comments

@hafen
Copy link

hafen commented Mar 6, 2016

If I am serving html through servr that embeds iframes, the iframe html also gets tagged with the websocket script. I think this can lead to conflicts wrt which websocket connection to honor (is the iframe reloaded or the page?).

library(servr)
library(htmltools)
tmpd <- tempdir()
httw(dir = tmpd, daemon = TRUE, pattern = "index.html")
save_html("iframecontent", file = file.path(tmpd, "iframe.html"))
save_html(tagList(tags$p("test1"), tags$iframe(src = "iframe.html")),
  file = file.path(tmpd, "index.html"))

Inspecting the served page:

untitled

In this situation, subsequent edits to index.html don't always guarantee a refresh of index.html.

@yihui
Copy link
Owner

yihui commented Mar 6, 2016

That is an interesting issue. I thought for a while but I don't know what to do in this case. I cannot simply disable the websocket in the iframe, since RStudio viewer is essentially an iframe.

@hafen
Copy link
Author

hafen commented Mar 6, 2016

True. I realize this is a bit of an edge case. It's probably a reasonable expectation for users to want to use iframes but in many cases it might point to something served from somewhere else, in which case this wouldn't be an issue (right?).

For my case, I have a master page allows the user to page through other pages created through servr, embedded in iframes (see here: http://ryanhafen.com/blog/rmote). The updating behavior isn't consistent (sometimes the iframe updates, sometimes the index).

I wonder how easy / reasonable it would be to add a check in the websockets javascript for a variable that indicates not to connect. I could then explicitly set the variable in the pages I don't want the script to be applied to. What do you think?

@yihui yihui closed this as completed in 44c8ef0 Mar 6, 2016
@yihui
Copy link
Owner

yihui commented Mar 6, 2016

Okay, now you can use an HTML comment <!-- DISABLE-SERVR-WEBSOCKET --> to disable the websocket on an HTML page, e.g.

library(servr)
library(htmltools)
tmpd <- tempdir()
httw(dir = tmpd, daemon = TRUE, pattern = "index.html")
save_html(HTML("iframecontent <!-- DISABLE-SERVR-WEBSOCKET -->"), file = file.path(tmpd, "iframe.html"))
save_html(tagList(tags$p("test1"), tags$iframe(src = "iframe.html")),
  file = file.path(tmpd, "index.html"))

@hafen
Copy link
Author

hafen commented Mar 6, 2016

Perfect! Thanks for considering this case. I can verify that it has provided me a way to fix my issue.

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

2 participants