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

problem accessing polymer properties from content script #753

Closed
davidmaxwaterman opened this issue Sep 14, 2014 · 7 comments
Closed

problem accessing polymer properties from content script #753

davidmaxwaterman opened this issue Sep 14, 2014 · 7 comments

Comments

@davidmaxwaterman
Copy link

It seems I can set an attribute of a polymer element ok from inside a content script, but setting an element's property doesn't work and/or doesn't trigger the corresponding Changed function.

I also had trouble getting events in the content script.

I wrote an example here :

https://github.com/davidmaxwaterman/cs_polymer_test

and would appreciate knowing if I'm doing anything wrong and/or how to do what I'm trying to do.

@robdodson
Copy link
Contributor

Wondering if the issues you're seeing are related to this bug: https://code.google.com/p/chromium/issues/detail?id=390807

@robdodson
Copy link
Contributor

@esprehn any idea why setting properties on an element using a content script might not work?

@davidmaxwaterman davidmaxwaterman changed the title problem accessing polymer attributes from content script problem accessing polymer properties from content script Sep 19, 2014
@davidmaxwaterman
Copy link
Author

Any news on this? I guess nothing will happen in the near-term anyway, so we'll continue manipulating the attributes in the dom.

@ebidel
Copy link
Contributor

ebidel commented Sep 19, 2014

@rafaelw could this have something to do with Object.observe() and content scripts being in an isolated world (e.g. the property is not part of the same origin)

@esprehn
Copy link

esprehn commented Sep 19, 2014

This can't work, content scripts see a totally different wrapper around the element. Specifically they see HTMLElement while the page sees the real MyCustomElement class. There's no way to make this work currently without some kind of serialization system in the middle.

ex. the Array type in the content script is different, so doing element.property = [1,2,3] needs to clone the array into the main world otherwise you leak the isolated world into the page and also end up with an array that fails instanceof Array. This doesn't work with complex APIs though, if the property expects some model object there's no way to create and clone across the worlds since JS has no concept of a clone() callback on objects.

It's all symptoms of the same thing going on in http://crbug.com/390807

My suggestion would be to appendChild a script into the main page like <script src="chrome-extension://.../proxy.js"> and then talk to the proxy when you want to interact with the page.

@davidmaxwaterman
Copy link
Author

The proxy script sounds like an interesting solution.
I wonder, though, if the addition of this mechanism couldn't be included in polymer.js or platform.js, to make life easier for the extension developer; or are extensions considered too 'corner case' as implied in the comments to the crbug/390807 mentioned above?
Anyway, it's good to have this explained and documented. Perhaps this could be added in the Polymer docs somewhere because it's quite a head-scratcher to the uninitiated :) Somewhere in the same places as the vulcanize tool, would be appropriate, I'd say, since that specifically addresses the csp needs of chrome app developers.

@tjsavage
Copy link
Contributor

Closing this here, thanks everyone!

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

5 participants