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

Loading issues when using with a chrome extension #3268

Closed
yattias opened this issue Jan 5, 2016 · 4 comments
Closed

Loading issues when using with a chrome extension #3268

yattias opened this issue Jan 5, 2016 · 4 comments

Comments

@yattias
Copy link

yattias commented Jan 5, 2016

Hi Polymer team,

I have been developing a chrome extension using Polymer for some time now. Thanks to Polymer, I was was able to create a very intricate extension that is sheltered from the host's scripts and CSS. 👍

I do however have a few of concerns about releasing it in it's current state. I would like to find out about some strategies for preventing the following problems I have been facing:

  1. Loading Polymer into the page leaks into the global namespace. Polymer does not come bundled into JS files but rather, it comes in the form of an html page and requires the user to use an HTML import to load it into the page. AFAIK, content scripts only allow for CSS and JS but not HTML. To resolve this issue, I am including it by dynamically generating a link element and adding it as such into the page:
function loadUrl(url) {
  return new Promise(
    function(resolve, reject) {
      var link = document.createElement('link');
      link.setAttribute('rel', 'import');
      link.setAttribute('href', url);
      link.onload = function() {
        resolve(url);
      };
      document.head.appendChild(link);
    });
}

loadUrl(chrome.extension.getURL("polymer/polymer.html")).
then( loadUrl(chrome.extension.getURL("my/component.html")) )

Once loaded into the host page, it does not run in isolation like content scripts and can cause namespace conflicts if the page already has Polymer loaded.

  1. Polymer does not tell you when it is loaded and ready to use. Polymer does not (currently) fire an event when it has loaded and as result, my components sometimes load before Polymer does (see bullet point 1) and break.

To mitigate this, I am triggering a custom event at the end of polymer-micro.html (which is where Polymer) is defined as such:

var ev = new CustomEvent('polymer-loaded');
document.dispatchEvent(ev);
  1. The Polybuild tool does not generate proper code for a chrome extension. As useful as it is, it generates a separate javascript file outside of the dom-module causing a namespace leak into the global window object. For example, if was importing jQuery in my module, Polybuild would generate a JS file containing jQuery outside of the DOM module causing it to be attached to the host window object - a big no-no in a chrome extension.

Thanks for the feedback.

I have posted this in StackOverflow but my Polymer questions typically don't get many views there so I decided to post it here as well.

@yattias
Copy link
Author

yattias commented Jan 9, 2016

I opened a bounty in StackOverflow

@yattias
Copy link
Author

yattias commented Jan 28, 2016

Cricket cricket cricket..

@dfreedm
Copy link
Member

dfreedm commented Feb 12, 2016

Can you expand more on (3), or file an issue on polybuild and link to this issue?

@dfreedm dfreedm added the tools label Feb 12, 2016
@tjsavage tjsavage added the 1.x label Sep 8, 2016
@TimvdLippe
Copy link
Contributor

It seems that the StackOverflow question has been answered. As such, I am closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants