Skip to content

Widget in iframe does not support renderValue calls #1434

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

Closed
jefshe opened this issue Dec 13, 2018 · 3 comments
Closed

Widget in iframe does not support renderValue calls #1434

jefshe opened this issue Dec 13, 2018 · 3 comments

Comments

@jefshe
Copy link

jefshe commented Dec 13, 2018

Running this htmlwidget within an iframe causes some odd behaviour.
When trying to update the widget's data via renderValue from the parent frame I get this error:

SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at new TraceManager (plotly-c1d49eded87001936f93debf9b25b2d0.js:551)
    at Object.renderValue (plotly-c1d49eded87001936f93debf9b25b2d0.js:389)

(this is because we are trying to deserialize graphDiv.data which is undefined)

I've tracked this problem down to plotly's isPlainObject implementation which checks if the object's prototype is Object.prototype:
https://github.com/plotly/plotly.js/blob/master/src/lib/is_plain_object.js#L25

Because the widget is in an iframe, the parent's Object.prototype is different from the iframe's Object.prototype.

I see there's been discussion on changing this implementation on the plotly repo:
plotly/plotly.js#1405
but there's little momentum. I propose we can fix it within the widget's js by replacing the object's prototype object if we detect that we're running in an iframe

@cpsievert
Copy link
Collaborator

Running this htmlwidget within an iframe causes some odd behaviour.
When trying to update the widget's data via renderValue from the parent frame I get this error:

Could you please provide a minimal example?

@jefshe
Copy link
Author

jefshe commented Dec 13, 2018

Im running these widgets in a pretty specific environment, the underlying cause is simple but setting it up is not.
I've tried to keep it simple with this pen:
https://codepen.io/jefshe/pen/aPvGpO

Basically the pen is showing the htmlwidget embedded within an iframe. When clicking the button the javascript code tries to update the widget by calling renderValue (with the exact same data in this scenario but a more useful scenario would be when we want to alter something about the data). This leads to the error that I've mentioned

@cpsievert
Copy link
Collaborator

Hmm, that codepen doesn't seem like a great idea. That code is relying pretty heavily on code internal to plotly and htmlwidgets. Have you considered an approach like #1441 (comment)?

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